Skip to content

Java optional codegen with final fields #1879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 81 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
d388ff0
Implement custom code generator for Java
aslakhellesoy Jan 5, 2022
0f51cba
Pass template as cli arg
aslakhellesoy Jan 5, 2022
c880f43
Update tests to use new code
aslakhellesoy Jan 5, 2022
e852173
Update gherkin and html-formatter
aslakhellesoy Jan 5, 2022
1db93fe
Fix shading
aslakhellesoy Jan 5, 2022
5e4a35d
Fix serialization
aslakhellesoy Jan 5, 2022
6b86b54
Replace custom codegen with jsonschema2pojo-maven-plugin
aslakhellesoy Jan 5, 2022
efe26b4
Remove Java code generator. Update imports.
aslakhellesoy Jan 5, 2022
334b9a7
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 5, 2022
ce700eb
Fix serialization
aslakhellesoy Jan 5, 2022
5e1b0d8
Merge branch 'java-optional-codegen' of github.com:cucumber/common in…
aslakhellesoy Jan 5, 2022
a718f2f
Fix compilation error
aslakhellesoy Jan 5, 2022
4a4963e
Remove Java code generator
aslakhellesoy Jan 5, 2022
2109b57
Switch back to NON_ABSENT
aslakhellesoy Jan 6, 2022
028ce75
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 6, 2022
2764039
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 6, 2022
7327402
Improve optional code
aslakhellesoy Jan 6, 2022
e6ea1f8
Revert "Remove Java code generator"
aslakhellesoy Jan 6, 2022
489da01
Revert "Remove Java code generator. Update imports."
aslakhellesoy Jan 6, 2022
2131d2a
Revert "Replace custom codegen with jsonschema2pojo-maven-plugin"
aslakhellesoy Jan 6, 2022
2fa22b6
Fix compile error
aslakhellesoy Jan 6, 2022
4c69c40
Restore custom code generation with validation
aslakhellesoy Jan 6, 2022
86a1887
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 6, 2022
1486592
Expand imports
aslakhellesoy Jan 6, 2022
f393af5
Test validate()
aslakhellesoy Jan 6, 2022
6289e0c
Update changelog
aslakhellesoy Jan 6, 2022
8e5ad83
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 7, 2022
e28abe4
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 7, 2022
d3018f8
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 7, 2022
7c14160
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 7, 2022
6e2c440
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 12, 2022
5daf24a
Improve generated messages
aslakhellesoy Jan 12, 2022
970e823
Merge branch 'main' into java-optional-codegen
aslakhellesoy Jan 12, 2022
19d53fe
Update changelog
aslakhellesoy Jan 12, 2022
bb6e9e4
Remove map lookup from enums
aslakhellesoy Jan 12, 2022
2f6a659
Rename static factories to just from
aslakhellesoy Jan 12, 2022
1d32170
Make all lists unmodifiable
aslakhellesoy Jan 12, 2022
92202fa
Copy list before making it unmodifiable
aslakhellesoy Jan 12, 2022
29f85f7
Add minItems
aslakhellesoy Jan 12, 2022
ce2aebe
Use final fields
aslakhellesoy Jan 17, 2022
8b4ae9a
Remove validate()
aslakhellesoy Jan 17, 2022
a021944
Merge branch 'main' into java-optional-codegen-final-fields
aslakhellesoy Jan 17, 2022
bc32d93
Add Jackson parameter names module
aslakhellesoy Jan 17, 2022
288ba0c
Fix tests. Fix enum fromValue
aslakhellesoy Jan 17, 2022
d5f1cef
Add shading of com.fasterxml.jackson.module:jackson-module-parameter-…
aslakhellesoy Jan 17, 2022
3a56eb4
Use single-arg constructor instead of static from method
aslakhellesoy Jan 17, 2022
2242bcc
Fix Gherkin compile errors
aslakhellesoy Jan 17, 2022
e1364df
Fix HTML Formatter compile errors
aslakhellesoy Jan 17, 2022
ee8f1fa
Merge branch 'main' into java-optional-codegen-final-fields
aslakhellesoy Jan 17, 2022
e89151a
Fix another compile error
aslakhellesoy Jan 17, 2022
fb1ba8f
Decouple Jackson and make tests pass
aslakhellesoy Jan 18, 2022
7a6a7a2
Merge branch 'main' into java-optional-codegen-final-fields
aslakhellesoy Jan 18, 2022
9c342d3
Remove Gherkin Main file from jar
aslakhellesoy Jan 18, 2022
027c103
Rename test
aslakhellesoy Jan 18, 2022
44eddbd
Merge branch 'main' into java-optional-codegen-final-fields
aurelien-reeves Jan 19, 2022
876eb2c
Make it work with jackson
mpkorstanje Jan 22, 2022
55676a1
Use idiomatic java for Enum.fromValue
mpkorstanje Jan 22, 2022
21bd79f
Use idiomatic java for serializer and deserializer
mpkorstanje Jan 22, 2022
bc00c4f
Clean up gherkin parser
mpkorstanje Jan 23, 2022
603c350
Fix test
mpkorstanje Jan 23, 2022
98df16d
Idiomatic java
mpkorstanje Jan 23, 2022
6ca17bf
Naming stuff
mpkorstanje Jan 23, 2022
a61cccf
Reduce scope of gherkin parser public api
mpkorstanje Jan 23, 2022
f600f14
Idiomatic java
mpkorstanje Jan 23, 2022
40d3ef4
Always include parse errors
mpkorstanje Jan 23, 2022
1a2c750
Reuse pickle compiler
mpkorstanje Jan 23, 2022
42f6c3c
Idiomatic java
mpkorstanje Jan 23, 2022
7003499
Merge branch 'main' into java-optional-codegen-final-fields
mpkorstanje Jan 23, 2022
efeee2d
Signal that Messages class is generated
mpkorstanje Jan 23, 2022
7e8b831
Nitpicking
mpkorstanje Jan 23, 2022
d9044da
Null checks
mpkorstanje Jan 23, 2022
a4dc269
Null checks
mpkorstanje Jan 23, 2022
8193151
Remove GenerateTokens from gherkin public api
mpkorstanje Jan 23, 2022
3df4d86
Reduce html writer public api
mpkorstanje Jan 23, 2022
2a363c8
Update readmes
mpkorstanje Jan 23, 2022
aa7b337
Merge branch 'main' into java-optional-codegen-final-fields
aslakhellesoy Jan 25, 2022
890ca1c
Generate messages into separate files
mpkorstanje Jan 29, 2022
9677e8b
Update imports
mpkorstanje Jan 29, 2022
a56ed75
Reduce diff size
mpkorstanje Jan 29, 2022
2e84728
Merge remote-tracking branch 'origin/main' into java-optional-codegen…
mpkorstanje Jan 29, 2022
7e7683d
Fix imports
mpkorstanje Jan 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .templates/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ dependency-reduced-pom.xml
.tested*
.compared
.built
.codegen
# Approval tests
acceptance/
7 changes: 5 additions & 2 deletions .templates/java/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(su
default: .tested
.PHONY: default

.codegen:
touch $@

.tested: .tested-jar-check

.tested-jar-check: .deps .built
./scripts/check-jar.sh $(JAR)
touch $@

.built: pom.xml $(JAVA_SOURCE_FILES)
.built: pom.xml $(JAVA_SOURCE_FILES) .codegen
mvn install
touch $@

Expand Down Expand Up @@ -59,7 +62,7 @@ clean: clean-java
.PHONY: clean

clean-java:
rm -rf target .deps .tested* .built acceptance
rm -rf target .deps .tested* .built acceptance .codegen
mvn clean
.PHONY: clean-java

Expand Down
1 change: 1 addition & 0 deletions config/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ dependency-reduced-pom.xml
.tested*
.compared
.built
.codegen
# Approval tests
acceptance/
7 changes: 5 additions & 2 deletions config/java/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(su
default: .tested
.PHONY: default

.codegen:
touch $@

.tested: .tested-jar-check

.tested-jar-check: .deps .built
./scripts/check-jar.sh $(JAR)
touch $@

.built: pom.xml $(JAVA_SOURCE_FILES)
.built: pom.xml $(JAVA_SOURCE_FILES) .codegen
mvn install
touch $@

Expand Down Expand Up @@ -59,7 +62,7 @@ clean: clean-java
.PHONY: clean

clean-java:
rm -rf target .deps .tested* .built acceptance
rm -rf target .deps .tested* .built acceptance .codegen
mvn clean
.PHONY: clean-java

Expand Down
5 changes: 5 additions & 0 deletions gherkin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt

### Changed

* [Java] Replaced `Gherkin` with a `GherkinParser` that uses a builder to construct.
* [Java] Made all internal classes package private

### Deprecated

### Removed

- [Java] the `io.cucumber.gherkin.Main` class is no longer part of the jar.

### Fixed

## [22.0.0] - 2021-09-23
Expand Down
1 change: 1 addition & 0 deletions gherkin/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ dependency-reduced-pom.xml
.tested*
.compared
.built
.codegen
# Approval tests
acceptance/
2 changes: 1 addition & 1 deletion gherkin/java/bin/gherkin
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ if [ ! -f "${DIR}/classpath.txt" ] || [ "${DIR}/../pom.xml" -nt "${DIR}/classpat
fi

java \
-classpath "$(cat "${DIR}/classpath.txt"):${DIR}/../target/classes" \
-classpath "$(cat "${DIR}/classpath.txt"):${DIR}/../target/test-classes:${DIR}/../target/classes" \
io.cucumber.gherkin.Main $*
2 changes: 1 addition & 1 deletion gherkin/java/bin/gherkin-generate-tokens
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ if [ ! -f "${DIR}/classpath.txt" ] || [ "${DIR}/../pom.xml" -nt "${DIR}/classpat
fi

java \
-classpath "$(cat "${DIR}/classpath.txt"):${DIR}/../target/classes" \
-classpath "$(cat "${DIR}/classpath.txt"):${DIR}/../target/classes:${DIR}/../target/test-classes" \
io.cucumber.gherkin.GenerateTokens $*
7 changes: 5 additions & 2 deletions gherkin/java/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(su
default: .tested
.PHONY: default

.codegen:
touch $@

.tested: .tested-jar-check

.tested-jar-check: .deps .built
./scripts/check-jar.sh $(JAR)
touch $@

.built: pom.xml $(JAVA_SOURCE_FILES)
.built: pom.xml $(JAVA_SOURCE_FILES) .codegen
mvn install
touch $@

Expand Down Expand Up @@ -59,7 +62,7 @@ clean: clean-java
.PHONY: clean

clean-java:
rm -rf target .deps .tested* .built acceptance
rm -rf target .deps .tested* .built acceptance .codegen
mvn clean
.PHONY: clean-java

Expand Down
58 changes: 29 additions & 29 deletions gherkin/java/gherkin-java.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,34 @@ import java.util.Queue;

import static java.util.Arrays.asList;

public class @Model.ParserClassName<T> {
public enum TokenType {
class @Model.ParserClassName<T> {
enum TokenType {
None,
@foreach(var rule in Model.RuleSet.TokenRules)
{<text> @rule.Name.Replace("#", ""),
</text>} ;
}

public enum RuleType {
enum RuleType {
None,
@foreach(var rule in Model.RuleSet.Where(r => !r.TempRule))
{<text> @rule.Name.Replace("#", "_"), // @rule.ToString(true)
</text>} ;

public static RuleType cast(TokenType tokenType) {
static RuleType cast(TokenType tokenType) {
return RuleType.values()[tokenType.ordinal()];
}
}

private final Builder<T> builder;

public boolean stopAtFirstError;
private boolean stopAtFirstError;

class ParserContext {
public final ITokenScanner tokenScanner;
public final ITokenMatcher tokenMatcher;
public final Queue<Token> tokenQueue;
public final List<ParserException> errors;
static class ParserContext {
final ITokenScanner tokenScanner;
final ITokenMatcher tokenMatcher;
final Queue<Token> tokenQueue;
final List<ParserException> errors;

ParserContext(ITokenScanner tokenScanner, ITokenMatcher tokenMatcher, Queue<Token> tokenQueue, List<ParserException> errors) {
this.tokenScanner = tokenScanner;
Expand All @@ -84,39 +84,39 @@ public class @Model.ParserClassName<T> {
}
}

public Parser(Builder<T> builder) {
Parser(Builder<T> builder) {
this.builder = builder;
}

public T parse(String source) {
return parse(new StringReader(source));
T parse(String source, String uri) {
return parse(new StringReader(source), uri);
}

public T parse(Reader source) {
return parse(new TokenScanner(source));
T parse(Reader source, String uri) {
return parse(new TokenScanner(source), uri);
}

public T parse(ITokenScanner tokenScanner) {
return parse(tokenScanner, new TokenMatcher());
T parse(ITokenScanner tokenScanner, String uri) {
return parse(tokenScanner, new TokenMatcher(), uri);
}

public T parse(String source, ITokenMatcher tokenMatcher) {
return parse(new StringReader(source), tokenMatcher);
T parse(String source, ITokenMatcher tokenMatcher, String uri) {
return parse(new StringReader(source), tokenMatcher, uri);
}

public T parse(Reader source, ITokenMatcher tokenMatcher) {
return parse(new TokenScanner(source), tokenMatcher);
T parse(Reader source, ITokenMatcher tokenMatcher, String uri) {
return parse(new TokenScanner(source), tokenMatcher, uri);
}

public T parse(ITokenScanner tokenScanner, ITokenMatcher tokenMatcher) {
builder.reset();
T parse(ITokenScanner tokenScanner, ITokenMatcher tokenMatcher, String uri) {
builder.reset(uri);
tokenMatcher.reset();

ParserContext context = new ParserContext(
tokenScanner,
tokenMatcher,
new LinkedList<Token>(),
new ArrayList<ParserException>()
new LinkedList<>(),
new ArrayList<>()
);

startRule(context, [email protected]);
Expand Down Expand Up @@ -298,19 +298,19 @@ public class @Model.ParserClassName<T> {
</text>
}

public interface Builder<T> {
interface Builder<T> {
void build(Token token);
void startRule(RuleType ruleType);
void endRule(RuleType ruleType);
T getResult();
void reset();
void reset(String uri);
}

public interface ITokenScanner {
interface ITokenScanner {
Token read();
}

public interface ITokenMatcher {
interface ITokenMatcher {
@foreach(var rule in Model.RuleSet.TokenRules)
{
@:boolean match_@(rule.Name.Replace("#", ""))(Token token);
Expand Down
44 changes: 31 additions & 13 deletions gherkin/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@
<tag>HEAD</tag>
</scm>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.13.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>[17.1.1,18.0.0)</version>
<version>[17.1.2-SNAPSHOT,18.0.0)</version>
</dependency>

<dependency>
Expand All @@ -38,6 +50,24 @@
<version>0.9.5</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -48,18 +78,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>io.cucumber.gherkin.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
8 changes: 2 additions & 6 deletions gherkin/java/src/main/java/io/cucumber/gherkin/AstNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static io.cucumber.gherkin.Parser.RuleType;
import static io.cucumber.gherkin.Parser.TokenType;

public class AstNode {
class AstNode {
private final Map<RuleType, List<Object>> subItems = new HashMap<RuleType, List<Object>>();
public final RuleType ruleType;

Expand All @@ -18,11 +18,7 @@ public AstNode(RuleType ruleType) {
}

public void add(RuleType ruleType, Object obj) {
List<Object> items = subItems.get(ruleType);
if (items == null) {
items = new ArrayList<Object>();
subItems.put(ruleType, items);
}
List<Object> items = subItems.computeIfAbsent(ruleType, k -> new ArrayList<>());
items.add(obj);
}

Expand Down
2 changes: 1 addition & 1 deletion gherkin/java/src/main/java/io/cucumber/gherkin/Func.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package io.cucumber.gherkin;

public interface Func<V> {
interface Func<V> {
V call();
}
Loading