Closed gabrielps closed 4 years ago
What problem is this solving? Can you please add a description and/or a test case that would fail if you hadn't added this method?
It solves issue 81, the second problem that was reported: https://github.com/jOOQ/jOOR/issues/81#issuecomment-598634178
I'll try to setup a unit test.
It may be a problem with the integration with https://github.com/square/javapoet when using it to generate code in the Processor. It seems that when writing the source code, it delegates the creation of the JavaFileObject to the filer (https://github.com/square/javapoet/blob/44622704248975ca398b90b4385005fdddeb35f9/src/main/java/com/squareup/javapoet/JavaFile.java#L164).
Im not really sure how the internals are working, but it seems that the generated file is being handled by https://github.com/jOOQ/jOOR/blob/1e6b04b2086ea0f4341e36753c7b523746f7a3d9/jOOR-java-8/src/main/java/org/joor/Compile.java#L211
I'm not sure if you want to maintain the integration with javapoet (I think it would be cool, plus it only needs this harmless tweak). I'm willing to add a unit test, but I'll have to add the javapoet dependency.
@gabrielps I don't think there is a problem with JavaPoet. Filer is a standard and preferable way for reading and writing files in the Annotation Processor.
@gabrielps Btw, you made a change in the "jOOR-java-8" module, but what about "jOOR" (for Java 9+, if I understand correctly)? @lukaseder Do you use some kind of generation tool and only support Java 9 implementation with tags ([java-8], [java-9], ...) or how does it all work?
I did not try other Java versions, sorry.
@gabrielps I don't think there is a problem with JavaPoet. Filer is a standard and preferable way for reading and writing files in the Annotation Processor.
Is there a simple way to call this method in a unit test without any third party assumptions? I think the suggested code is fine as it is, but I prefer not to accept any PRs without understanding what specific problem is being fixed.
Do you use some kind of generation tool and only support Java 9 implementation with tags ([java-8], [java-9], ...) or how does it all work?
Yes, there's a closed source preprocessor for these things.
I did not try other Java versions, sorry.
Don't worry about it. I'll take it from here, once I can see what problem this is solving.
I'll merge it without a test for now. If you can think of a test, feel free...
I tried to setup a test, but had no time. Sorry :(
No worries, thanks again.
@lukaseder
Is this it? #98, https://github.com/jbreathe/joor-repro
Yes, thank you! I will close #98 in a minute.
Is there a simple way to call this method in a unit test without any third party assumptions?
I think yes. Give me a few minutes, I will try to change the code in my repro.
upd: something like this:
String rawSource = javaFile.toString();
try {
javaFile.writeTo(processingEnv.getFiler());
JavaFileObject implSourceFile = processingEnv.getFiler().createSourceFile(packageName + "." + implName);
try (Writer writer = implSourceFile.openWriter()) {
writer.append(rawSource);
}
} catch (IOException e) {
...
}
It seems that to be able to integrate with JavaPoet code generation tool this little tweak is needed.