Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

arouel
Copy link

@arouel arouel commented Jun 26, 2024

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:

  • Due to the implementation of IdeFilerImpl:236 there is no handling for javax.tools.StandardLocation.SOURCE_PATH implemented and therefore the search for module-info.java fails with a thrown IllegalArgumentException. Ignoring this exception when compiling with the ECJ is fine.
  • There is also a case where the ECJ cannot resolve a type name and the Element parameter is null. Returning an empty Optional enables the caller to fall back.
  • Due to the implementation of IdeInputFileObject:50 the deletion of a FileObject throws an IllegalStateException. 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.

Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the 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.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Jun 26, 2024
@arouel arouel changed the title Get annotation processing running in Eclipse IDE Get annotation processing going with Eclipse Compiler for Java Jun 26, 2024
@@ -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) {
Copy link
Author

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?

Copy link
Member

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.

Copy link
Author

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.

@tomas-langer
Copy link
Member

If you want to go forward with this PR, kindly sign the OCA, as otherwise we cannot accept your contribution.

@arouel
Copy link
Author

arouel commented Jun 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Required At least one contributor does not have an approved Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants