-
Notifications
You must be signed in to change notification settings - Fork 561
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
Get annotation processing going with Eclipse Compiler for Java #8913
base: main
Are you sure you want to change the base?
Conversation
Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application. When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated. If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public. |
@@ -101,7 +101,7 @@ private static Optional<ModuleInfo> findModule(Filer filer) { | |||
try (InputStream in = resource.openInputStream()) { | |||
return Optional.of(ModuleInfoSourceParser.parse(in)); | |||
} | |||
} catch (IOException ignored) { | |||
} catch (Exception ignored) { |
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.
Should we consider catching IOException
and IllegalArgumentException
instead?
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.
I think catching Exception
is sufficient here, as it shows that there was "a" problem getting the module-info.java
. As we have some fallback mechanism here, and we do not require it, it should be fine.
It may be interesting to find an alternative for Eclipse IDE (is there "any" way to get the module info?), because we use the module info to get the module name, which is used in some generated types (the worst case here is that the used name will be unnamed/package-name
) for documentation purposes.
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.
I double-checked the ECJ implementation and it only handles javax.tools.StandardLocation
values that point to generated source code. Which means, we can't do anything here. We would need to adapt the ECJ and implement the missing cases we need.
If you want to go forward with this PR, kindly sign the OCA, as otherwise we cannot accept your contribution. |
@tomas-langer I added one more commit to handle the last case I had issues with when using Eclipse IDE. Can you have a look at it as well? I signed the OCA already, I guess it needs a bit to be approved. |
Problem
I'm writing a HTTP feature for Helidon (related to #8897) and want to work with Eclipse IDE, but the Helidon annotation processors throw an exception because the Eclipse Compiler for Java (ECJ) behaves slightly different compared to javac.
Solution
Two changes were necessary to get the annotation processing going:
javax.tools.StandardLocation.SOURCE_PATH
implemented and therefore the search formodule-info.java
fails with a thrownIllegalArgumentException
. Ignoring this exception when compiling with the ECJ is fine.Element
parameter is null. Returning an emptyOptional
enables the caller to fall back.FileObject
throws anIllegalStateException
. Ignoring any exception when compiling with the ECJ should be fine.I have successfully tested the changes suggested here in a current Eclipse IDE (
Version: 2024-06 (4.32.0)
) on my local computer.