Enhancement: make Java8 lambda steps reflection portable and use stable javac APIs
See original GitHub issueSee:
- #912: a JDK upgrade which changed class file layout broke Java8 lambda steps
- #916: closing over local variables breaks Java8 lambda steps
- (currently fixed on branch https://github.com/cucumber/cucumber-jvm/tree/java8-fixes , using the existing Constant Pool inspector)
- #936: Java 8 Lambda steps don’t support Map or List arguments
- (may not be fixable using the the existing Constant Pool inspector)
Currently, for Java8 lambda steps to work, the step runner needs to know the declared type of all arguments to the step body (see Java8StepDefinition.getParameterInfos
).
The declared type can be any runtime type, including primitives like int
, normal classes like String
or generic types like List<String>
. Users can register converters to allow any type for these step params (see cucumber.runtime.ParameterInfo.convert
), including perhaps Object
(although that would be a pathological case, I expect it might need special handling by the reflector and it does seem to be allowed).
It does look to me like we could replace the class ConstantPool inspector with a compile-time Compiler Annotation Processor which records the declared generic types. See e.g. http://stackoverflow.com/questions/29922668/get-typeelement-from-generic-typeparameterelement-for-java-annotation-processor
This would mean that cucumber-jvm would be using a public supported javac API, instead of hacking about with trying to interpret the class files internals (which might change again).
We could either require Cucumber java8 users to annotate their Step files to give cucumber-jvm access to edit the source, or we could do a full project lombok and register a compiler plugin for everyone who compiles anything with cucumber-java8 on the classpath and scan for (and fixup) all calls to En.Given etc.
I’ll see if I can get this to work and submit a POC.
This will need careful testing, and possibly deserve a major release version, as it will greatly change how java8
steps are compiled.
We’ll need to test different compilers and different build tools (Maven, ant, manual javac) and check that they all execute the CAP correctly.
First though, I’ll write a proof of concept to see if this can be made to work at all, and what the code would look like with this new approach.
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (8 by maintainers)
Top GitHub Comments
Love it, great work!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.