-
Notifications
You must be signed in to change notification settings - Fork 373
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
Overload unimplemented getCharContent method #96
Conversation
|
||
@Override | ||
public CharSequence getCharContent(final boolean ignoreEncodingErrors) { | ||
return new String(this.os.toByteArray(), Charset.forName("UTF-8")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the encoding can be obtained somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, Charset.forName("UTF-8")
can be replaced with StandardCharsets.UTF_8
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@since 1.7
We still support Java 6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... not in that class, though. So yes, it could be replaced. Will do
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: #81 (comment) |
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
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 |
@GabrielPS |
I did not try other Java versions, sorry. |
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.
Yes, there's a closed source preprocessor for these things.
Don't worry about it. I'll take it from here, once I can see what problem this is solving. |
Is this it? #98, https://github.com/jbreathe/joor-repro |
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. |
Yes, thank you!
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.