diff options
Diffstat (limited to 'src/eclipseAgent/lombok')
3 files changed, 17 insertions, 20 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java index c11a49cd..ace97a4d 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java @@ -33,6 +33,7 @@ import java.util.List; import lombok.eclipse.EclipseNode; import lombok.eclipse.agent.PatchExtensionMethod.Extension; import lombok.experimental.ExtensionMethod; +import lombok.permit.Permit; import org.eclipse.jdt.core.CompletionProposal; import org.eclipse.jdt.internal.codeassist.InternalCompletionContext; @@ -220,7 +221,7 @@ public class PatchExtensionMethodCompletionProposal { return null; } } - + private static Method accessMethod(Class<?> clazz, String methodName, Class<?> parameter) { try { return makeAccessible(clazz.getDeclaredMethod(methodName, parameter)); @@ -228,10 +229,9 @@ public class PatchExtensionMethodCompletionProposal { return null; } } - + private static <T extends AccessibleObject> T makeAccessible(T object) { - object.setAccessible(true); - return object; + return Permit.setAccessible(object); } } } diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java index fee104d3..8d581819 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java @@ -43,6 +43,8 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; +import lombok.permit.Permit; + import java.lang.reflect.Field; import static lombok.eclipse.Eclipse.poss; @@ -196,8 +198,8 @@ public class PatchVal { Field a = null, b = null; try { - a = LocalDeclaration.class.getDeclaredField("$initCopy"); - b = LocalDeclaration.class.getDeclaredField("$iterableCopy"); + a = Permit.getField(LocalDeclaration.class, "$initCopy"); + b = Permit.getField(LocalDeclaration.class, "$iterableCopy"); } catch (Throwable t) { //ignore - no $initCopy exists when running in ecj. } diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java b/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java index 99447bae..fc6e7de2 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchValEclipse.java @@ -30,6 +30,7 @@ import java.lang.reflect.Method; import java.util.List; import lombok.Lombok; +import lombok.permit.Permit; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.IExtendedModifier; @@ -277,8 +278,7 @@ public class PatchValEclipse { static { Field f = null; try { - f = Name.class.getDeclaredField("index"); - f.setAccessible(true); + f = Permit.getField(Name.class, "index"); } catch (Throwable t) { // Leave it null, in which case we don't set index. That'll result in error log messages but its better than crashing here. } @@ -308,24 +308,19 @@ public class PatchValEclipse { Method h = null; try { - a = LocalDeclaration.class.getDeclaredField("$initCopy"); - b = LocalDeclaration.class.getDeclaredField("$iterableCopy"); + a = Permit.getField(LocalDeclaration.class, "$initCopy"); + b = Permit.getField(LocalDeclaration.class, "$iterableCopy"); } catch (Throwable t) { //ignore - no $initCopy exists when running in ecj. } try { - c = Parser.class.getDeclaredField("astStack"); - c.setAccessible(true); - d = Parser.class.getDeclaredField("astPtr"); - d.setAccessible(true); - f = Modifier.class.getDeclaredConstructor(AST.class); - f.setAccessible(true); - g = MarkerAnnotation.class.getDeclaredConstructor(AST.class); - g.setAccessible(true); + c = Permit.getField(Parser.class, "astStack"); + d = Permit.getField(Parser.class, "astPtr"); + f = Permit.getConstructor(Modifier.class, AST.class); + g = Permit.getConstructor(MarkerAnnotation.class, AST.class); Class<?> z = Class.forName("org.eclipse.jdt.core.dom.ASTConverter"); - h = z.getDeclaredMethod("recordNodes", org.eclipse.jdt.core.dom.ASTNode.class, org.eclipse.jdt.internal.compiler.ast.ASTNode.class); - h.setAccessible(true); + h = Permit.getMethod(z, "recordNodes", org.eclipse.jdt.core.dom.ASTNode.class, org.eclipse.jdt.internal.compiler.ast.ASTNode.class); } catch (Throwable t) { // Most likely we're in ecj or some other plugin usage of the eclipse compiler. No need for this. } |