From 3aace094f336393330ed275e1fb6d6c1f9187e14 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 13 Nov 2020 04:37:27 +0100 Subject: [refactor] reflection code streamlined by sending it through the Permit class --- src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java') diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java index b90d5762..99367a22 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java @@ -101,6 +101,7 @@ import lombok.eclipse.EclipseNode; import lombok.eclipse.TransformEclipseAST; import lombok.eclipse.handlers.SetGeneratedByVisitor; import lombok.patcher.Symbols; +import lombok.permit.Permit; public class PatchDelegate { @@ -846,18 +847,20 @@ public class PatchDelegate { private static final class Reflection { public static final Method classScopeBuildFieldsAndMethodsMethod; - + public static final Throwable initCause; static { Method m = null; + Throwable c = null; try { - m = ClassScope.class.getDeclaredMethod("buildFieldsAndMethods"); - m.setAccessible(true); + m = Permit.getMethod(ClassScope.class, "buildFieldsAndMethods"); } catch (Throwable t) { + c = t; // That's problematic, but as long as no local classes are used we don't actually need it. // Better fail on local classes than crash altogether. } classScopeBuildFieldsAndMethodsMethod = m; + initCause = c; } } @@ -894,16 +897,14 @@ public class PatchDelegate { ClassScope cs = ((SourceTypeBinding)inner).scope; if (cs != null) { try { - Reflection.classScopeBuildFieldsAndMethodsMethod.invoke(cs); + Permit.invoke(Reflection.initCause, Reflection.classScopeBuildFieldsAndMethodsMethod, cs); } catch (Exception e) { // See 'Reflection' class for why we ignore this exception. } } } - if (!(binding instanceof ReferenceBinding)) { - return; - } + if (!(binding instanceof ReferenceBinding)) return; ReferenceBinding rb = (ReferenceBinding) binding; MethodBinding[] availableMethods = rb.availableMethods(); -- cgit