Skip to content

Commit 7ad07b4

Browse files
committed
Use Java 17
1 parent 7ff53c1 commit 7ad07b4

27 files changed

+208
-206
lines changed

java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
<executions>
121121
<execution>
122122
<id>validate</id>
123-
<phase>verify</phase>
123+
<phase>validate</phase>
124124
<goals>
125125
<goal>check</goal>
126126
</goals>

java/src/main/java/io/cucumber/cucumberexpressions/CucumberExpressionException.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static CucumberExpressionException createParameterIsNotAllowedInOptional(Node no
6464
"An optional may not contain a parameter type",
6565
"If you did not mean to use an parameter type you can use '\\{' to escape the '{'"));
6666
}
67+
6768
static CucumberExpressionException createOptionalIsNotAllowedInOptional(Node node, String expression) {
6869
return new CucumberExpressionException(message(
6970
node.start(),
@@ -83,7 +84,7 @@ static CucumberExpressionException createOptionalMayNotBeEmpty(Node node, String
8384
}
8485

8586
static CucumberExpressionException createAlternativeMayNotExclusivelyContainOptionals(Node node,
86-
String expression) {
87+
String expression) {
8788
return new CucumberExpressionException(message(
8889
node.start(),
8990
expression,
@@ -129,7 +130,7 @@ static CucumberExpressionException createInvalidParameterTypeName(Token token, S
129130
}
130131

131132
static String message(int index, String expression, String pointer, String problem,
132-
String solution) {
133+
String solution) {
133134
return thisCucumberExpressionHasAProblemAt(index) +
134135
"\n" +
135136
expression + "\n" +

java/src/main/java/io/cucumber/cucumberexpressions/CucumberExpressionGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public List<GeneratedExpression> generateExpressions(String text) {
7979
}
8080

8181
private String escape(String s) {
82-
return s.replaceAll("%", "%%") // Escape for String.format
82+
return s
83+
// Escape for String.format
84+
.replaceAll("%", "%%")
8385
.replaceAll("\\(", "\\\\(")
8486
.replaceAll("\\{", "\\\\{")
8587
.replaceAll("/", "\\\\/");

java/src/main/java/io/cucumber/cucumberexpressions/CucumberExpressionParser.java

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.apiguardian.api.API;
55

66
import java.util.ArrayList;
7-
import java.util.Arrays;
87
import java.util.List;
98

109
import static io.cucumber.cucumberexpressions.Node.Type.ALTERNATION_NODE;
@@ -63,10 +62,10 @@ public final class CucumberExpressionParser {
6362
Token token = tokens.get(current);
6463
return switch (token.type) {
6564
case WHITE_SPACE, TEXT -> new Result(1, new Node(TEXT_NODE, token.start(), token.end(), token.text));
66-
case BEGIN_OPTIONAL,
67-
END_OPTIONAL,
68-
BEGIN_PARAMETER,
69-
END_PARAMETER,
65+
case BEGIN_OPTIONAL,
66+
END_OPTIONAL,
67+
BEGIN_PARAMETER,
68+
END_PARAMETER,
7069
ALTERNATION -> throw createInvalidParameterTypeName(token, expression);
7170
// If configured correctly this will never happen
7271
default -> new Result(0);
@@ -88,6 +87,7 @@ public final class CucumberExpressionParser {
8887
* option := optional | parameter | text
8988
*/
9089
private static final Parser optionalParser;
90+
9191
static {
9292
List<Parser> parsers = new ArrayList<>();
9393
optionalParser = parseBetween(
@@ -158,7 +158,8 @@ public final class CucumberExpressionParser {
158158
);
159159

160160
/**
161-
* Parses as Cucumber expression into an AST of {@link Node nodes}.
161+
* Parses as Cucumber expression into an AST of {@link Node nodes}.
162+
*
162163
* @param expression the expression to parse
163164
* @return an AST of nodes
164165
* @throws CucumberExpressionException if the expression could not be parsed
@@ -170,26 +171,6 @@ public Node parse(String expression) {
170171
return result.ast.get(0);
171172
}
172173

173-
private interface Parser {
174-
Result parse(String expression, List<Token> tokens, int current);
175-
176-
}
177-
178-
private static final class Result {
179-
final int consumed;
180-
final List<Node> ast;
181-
182-
private Result(int consumed, Node... ast) {
183-
this(consumed, Arrays.asList(ast));
184-
}
185-
186-
private Result(int consumed, List<Node> ast) {
187-
this.consumed = consumed;
188-
this.ast = ast;
189-
}
190-
191-
}
192-
193174
private static Parser parseBetween(
194175
Node.Type type,
195176
Token.Type beginToken,
@@ -241,8 +222,8 @@ private static Result parseTokensUntil(
241222
}
242223

243224
private static Result parseToken(String expression, List<Parser> parsers,
244-
List<Token> tokens,
245-
int startAt) {
225+
List<Token> tokens,
226+
int startAt) {
246227
for (Parser parser : parsers) {
247228
Result result = parser.parse(expression, tokens, startAt);
248229
if (result.consumed != 0) {
@@ -311,4 +292,14 @@ private static List<Node> createAlternativeNodes(int start, int end, List<Node>
311292
return nodes;
312293
}
313294

295+
private interface Parser {
296+
Result parse(String expression, List<Token> tokens, int current);
297+
298+
}
299+
300+
private record Result(int consumed, List<Node> ast) {
301+
private Result(int consumed, Node... ast) {
302+
this(consumed, asList(ast));
303+
}
304+
}
314305
}

java/src/main/java/io/cucumber/cucumberexpressions/CucumberExpressionTokenizer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.Iterator;
88
import java.util.List;
99
import java.util.NoSuchElementException;
10-
import java.util.Objects;
1110
import java.util.PrimitiveIterator.OfInt;
1211

1312
import static io.cucumber.cucumberexpressions.CucumberExpressionException.createCantEscape;

java/src/main/java/io/cucumber/cucumberexpressions/Expression.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.lang.reflect.Type;
77
import java.util.List;
8-
import java.util.Set;
98
import java.util.regex.Pattern;
109

1110
@API(status = API.Status.STABLE)

java/src/main/java/io/cucumber/cucumberexpressions/ExpressionFactory.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.apiguardian.api.API;
44

5-
import java.util.regex.Matcher;
65
import java.util.regex.Pattern;
76
import java.util.regex.PatternSyntaxException;
87

@@ -11,9 +10,9 @@
1110
* using heuristics. This is particularly useful for languages that don't have a
1211
* literal syntax for regular expressions. In Java, a regular expression has to be represented as a String.
1312
*
14-
* A string that starts with `^` and/or ends with `$` (or written in script style, i.e. starting with `/`
15-
* and ending with `/`) is considered a regular expression.
16-
* Everything else is considered a Cucumber expression.
13+
* <p>A string that starts with `^` and/or ends with `$` (or written in script style, i.e. starting with `/`
14+
* and ending with `/`) is considered a regular expression.
15+
* Everything else is considered a Cucumber expression.
1716
*/
1817
@API(status = API.Status.STABLE)
1918
public final class ExpressionFactory {

java/src/main/java/io/cucumber/cucumberexpressions/GeneratedExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.Map;
1313

1414
@API(status = API.Status.STABLE)
15-
public class GeneratedExpression {
15+
public final class GeneratedExpression {
1616
private static final Collator ENGLISH_COLLATOR = Collator.getInstance(Locale.ENGLISH);
1717
private static final String[] JAVA_KEYWORDS = {
1818
"abstract", "assert", "boolean", "break", "byte", "case",
@@ -36,7 +36,7 @@ public class GeneratedExpression {
3636
}
3737

3838
private static boolean isJavaKeyword(@Nullable String keyword) {
39-
return (Arrays.binarySearch(JAVA_KEYWORDS, keyword, ENGLISH_COLLATOR) >= 0);
39+
return Arrays.binarySearch(JAVA_KEYWORDS, keyword, ENGLISH_COLLATOR) >= 0;
4040
}
4141

4242
public String getSource() {

java/src/main/java/io/cucumber/cucumberexpressions/Group.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.util.Collection;
1414

1515
@API(status = API.Status.STABLE)
16-
public class Group {
16+
public final class Group {
1717
private final List<Group> children;
1818
private final @Nullable String value;
1919
private final int start;
@@ -25,6 +25,7 @@ public class Group {
2525
this.end = end;
2626
this.children = children;
2727
}
28+
2829
@Nullable
2930
public String getValue() {
3031
return value;

java/src/main/java/io/cucumber/cucumberexpressions/GroupBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.ArrayList;
66
import java.util.Iterator;
77
import java.util.List;
8-
import java.util.Objects;
98
import java.util.regex.Matcher;
109

1110
import static java.util.Objects.requireNonNull;

0 commit comments

Comments
 (0)