-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[Java8] Add lambda parameter type annotations #1768
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
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
c1c33a9
WIP Lambda equivalent for @DocStringType annotation
ca66872
Implemented addDocStringType method in tests mocked glue
a141a02
Lambda equivalent for @DataTableType annotation
17b32e1
Lambda equivalent for @ParameterType annotation
7685c69
basic tests
0e27023
Fixed broken data table lambda registration
9251ef0
more tests
b8e44dd
Merge remote-tracking branch 'origin/master' into
edb0b77
Remove unused timeout
ecb8424
Work in progress; Added ParameterType with two arguments (broken still)
350c91b
Alter example to do away with Point class
529c21c
Switch to StringBuffer to actually return a different type
59960fb
Expand multi argument example to three
c097b5a
Add example that maps to Map.Entry
d9e3816
Demonstrate issues parsing any non-string arguments
c0efd78
One step closer
0e0dcce
Only support String arguments after looking at Java & Expressions
fdefbf4
Remove Class<T> bodyClass arg as we're only using first type argument
de71b15
Add ParameterTypes with 4-9 arguments
3099f1b
Sprinkle on a few more generics
3ef30f5
Add more LambdaGlue
fef6bc1
Do not reintroduce AfterStep with timeout argument
d12aa24
First JavaDoc
f9ac282
Add more JavaDoc
9265fcd
Fix compilation error in Travis
04ff667
Map.Entry is only in Java11; so drop that test
6ad67f8
Harmonize project names in Maven output
36fd570
Remove left over Map.Entry scenario
e727622
Remove generics from ParameterTypeDefinition & ParameterDefinitionBody
5dd201f
Merge pull request #1782 from cucumber/lambda-type-annotations-continued
mpkorstanje 5feea6f
Rename as suggested in review comments
8a79d35
Remove unused imports
a2cb66f
Add our own Point class to prevent needing java.awt in Java 12+
4538a81
Add a few of the missing supported types
c83556a
Lambda docstring content type checks
347d169
Removed unused API annotation, because constructors is package private
3da65e6
Lambda table row definition
c3d0e07
Lambda table row definition
4d22606
Catch doc string exceptions
mpkorstanje b765883
Lambda table definition, Lambda cell definition
33a7bda
Fixed broken javadoc
0dd6ffd
Fixed broken javadoc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
java8/src/main/java/io/cucumber/java8/DataTableCellDefinitionBody.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package io.cucumber.java8; | ||
|
|
||
| import org.apiguardian.api.API; | ||
|
|
||
| @FunctionalInterface | ||
| @API(status = API.Status.STABLE) | ||
| public interface DataTableCellDefinitionBody<T> { | ||
| T accept(String cell) throws Throwable; | ||
| } |
10 changes: 10 additions & 0 deletions
10
java8/src/main/java/io/cucumber/java8/DataTableDefinitionBody.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.cucumber.java8; | ||
|
|
||
| import io.cucumber.datatable.DataTable; | ||
| import org.apiguardian.api.API; | ||
|
|
||
| @FunctionalInterface | ||
| @API(status = API.Status.STABLE) | ||
| public interface DataTableDefinitionBody<T> { | ||
| T accept(DataTable dataTable) throws Throwable; | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
java8/src/main/java/io/cucumber/java8/DataTableEntryDefinitionBody.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.cucumber.java8; | ||
|
|
||
| import java.util.Map; | ||
| import org.apiguardian.api.API; | ||
|
|
||
| @FunctionalInterface | ||
| @API(status = API.Status.STABLE) | ||
| public interface DataTableEntryDefinitionBody<T> { | ||
| T accept(Map<String, String> map) throws Throwable; | ||
| } |
10 changes: 10 additions & 0 deletions
10
java8/src/main/java/io/cucumber/java8/DataTableRowDefinitionBody.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.cucumber.java8; | ||
|
|
||
| import java.util.List; | ||
| import org.apiguardian.api.API; | ||
|
|
||
| @FunctionalInterface | ||
| @API(status = API.Status.STABLE) | ||
| public interface DataTableRowDefinitionBody<T> { | ||
| T accept(List<String> row) throws Throwable; | ||
| } |
9 changes: 9 additions & 0 deletions
9
java8/src/main/java/io/cucumber/java8/DocStringDefinitionBody.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package io.cucumber.java8; | ||
|
|
||
| import org.apiguardian.api.API; | ||
|
|
||
| @FunctionalInterface | ||
| @API(status = API.Status.STABLE) | ||
| public interface DocStringDefinitionBody<T> { | ||
| T accept(String docString) throws Throwable; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
java8/src/main/java/io/cucumber/java8/Java8DataTableTypeDefinition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package io.cucumber.java8; | ||
|
|
||
| import io.cucumber.core.backend.DataTableTypeDefinition; | ||
| import io.cucumber.datatable.DataTable; | ||
| import io.cucumber.datatable.DataTableType; | ||
| import io.cucumber.datatable.TableCellTransformer; | ||
| import io.cucumber.datatable.TableEntryTransformer; | ||
| import io.cucumber.datatable.TableRowTransformer; | ||
| import io.cucumber.datatable.TableTransformer; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.lang.reflect.Type; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import net.jodah.typetools.TypeResolver; | ||
|
|
||
| final class Java8DataTableTypeDefinition extends AbstractGlueDefinition implements DataTableTypeDefinition { | ||
|
|
||
| private final DataTableType dataTableType; | ||
|
|
||
| Java8DataTableTypeDefinition(Object body) { | ||
| super(body, new Exception().getStackTrace()[3]); | ||
| this.dataTableType = createDataTableType(method); | ||
| } | ||
|
|
||
| private DataTableType createDataTableType(Method method) { | ||
| Class returnType = TypeResolver.resolveRawArguments(DataTableEntryDefinitionBody.class, body.getClass())[0]; | ||
| Type[] parameterTypes = method.getGenericParameterTypes(); | ||
| Type parameterType = parameterTypes[0]; | ||
|
|
||
| if (DataTable.class.equals(parameterType)) { | ||
| return new DataTableType( returnType, (TableTransformer<Object>) this::execute); | ||
| } | ||
|
|
||
| if (List.class.equals(parameterType)) { | ||
| return new DataTableType(returnType, (TableRowTransformer<Object>) this::execute); | ||
| } | ||
|
|
||
| if (Map.class.equals(parameterType)) { | ||
| return new DataTableType(returnType, (TableEntryTransformer<Object>) this::execute); | ||
| } | ||
|
|
||
| if (String.class.equals(parameterType)) { | ||
| return new DataTableType(returnType, (TableCellTransformer<Object>) this::execute); | ||
| } | ||
|
|
||
| return new DataTableType(returnType, (TableTransformer<Object>) this::execute); | ||
| } | ||
|
|
||
| @Override | ||
| public DataTableType dataTableType() { | ||
| return dataTableType; | ||
| } | ||
|
|
||
| private Object execute(Object arg) throws Throwable { | ||
| return Invoker.invoke(this, body, method, arg); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
java8/src/main/java/io/cucumber/java8/Java8DocStringTypeDefinition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package io.cucumber.java8; | ||
|
|
||
| import io.cucumber.core.backend.DocStringTypeDefinition; | ||
| import io.cucumber.core.exception.CucumberException; | ||
| import io.cucumber.docstring.DocStringType; | ||
| import net.jodah.typetools.TypeResolver; | ||
|
|
||
| final class Java8DocStringTypeDefinition extends AbstractGlueDefinition implements DocStringTypeDefinition { | ||
|
|
||
| private final DocStringType docStringType; | ||
|
|
||
| @Override | ||
| public DocStringType docStringType() { | ||
| return docStringType; | ||
| } | ||
|
|
||
| Java8DocStringTypeDefinition(Object body, String contentType) { | ||
| super(body, new Exception().getStackTrace()[3]); | ||
| if (contentType == null) { | ||
| throw new CucumberException("Docstring content type couldn't be null, define docstring content type"); | ||
| } | ||
| if (contentType.isEmpty()) { | ||
| throw new CucumberException("Docstring content type couldn't be empty, define docstring content type"); | ||
| } | ||
| Class returnType = TypeResolver.resolveRawArguments(DocStringDefinitionBody.class, body.getClass())[0]; | ||
| this.docStringType = new DocStringType( | ||
| returnType, | ||
| contentType, | ||
| this::execute); | ||
| } | ||
|
|
||
| private Object execute(String content) throws Throwable { | ||
| return Invoker.invoke(this, body, method, content); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
java8/src/main/java/io/cucumber/java8/Java8ParameterTypeDefinition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package io.cucumber.java8; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| import io.cucumber.core.backend.ParameterTypeDefinition; | ||
| import io.cucumber.cucumberexpressions.ParameterType; | ||
|
|
||
| import static net.jodah.typetools.TypeResolver.resolveRawArguments; | ||
|
|
||
| class Java8ParameterTypeDefinition extends AbstractGlueDefinition implements ParameterTypeDefinition { | ||
|
|
||
| private final ParameterType parameterType; | ||
|
|
||
| @Override | ||
| public ParameterType<?> parameterType() { | ||
| return parameterType; | ||
| } | ||
|
|
||
| <T extends ParameterDefinitionBody> Java8ParameterTypeDefinition(String name, String regex, Class<T> bodyClass, T body) { | ||
| super(body, new Exception().getStackTrace()[3]); | ||
| Class<?> returnType = resolveRawArguments(bodyClass, body.getClass())[0]; | ||
| this.parameterType = new ParameterType(name, Collections.singletonList(regex), returnType, this::execute); | ||
| } | ||
|
|
||
| private Object execute(String[] parameterContent) throws Throwable { | ||
| return Invoker.invoke(this, body, method, parameterContent); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.