Skip to content

Commit

Permalink
Merge pull request #670 from cucumber/upgrade-cucumber-parent
Browse files Browse the repository at this point in the history
cucumber/tag-expressions/datatable: Upgrades for Cucumber 5.0.0
  • Loading branch information
mpkorstanje authored Aug 2, 2019
2 parents e837d8b + 0938418 commit 0e63c88
Show file tree
Hide file tree
Showing 59 changed files with 328 additions and 305 deletions.
9 changes: 7 additions & 2 deletions cucumber-expressions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [8.0.0 - Unreleased]

### Added

* [Java] Annotate function interfaces with @FunctionalInterface
([cucumber/cucumber-jvm#1716](https://github.com/cucumber/cucumber-jvm/issues/1716)
[mpkorstanje])
* [Java] Mark public api with @API Guardian annotations
([cucumber/cucumber-jvm#1536](https://github.com/cucumber/cucumber-jvm/issues/1536)
[mpkorstanje])
### Changed

* Upgrades to `cucumber-parent:2.0.2`
* [Java] Simplify heuristics to distinguish between Cucumber Expressions and Regular Expressions
([#515](https://github.com/cucumber/cucumber/issues/515)
[#581](https://github.com/cucumber/cucumber/pull/581)
Expand Down
8 changes: 7 additions & 1 deletion cucumber-expressions/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-parent</artifactId>
<version>1.0.6</version>
<version>2.0.2</version>
</parent>
<artifactId>cucumber-expressions</artifactId>
<version>8.0.0-SNAPSHOT</version>
Expand All @@ -27,6 +27,12 @@
</scm>

<dependencies>
<dependency>
<groupId>org.apiguardian</groupId>
<artifactId>apiguardian-api</artifactId>
<version>1.1.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package io.cucumber.cucumberexpressions;

import java.lang.reflect.Type;
import org.apiguardian.api.API;

import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.regex.Pattern;

public class AmbiguousParameterTypeException extends CucumberExpressionException {
@API(status = API.Status.STABLE)
public final class AmbiguousParameterTypeException extends CucumberExpressionException {
private final Pattern regexp;
private final String parameterTypeRegexp;
private final SortedSet<ParameterType<?>> parameterTypes;
private final List<GeneratedExpression> generatedExpressions;

public AmbiguousParameterTypeException(String parameterTypeRegexp, Pattern expressionRegexp, SortedSet<ParameterType<?>> parameterTypes, List<GeneratedExpression> generatedExpressions) {
AmbiguousParameterTypeException(String parameterTypeRegexp, Pattern expressionRegexp, SortedSet<ParameterType<?>> parameterTypes, List<GeneratedExpression> generatedExpressions) {
super(String.format("Your Regular Expression /%s/\n" +
"matches multiple parameter types with regexp /%s/:\n" +
" %s\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class Argument<T> {
@API(status = API.Status.STABLE)
public final class Argument<T> {
private final ParameterType<T> parameterType;
private final Group group;

Expand Down Expand Up @@ -51,7 +54,7 @@ private static List<Object> getGroupValues(List<Group> argGroups) {
return list;
}

public Argument(Group group, ParameterType<T> parameterType) {
private Argument(Group group, ParameterType<T> parameterType) {
this.group = group;
this.parameterType = parameterType;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

/**
* Transformer for a @{@link ParameterType} with (multiple) capture groups.
*
* @param <T> the type to transform to.
*/
@API(status = API.Status.STABLE)
@FunctionalInterface
public interface CaptureGroupTransformer<T> {
/**
* Transforms multiple strings into to an object. The strings are taken from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Deque;
import java.util.List;

class CombinatorialGeneratedExpressionFactory {
final class CombinatorialGeneratedExpressionFactory {
// 256 generated expressions ought to be enough for anybody
private static final int MAX_EXPRESSIONS = 256;
private final String expressionTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CucumberExpression implements Expression {
@API(status = API.Status.STABLE)
public final class CucumberExpression implements Expression {
// Does not include (){} characters because they have special meaning
private static final Pattern ESCAPE_PATTERN = Pattern.compile("([\\\\^\\[$.|?*+\\]])");
@SuppressWarnings("RegExpRedundantEscape") // Android can't parse unescaped braces
Expand All @@ -22,7 +25,7 @@ public class CucumberExpression implements Expression {
private final TreeRegexp treeRegexp;
private final ParameterTypeRegistry parameterTypeRegistry;

public CucumberExpression(String expression, ParameterTypeRegistry parameterTypeRegistry) {
CucumberExpression(String expression, ParameterTypeRegistry parameterTypeRegistry) {
this.source = expression;
this.parameterTypeRegistry = parameterTypeRegistry;

Expand Down Expand Up @@ -134,8 +137,7 @@ public List<Argument<?>> match(String text, Type... typeHints) {
Type type = i < typeHints.length ? typeHints[i] : String.class;
if (parameterType.isAnonymous()) {
ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer();
ObjectMapperTransformer transformer = new ObjectMapperTransformer(defaultTransformer, type);
parameterTypes.set(i, parameterType.deAnonymize(type, transformer));
parameterTypes.set(i, parameterType.deAnonymize(type, arg -> defaultTransformer.transform(arg, type) ));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

@API(status = API.Status.STABLE)
public class CucumberExpressionException extends RuntimeException {
CucumberExpressionException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -11,7 +13,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CucumberExpressionGenerator {
@API(status = API.Status.STABLE)
public final class CucumberExpressionGenerator {
private final ParameterTypeRegistry parameterTypeRegistry;

public CucumberExpressionGenerator(ParameterTypeRegistry parameterTypeRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Default {@link PatternCompiler}
*/
class DefaultPatternCompiler implements PatternCompiler {
final class DefaultPatternCompiler implements PatternCompiler {

@Override
public Pattern compile(String regexp, int flags) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

@API(status = API.Status.STABLE)
public class DuplicateTypeNameException extends CucumberExpressionException {
public DuplicateTypeNameException(String message) {
DuplicateTypeNameException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

import java.lang.reflect.Type;
import java.util.List;
import java.util.regex.Pattern;

@API(status = API.Status.STABLE)
public interface Expression {
List<Argument<?>> match(String text, Type... typeHints);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
Expand All @@ -9,7 +11,8 @@
* using heuristics. This is particularly useful for languages that don't have a
* literal syntax for regular expressions. In Java, a regular expression has to be represented as a String.
*/
public class ExpressionFactory {
@API(status = API.Status.STABLE)
public final class ExpressionFactory {

private static final Pattern BEGIN_ANCHOR = Pattern.compile("^\\^.*");
private static final Pattern END_ANCHOR = Pattern.compile(".*\\$$");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -8,7 +10,7 @@
import java.util.Locale;
import java.util.Map;


@API(status = API.Status.STABLE)
public class GeneratedExpression {
private static final Collator ENGLISH_COLLATOR = Collator.getInstance(Locale.ENGLISH);
private static final String JAVA_KEYWORDS[] = {
Expand All @@ -27,7 +29,7 @@ public class GeneratedExpression {
private final String expressionTemplate;
private final List<ParameterType<?>> parameterTypes;

public GeneratedExpression(String expressionTemplate, List<ParameterType<?>> parameterTypes) {
GeneratedExpression(String expressionTemplate, List<ParameterType<?>> parameterTypes) {
this.expressionTemplate = expressionTemplate;
this.parameterTypes = parameterTypes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.singletonList;

@API(status = API.Status.STABLE)
public class Group {
private final List<Group> children;
private final String value;
private final int start;
private final int end;

public Group(String value, int start, int end, List<Group> children) {
Group(String value, int start, int end, List<Group> children) {
this.value = value;
this.start = start;
this.end = end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import java.util.regex.Matcher;

class GroupBuilder {
final class GroupBuilder {
private List<GroupBuilder> groupBuilders = new ArrayList<>();
private boolean capturing = true;
private String source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.text.ParseException;
import java.util.Locale;

class NumberParser {
final class NumberParser {
private final NumberFormat numberFormat;

NumberParser(Locale locale) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

import java.lang.reflect.Type;

/**
* The {@link ParameterTypeRegistry} uses the default transformer
* to execute all transforms for build in parameter types and all
* anonymous types.
*/
@API(status = API.Status.STABLE)
@FunctionalInterface
public interface ParameterByTypeTransformer {

Object transform(String fromValue, Type toValueType) throws Throwable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.cucumber.cucumberexpressions;

import org.apiguardian.api.API;

import java.lang.reflect.Type;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.util.Collections.singletonList;

@API(status = API.Status.STABLE)
public final class ParameterType<T> implements Comparable<ParameterType<?>> {
@SuppressWarnings("RegExpRedundantEscape") // Android can't parse unescaped braces
private static final Pattern ILLEGAL_PARAMETER_NAME_PATTERN = Pattern.compile("([\\[\\]()$.|?*+])");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import java.util.regex.Matcher;

class ParameterTypeMatcher implements Comparable<ParameterTypeMatcher> {
final class ParameterTypeMatcher implements Comparable<ParameterTypeMatcher> {
private final ParameterType<?> parameterType;
private final Matcher matcher;
private final int textLength;

public ParameterTypeMatcher(ParameterType<?> parameterType, Matcher matcher, int textLength) {
ParameterTypeMatcher(ParameterType<?> parameterType, Matcher matcher, int textLength) {
this.parameterType = parameterType;
this.matcher = matcher;
this.textLength = textLength;
}

public boolean advanceToAndFind(int newMatchPos) {
boolean advanceToAndFind(int newMatchPos) {
// Unlike js, ruby and go, the matcher is stateful
// so we can't use the immutable semantics.
matcher.region(newMatchPos, textLength);
Expand All @@ -25,11 +25,11 @@ public boolean advanceToAndFind(int newMatchPos) {
return false;
}

public int start() {
int start() {
return matcher.start();
}

public String group() {
String group() {
return matcher.group();
}

Expand All @@ -44,7 +44,7 @@ public int compareTo(ParameterTypeMatcher o) {
return 0;
}

public ParameterType<?> getParameterType() {
ParameterType<?> getParameterType() {
return parameterType;
}

Expand Down
Loading

0 comments on commit 0e63c88

Please sign in to comment.