Skip to content

Commit acc7b16

Browse files
committed
Use Java 17
1 parent 18af3b2 commit acc7b16

16 files changed

+187
-143
lines changed

java/.mvn/jvm.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

java/pom.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.cucumber</groupId>
77
<artifactId>cucumber-parent</artifactId>
8-
<version>4.5.0</version>
8+
<version>5.0.0-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>cucumber-expressions</artifactId>
@@ -47,6 +47,12 @@
4747
</dependencyManagement>
4848

4949
<dependencies>
50+
<dependency>
51+
<groupId>org.jspecify</groupId>
52+
<artifactId>jspecify</artifactId>
53+
<version>1.0.0</version>
54+
</dependency>
55+
5056
<dependency>
5157
<groupId>org.apiguardian</groupId>
5258
<artifactId>apiguardian-api</artifactId>
@@ -96,6 +102,19 @@
96102
</archive>
97103
</configuration>
98104
</plugin>
105+
<plugin>
106+
<groupId>org.apache.maven.plugins</groupId>
107+
<artifactId>maven-checkstyle-plugin</artifactId>
108+
<executions>
109+
<execution>
110+
<id>validate</id>
111+
<phase>verify</phase>
112+
<goals>
113+
<goal>check</goal>
114+
</goals>
115+
</execution>
116+
</executions>
117+
</plugin>
99118
</plugins>
100119
</build>
101120

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ public final class AmbiguousParameterTypeException extends CucumberExpressionExc
1515
private final List<GeneratedExpression> generatedExpressions;
1616

1717
AmbiguousParameterTypeException(String parameterTypeRegexp, Pattern expressionRegexp, SortedSet<ParameterType<?>> parameterTypes, List<GeneratedExpression> generatedExpressions) {
18-
super(String.format("Your Regular Expression /%s/\n" +
19-
"matches multiple parameter types with regexp /%s/:\n" +
20-
" %s\n" +
21-
"\n" +
22-
"I couldn't decide which one to use. You have two options:\n" +
23-
"\n" +
24-
"1) Use a Cucumber Expression instead of a Regular Expression. Try one of these:\n" +
25-
" %s\n" +
26-
"\n" +
27-
"2) Make one of the parameter types preferential and continue to use a Regular Expression.\n" +
28-
"\n",
18+
super(String.format("""
19+
Your Regular Expression /%s/
20+
matches multiple parameter types with regexp /%s/:
21+
%s
22+
23+
I couldn't decide which one to use. You have two options:
24+
25+
1) Use a Cucumber Expression instead of a Regular Expression. Try one of these:
26+
%s
27+
28+
2) Make one of the parameter types preferential and continue to use a Regular Expression.
29+
30+
""",
2931
expressionRegexp.pattern(),
3032
parameterTypeRegexp,
3133
parameterTypeNames(parameterTypes),

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

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package io.cucumber.cucumberexpressions;
22

3+
import org.jspecify.annotations.Nullable;
4+
35
import java.util.List;
46
import java.util.Objects;
57
import java.util.StringJoiner;
68

7-
import static java.util.Arrays.asList;
89
import static java.util.Objects.requireNonNull;
910
import static java.util.stream.Collectors.joining;
1011

@@ -26,29 +27,29 @@ interface Located {
2627

2728
static final class Node implements Located {
2829

29-
private final Type type;
30-
private final List<Node> nodes;
31-
private final String token;
30+
private final NodeType type;
31+
private final @Nullable List<Node> nodes;
32+
private final @Nullable String token;
3233
private final int start;
3334
private final int end;
3435

35-
Node(Type type, int start, int end, String token) {
36+
Node(NodeType type, int start, int end, String token) {
3637
this(type, start, end, null, token);
3738
}
3839

39-
Node(Type type, int start, int end, List<Node> nodes) {
40+
Node(NodeType type, int start, int end, List<Node> nodes) {
4041
this(type, start, end, nodes, null);
4142
}
4243

43-
private Node(Type type, int start, int end, List<Node> nodes, String token) {
44+
private Node(NodeType type, int start, int end, @Nullable List<Node> nodes, @Nullable String token) {
4445
this.type = requireNonNull(type);
4546
this.nodes = nodes;
4647
this.token = token;
4748
this.start = start;
4849
this.end = end;
4950
}
50-
51-
enum Type {
51+
52+
enum NodeType {
5253
TEXT_NODE,
5354
OPTIONAL_NODE,
5455
ALTERNATION_NODE,
@@ -57,27 +58,29 @@ enum Type {
5758
EXPRESSION_NODE
5859
}
5960

61+
@Override
6062
public int start() {
6163
return start;
6264
}
6365

66+
@Override
6467
public int end() {
6568
return end;
6669
}
6770

6871
List<Node> nodes() {
69-
return nodes;
72+
return requireNonNull(nodes);
7073
}
7174

72-
Type type() {
75+
NodeType type() {
7376
return type;
7477
}
75-
78+
7679
String text() {
7780
if (nodes == null)
78-
return token;
81+
return requireNonNull(token);
7982

80-
return nodes().stream()
83+
return nodes.stream()
8184
.map(Node::text)
8285
.collect(joining());
8386
}
@@ -146,11 +149,11 @@ public int hashCode() {
146149
static final class Token implements Located {
147150

148151
final String text;
149-
final Token.Type type;
152+
final TokenType type;
150153
final int start;
151154
final int end;
152155

153-
Token(String text, Token.Type type, int start, int end) {
156+
Token(String text, TokenType type, int start, int end) {
154157
this.text = requireNonNull(text);
155158
this.type = requireNonNull(type);
156159
this.start = start;
@@ -161,45 +164,41 @@ static boolean canEscape(Integer token) {
161164
if (Character.isWhitespace(token)) {
162165
return true;
163166
}
164-
switch (token) {
165-
case (int) escapeCharacter:
166-
case (int) alternationCharacter:
167-
case (int) beginParameterCharacter:
168-
case (int) endParameterCharacter:
169-
case (int) beginOptionalCharacter:
170-
case (int) endOptionalCharacter:
171-
return true;
172-
}
173-
return false;
167+
return switch (token) {
168+
case (int) escapeCharacter,
169+
(int) alternationCharacter,
170+
(int) beginParameterCharacter,
171+
(int) endParameterCharacter,
172+
(int) beginOptionalCharacter,
173+
(int) endOptionalCharacter -> true;
174+
default -> false;
175+
};
174176
}
175177

176-
static Type typeOf(Integer token) {
178+
static TokenType typeOf(Integer token) {
177179
if (Character.isWhitespace(token)) {
178-
return Type.WHITE_SPACE;
179-
}
180-
switch (token) {
181-
case (int) alternationCharacter:
182-
return Type.ALTERNATION;
183-
case (int) beginParameterCharacter:
184-
return Type.BEGIN_PARAMETER;
185-
case (int) endParameterCharacter:
186-
return Type.END_PARAMETER;
187-
case (int) beginOptionalCharacter:
188-
return Type.BEGIN_OPTIONAL;
189-
case (int) endOptionalCharacter:
190-
return Type.END_OPTIONAL;
180+
return TokenType.WHITE_SPACE;
191181
}
192-
return Type.TEXT;
182+
return switch (token) {
183+
case (int) alternationCharacter -> TokenType.ALTERNATION;
184+
case (int) beginParameterCharacter -> TokenType.BEGIN_PARAMETER;
185+
case (int) endParameterCharacter -> TokenType.END_PARAMETER;
186+
case (int) beginOptionalCharacter -> TokenType.BEGIN_OPTIONAL;
187+
case (int) endOptionalCharacter -> TokenType.END_OPTIONAL;
188+
default -> TokenType.TEXT;
189+
};
193190
}
194191

195192
static boolean isEscapeCharacter(int token) {
196193
return token == escapeCharacter;
197194
}
198195

196+
@Override
199197
public int start() {
200198
return start;
201199
}
202200

201+
@Override
203202
public int end() {
204203
return end;
205204
}
@@ -232,7 +231,7 @@ public String toString() {
232231
.toString();
233232
}
234233

235-
enum Type {
234+
enum TokenType {
236235
START_OF_LINE,
237236
END_OF_LINE,
238237
WHITE_SPACE,
@@ -243,14 +242,14 @@ enum Type {
243242
ALTERNATION("" + alternationCharacter, "alternation"),
244243
TEXT;
245244

246-
private final String symbol;
247-
private final String purpose;
245+
private final @Nullable String symbol;
246+
private final @Nullable String purpose;
248247

249-
Type() {
248+
TokenType() {
250249
this(null, null);
251250
}
252251

253-
Type(String symbol, String purpose) {
252+
TokenType(@Nullable String symbol, @Nullable String purpose) {
254253
this.symbol = symbol;
255254
this.purpose = purpose;
256255
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.cucumber.cucumberexpressions;
22

3+
import org.jspecify.annotations.Nullable;
4+
35
import java.lang.reflect.ParameterizedType;
46
import java.lang.reflect.Type;
57
import java.math.BigDecimal;
@@ -18,11 +20,12 @@ final class BuiltInParameterTransformer implements ParameterByTypeTransformer {
1820
}
1921

2022
@Override
21-
public Object transform(String fromValue, Type toValueType) {
23+
public @Nullable Object transform(@Nullable String fromValue, Type toValueType) {
2224
return doTransform(fromValue, toValueType, toValueType);
2325
}
2426

25-
private Object doTransform(String fromValue, Type toValueType, Type originalToValueType) {
27+
@Nullable
28+
private Object doTransform(@Nullable String fromValue, Type toValueType, Type originalToValueType) {
2629
Type optionalValueType;
2730
if ((optionalValueType = getOptionalGenericType(toValueType)) != null) {
2831
Object wrappedValue = doTransform(fromValue, optionalValueType, originalToValueType);
@@ -99,24 +102,24 @@ private Object doTransform(String fromValue, Type toValueType, Type originalToVa
99102
throw createIllegalArgumentException(fromValue, originalToValueType);
100103
}
101104

105+
@Nullable
102106
private Type getOptionalGenericType(Type type) {
103107
if (Optional.class.equals(type)) {
104108
return Object.class;
105109
}
106110

107-
if (!(type instanceof ParameterizedType)) {
111+
if (!(type instanceof ParameterizedType parameterizedType)) {
108112
return null;
109113
}
110114

111-
ParameterizedType parameterizedType = (ParameterizedType) type;
112115
if (Optional.class.equals(parameterizedType.getRawType())) {
113116
return parameterizedType.getActualTypeArguments()[0];
114117
}
115118

116119
return null;
117120
}
118121

119-
private IllegalArgumentException createIllegalArgumentException(String fromValue, Type toValueType) {
122+
private IllegalArgumentException createIllegalArgumentException(@Nullable String fromValue, Type toValueType) {
120123
return new IllegalArgumentException(
121124
"Can't transform '" + fromValue + "' to " + toValueType + "\n" +
122125
"BuiltInParameterTransformer only supports a limited number of class types\n" +

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
import java.util.function.Function;
1010
import java.util.regex.Pattern;
1111

12-
import static io.cucumber.cucumberexpressions.Ast.Node.Type.OPTIONAL_NODE;
13-
import static io.cucumber.cucumberexpressions.Ast.Node.Type.PARAMETER_NODE;
14-
import static io.cucumber.cucumberexpressions.Ast.Node.Type.TEXT_NODE;
12+
import static io.cucumber.cucumberexpressions.Ast.Node.NodeType.OPTIONAL_NODE;
13+
import static io.cucumber.cucumberexpressions.Ast.Node.NodeType.PARAMETER_NODE;
14+
import static io.cucumber.cucumberexpressions.Ast.Node.NodeType.TEXT_NODE;
1515
import static io.cucumber.cucumberexpressions.CucumberExpressionException.createAlternativeMayNotBeEmpty;
1616
import static io.cucumber.cucumberexpressions.CucumberExpressionException.createAlternativeMayNotExclusivelyContainOptionals;
1717
import static io.cucumber.cucumberexpressions.CucumberExpressionException.createInvalidParameterTypeName;
1818
import static io.cucumber.cucumberexpressions.CucumberExpressionException.createOptionalIsNotAllowedInOptional;
1919
import static io.cucumber.cucumberexpressions.CucumberExpressionException.createOptionalMayNotBeEmpty;
2020
import static io.cucumber.cucumberexpressions.CucumberExpressionException.createParameterIsNotAllowedInOptional;
21-
import static io.cucumber.cucumberexpressions.ParameterType.isValidParameterTypeName;
2221
import static io.cucumber.cucumberexpressions.RegexpUtils.escapeRegex;
2322
import static io.cucumber.cucumberexpressions.UndefinedParameterTypeException.createUndefinedParameterType;
2423
import static java.util.stream.Collectors.joining;
@@ -130,8 +129,8 @@ private void assertNoOptionals(Node node,
130129
assertNoNodeOfType(OPTIONAL_NODE, node, createNodeContainedAnOptionalException);
131130
}
132131

133-
private void assertNoNodeOfType(Node.Type nodeType, Node node,
134-
Function<Node, CucumberExpressionException> createException) {
132+
private void assertNoNodeOfType(Node.NodeType nodeType, Node node,
133+
Function<Node, CucumberExpressionException> createException) {
135134
node.nodes()
136135
.stream()
137136
.filter(astNode -> nodeType.equals(astNode.type()))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io.cucumber.cucumberexpressions.Ast.Located;
44
import io.cucumber.cucumberexpressions.Ast.Node;
55
import io.cucumber.cucumberexpressions.Ast.Token;
6-
import io.cucumber.cucumberexpressions.Ast.Token.Type;
6+
import io.cucumber.cucumberexpressions.Ast.Token.TokenType;
77
import org.apiguardian.api.API;
88

99
@API(status = API.Status.STABLE)
@@ -17,8 +17,8 @@ public class CucumberExpressionException extends RuntimeException {
1717
super(message, cause);
1818
}
1919

20-
static CucumberExpressionException createMissingEndToken(String expression, Type beginToken, Type endToken,
21-
Token current) {
20+
static CucumberExpressionException createMissingEndToken(String expression, TokenType beginToken, TokenType endToken,
21+
Token current) {
2222
return new CucumberExpressionException(message(
2323
current.start(),
2424
expression,

0 commit comments

Comments
 (0)