diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-11-13 04:37:27 +0100 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-11-13 04:44:39 +0100 |
commit | 3aace094f336393330ed275e1fb6d6c1f9187e14 (patch) | |
tree | 3c235a645f057a393194bf789fc4ce4bfaaef340 /src/core/lombok/eclipse | |
parent | 219bb4bea5035c370614474f630dac454cfe4223 (diff) | |
download | lombok-3aace094f336393330ed275e1fb6d6c1f9187e14.tar.gz lombok-3aace094f336393330ed275e1fb6d6c1f9187e14.tar.bz2 lombok-3aace094f336393330ed275e1fb6d6c1f9187e14.zip |
[refactor] reflection code streamlined by sending it through the Permit class
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r-- | src/core/lombok/eclipse/EclipseAST.java | 23 | ||||
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 22 |
2 files changed, 11 insertions, 34 deletions
diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java index d53856af..73114c6c 100644 --- a/src/core/lombok/eclipse/EclipseAST.java +++ b/src/core/lombok/eclipse/EclipseAST.java @@ -286,23 +286,8 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { */ public static void addProblemToCompilationResult(char[] fileNameArray, CompilationResult result, boolean isWarning, String message, int sourceStart, int sourceEnd) { - try { - EcjReflectionCheck.addProblemToCompilationResult.invoke(null, fileNameArray, result, isWarning, message, sourceStart, sourceEnd); - } catch (NoClassDefFoundError e) { - //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly - //do anything useful here. - } catch (IllegalAccessException e) { - throw Lombok.sneakyThrow(e); - } catch (InvocationTargetException e) { - throw Lombok.sneakyThrow(e); - } catch (NullPointerException e) { - if (!"false".equals(System.getProperty("lombok.debug.reflection", "false"))) { - e.initCause(EcjReflectionCheck.problemAddProblemToCompilationResult); - throw e; - } - //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly - //do anything useful here. - } + + Permit.invokeSneaky(EcjReflectionCheck.problemAddProblemToCompilationResult, EcjReflectionCheck.addProblemToCompilationResult, null, fileNameArray, result, isWarning, message, sourceStart, sourceEnd); } public static Annotation[] getTopLevelTypeReferenceAnnotations(TypeReference tr) { @@ -310,14 +295,14 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { if (m == null) return null; Annotation[][] annss = null; try { - annss = (Annotation[][]) m.invoke(tr); + annss = (Annotation[][]) Permit.invoke(m, tr); if (annss != null) return annss[0]; } catch (Throwable ignore) {} try { Field f = EcjReflectionCheck.typeReferenceAnnotations; if (f == null) return null; - annss = (Annotation[][]) f.get(tr); + annss = (Annotation[][]) Permit.get(f, tr); if (annss == null) return null; return annss[annss.length - 1]; } catch (Throwable t) { diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 03f26341..5da7abfd 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -373,7 +373,7 @@ public class EclipseHandlerUtil { private static Class<?> getClass(String fqn) { try { return Class.forName(fqn); - } catch (Exception e) { + } catch (Throwable t) { return null; } } @@ -381,7 +381,7 @@ public class EclipseHandlerUtil { private static Field getField(Class<?> c, String fName) { try { return Permit.getField(c, fName); - } catch (Exception e) { + } catch (Throwable t) { return null; } } @@ -2309,18 +2309,10 @@ public class EclipseHandlerUtil { public static IntLiteral makeIntLiteral(char[] token, ASTNode source) { int pS = source == null ? 0 : source.sourceStart, pE = source == null ? 0 : source.sourceEnd; IntLiteral result; - try { - if (intLiteralConstructor != null) { - result = intLiteralConstructor.newInstance(token, pS, pE); - } else { - result = (IntLiteral) intLiteralFactoryMethod.invoke(null, token, pS, pE); - } - } catch (InvocationTargetException e) { - throw Lombok.sneakyThrow(e.getCause()); - } catch (IllegalAccessException e) { - throw Lombok.sneakyThrow(e); - } catch (InstantiationException e) { - throw Lombok.sneakyThrow(e); + if (intLiteralConstructor != null) { + result = Permit.newInstanceSneaky(intLiteralConstructor, token, pS, pE); + } else { + result = (IntLiteral) Permit.invokeSneaky(intLiteralFactoryMethod, null, token, pS, pE); } if (source != null) setGeneratedBy(result, source); @@ -2671,7 +2663,7 @@ public class EclipseHandlerUtil { try { Class.forName("org.eclipse.jdt.internal.core.CompilationUnit"); eclipseMode = true; - } catch (Exception e) { + } catch (Throwable t) { eclipseMode = false; } return eclipseMode; |