jOOQ / jOOR

jOOR - Fluent Reflection in Java jOOR is a very simple fluent API that gives access to your Java Class structures in a more intuitive way. The JDK's reflection APIs are hard and verbose to use. Other languages have much simpler constructs to access type meta information at runtime. Let us make Java reflection better.
http://www.jooq.org/products
Apache License 2.0
2.81k stars 376 forks source link

Overload unimplemented getCharContent method #96

Closed gabrielps closed 4 years ago

gabrielps commented 4 years ago

It seems that to be able to integrate with JavaPoet code generation tool this little tweak is needed.

lukaseder commented 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?

gabrielps commented 4 years ago

It solves issue 81, the second problem that was reported: https://github.com/jOOQ/jOOR/issues/81#issuecomment-598634178

gabrielps commented 4 years ago

I'll try to setup a unit test.

gabrielps commented 4 years ago

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.

ghost commented 4 years ago

@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.

ghost commented 4 years ago

@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?

gabrielps commented 4 years ago

I did not try other Java versions, sorry.

lukaseder commented 4 years ago

@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.

lukaseder commented 4 years ago

Is this it? https://github.com/jOOQ/jOOR/issues/98, https://github.com/jbreathe/joor-repro

lukaseder commented 4 years ago

I'll merge it without a test for now. If you can think of a test, feel free...

gabrielps commented 4 years ago

I tried to setup a test, but had no time. Sorry :(

lukaseder commented 4 years ago

No worries, thanks again.

ghost commented 4 years ago

@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) {
    ...
}