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

[Eclipse 4.27] Lombok ignores lombok.config #3335

Closed
wants to merge 1 commit into from

Conversation

snjeza
Copy link

@snjeza snjeza commented Jan 21, 2023

Fixes #3332

@matter-it-does
Copy link

@Rawi01
Copy link
Collaborator

Rawi01 commented Jan 27, 2023

I think this can be simplified by loading EclipseWorkspaceBasedFileResolver with the right classloader and calling only the resolve method via reflection.

I tried the patch and it seems to work, but I'm not sure if the way you store the classloader in the EclipseAst is safe. It uses the classloaded of the patched Parser class and if it is part of jdt.core it might break.

I have thought about this but have not found a perfect solution yet. What we need is some kind of global cache through which we can find the right classloader for the call. We have to consider that it is theoretically possible that a bundle occurs several times.

@Rawi01
Copy link
Collaborator

Rawi01 commented Feb 2, 2023

@snjeza I was trying to come up with a simpler patch and ended up with this one. It also has the advantage that all the class loading stuff is in the same place.

diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
index c7bdbc3..bd318f9 100755
--- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java
+++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
@@ -200,6 +200,13 @@
 			if (TRANSFORM != null) return;
 			
 			Main.prependClassLoader(prepend);
+			try {
+				ClassLoader currentClassLoader = Transform.class.getClassLoader();
+				Method prependParentMethod = Util.findMethod(currentClassLoader.getClass(), "prependParent", ClassLoader.class);
+				prependParentMethod.invoke(currentClassLoader, prepend);
+			} catch (Throwable t) {
+				// Ignore
+			}
 			Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.TransformEclipseAST");
 			TRANSFORM = Util.findMethodAnyArgs(shadowed, "transform");
 			TRANSFORM_SWAPPED = Util.findMethodAnyArgs(shadowed, "transform_swapped");

@snjeza
Copy link
Author

snjeza commented Feb 2, 2023

@Rawi01 I have tried your patch. It doesn't fix the issue described at redhat-developer/vscode-java#2887
lombok.eclipse.EclipseAST still can't resolve org.eclipse.core.resources.ResourcesPlugin.class - See https://github.com/projectlombok/lombok/blob/master/src/core/lombok/eclipse/EclipseAST.java#L191

@Rawi01
Copy link
Collaborator

Rawi01 commented Feb 2, 2023

You are right, sorry for wasting your time. I used the Permit class in an earlier version but thought that it would be better to replace it with Util. No idea why I did not notice during my test that this breaks everything. Added an updated diff below.

Lombok adds a ShadowClassLoader to every module. Instead of loading the RessourcePlugin by hand my idea is to prepend the jdt.core SCL to the compiler.batch SCL. This should enable lombok to use classes of jdt.core without additional workarounds.

diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
index c7bdbc3..5404ee1 100755
--- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java
+++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java
@@ -60,6 +60,8 @@
 import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup;
 import org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment;
 
+import lombok.permit.Permit;
+
 import static lombok.eclipse.EcjAugments.ASTNode_generatedBy;
 
 /** These contain a mix of the following:
@@ -200,6 +202,13 @@
 			if (TRANSFORM != null) return;
 			
 			Main.prependClassLoader(prepend);
+			try {
+				ClassLoader currentClassLoader = Transform.class.getClassLoader();
+				Method prependParentMethod = Permit.getMethod(currentClassLoader.getClass(), "prependParent", ClassLoader.class);
+				Permit.invoke(prependParentMethod, currentClassLoader, prepend);
+			} catch (Throwable t) {
+				// Ignore
+			}
 			Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.TransformEclipseAST");
 			TRANSFORM = Util.findMethodAnyArgs(shadowed, "transform");
 			TRANSFORM_SWAPPED = Util.findMethodAnyArgs(shadowed, "transform_swapped");

@snjeza
Copy link
Author

snjeza commented Feb 2, 2023

@Rawi01 It works fine.

@snjeza
Copy link
Author

snjeza commented Feb 2, 2023

I have closed this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Eclipse 4.27] Lombok ignores lombok.config
3 participants