You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a need to access the mirror-based instances of elements and types in order to unit test code which deals with them after compiling supplied JavaFileObject instances.
Currently this library only assumes I either want "empty" Elements or Types instance from the rule or that I want to assert about the compilation of JavaFileObjects (optionally processed through some processor). This would be an API that sat between the two allowing for the same compilation of JavaFileObjects but then providing me access to the Elements and Types instances from that compilation.
For this I was thinking of a Compilation class which facilitated building what was to be compiled and any annotation processors to run. Calling .compile produced a Compilation.Result containing methods for access to the exit code, Elements, Types, and generated files (this would solve #58).
Additionally, another subject factory would be added for asserting about a Compilation.Result. Ideally supporting this use-case would simply mean putting a cleaner API around what's already happening internally and then refactoring the current assertion-based usage to use this new API directly.
A contrived example:
Stringinput = ""
+ "package example;\n"
+ "public final class Example {}";
StringinputFile = JavaFileObjects.forSourceString("example.Example", input);
Compilation.Resultresult = Compilation.builder()
.addFileObject(inputFile)
//.addProcessor(..)
.compile();
Elementselements = result.elements();
TypeElementexample = elements.getTypeElement("example.Example");
assertThat(SomeUtility.validateSomething(example)).isTrue();
The text was updated successfully, but these errors were encountered:
I have a need to access the mirror-based instances of elements and types in order to unit test code which deals with them after compiling supplied
JavaFileObject
instances.Currently this library only assumes I either want "empty"
Elements
orTypes
instance from the rule or that I want to assert about the compilation ofJavaFileObjects
(optionally processed through some processor). This would be an API that sat between the two allowing for the same compilation ofJavaFileObjects
but then providing me access to theElements
andTypes
instances from that compilation.For this I was thinking of a
Compilation
class which facilitated building what was to be compiled and any annotation processors to run. Calling.compile
produced aCompilation.Result
containing methods for access to the exit code,Elements
,Types
, and generated files (this would solve #58).Additionally, another subject factory would be added for asserting about a
Compilation.Result
. Ideally supporting this use-case would simply mean putting a cleaner API around what's already happening internally and then refactoring the current assertion-based usage to use this new API directly.A contrived example:
The text was updated successfully, but these errors were encountered: