diff options
Diffstat (limited to 'src/core/lombok')
-rw-r--r-- | src/core/lombok/core/AnnotationProcessor.java | 2 | ||||
-rw-r--r-- | src/core/lombok/eclipse/EclipseAST.java | 23 | ||||
-rw-r--r-- | src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java | 22 | ||||
-rw-r--r-- | src/core/lombok/javac/Javac6BasedLombokOptions.java | 2 | ||||
-rw-r--r-- | src/core/lombok/javac/JavacAST.java | 38 | ||||
-rw-r--r-- | src/core/lombok/javac/JavacResolution.java | 20 | ||||
-rw-r--r-- | src/core/lombok/javac/apt/InterceptingJavaFileObject.java | 13 | ||||
-rw-r--r-- | src/core/lombok/javac/apt/LombokProcessor.java | 18 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/HandleDelegate.java | 5 | ||||
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 4 |
10 files changed, 48 insertions, 99 deletions
diff --git a/src/core/lombok/core/AnnotationProcessor.java b/src/core/lombok/core/AnnotationProcessor.java index c72d1bb2..c9171284 100644 --- a/src/core/lombok/core/AnnotationProcessor.java +++ b/src/core/lombok/core/AnnotationProcessor.java @@ -174,7 +174,7 @@ public class AnnotationProcessor extends AbstractProcessor { if (!ClassLoader_lombokAlreadyAddedTo.getAndSet(environmentClassLoader, true)) { Method m = Permit.getMethod(environmentClassLoader.getClass(), "addURL", URL.class); URL selfUrl = new File(ClassRootFinder.findClassRootOfClass(AnnotationProcessor.class)).toURI().toURL(); - m.invoke(environmentClassLoader, selfUrl); + Permit.invoke(m, environmentClassLoader, selfUrl); } } 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; diff --git a/src/core/lombok/javac/Javac6BasedLombokOptions.java b/src/core/lombok/javac/Javac6BasedLombokOptions.java index fc73181c..93f448a7 100644 --- a/src/core/lombok/javac/Javac6BasedLombokOptions.java +++ b/src/core/lombok/javac/Javac6BasedLombokOptions.java @@ -58,7 +58,7 @@ public class Javac6BasedLombokOptions extends LombokOptions { @Override public void putJavacOption(String optionName, String value) { try { - options_put.invoke(this, optionName_valueOf.invoke(null, optionName), value); + Permit.invoke(options_put, this, Permit.invoke(optionName_valueOf, null, optionName), value); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Can't initialize Javac6-based lombok options due to reflection issue.", e); } catch (InvocationTargetException e) { diff --git a/src/core/lombok/javac/JavacAST.java b/src/core/lombok/javac/JavacAST.java index 86ff7646..22373cbe 100644 --- a/src/core/lombok/javac/JavacAST.java +++ b/src/core/lombok/javac/JavacAST.java @@ -397,11 +397,7 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> { } private JCTree getBody(JCTree jcTree) { - try { - return (JCTree) getBodyMethod(jcTree.getClass()).invoke(jcTree); - } catch (Exception e) { - throw Javac.sneakyThrow(e); - } + return (JCTree) Permit.invokeSneaky(getBodyMethod(jcTree.getClass()), jcTree); } private final static ConcurrentMap<Class<?>, Method> getBodyMethods = new ConcurrentHashMap<Class<?>, Method>(); @@ -662,42 +658,26 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> { } @Override void error1(DiagnosticPosition pos, String message) { - try { - Object error = this.errorKey.invoke(diags, PROC_MESSAGER, new Object[] { message }); - errorMethod.invoke(log, multiple, pos, error); - } catch (Throwable t) { - //t.printStackTrace(); - } + Object error = Permit.invokeSneaky(this.errorKey, diags, PROC_MESSAGER, new Object[] { message }); + if (error != null) Permit.invokeSneaky(errorMethod, log, multiple, pos, error); } @Override void warning1(DiagnosticPosition pos, String message) { - try { - Object warning = this.warningKey.invoke(diags, PROC_MESSAGER, new Object[] { message }); - warningMethod.invoke(log, pos, warning); - } catch (Throwable t) { - //t.printStackTrace(); - } + Object warning = Permit.invokeSneaky(this.warningKey, diags, PROC_MESSAGER, new Object[] { message }); + if (warning != null) Permit.invokeSneaky(warningMethod, log, pos, warning); } @Override void mandatoryWarning1(DiagnosticPosition pos, String message) { - try { - Object warning = this.warningKey.invoke(diags, PROC_MESSAGER, new Object[] { message }); - mandatoryWarningMethod.invoke(log, pos, warning); - } catch (Throwable t) { - //t.printStackTrace(); - } + Object warning = Permit.invokeSneaky(this.warningKey, diags, PROC_MESSAGER, new Object[] { message }); + if (warning != null) Permit.invokeSneaky(mandatoryWarningMethod, log, pos, warning); } @Override void note(DiagnosticPosition pos, String message) { - try { - Object note = this.noteKey.invoke(diags, PROC_MESSAGER, new Object[] { message }); - noteMethod.invoke(log, pos, note); - } catch (Throwable t) { - //t.printStackTrace(); - } + Object note = Permit.invokeSneaky(this.noteKey, diags, PROC_MESSAGER, new Object[] { message }); + if (note != null) Permit.invokeSneaky(noteMethod, log, pos, note); } } } diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java index 6b2f4637..63ca69dd 100644 --- a/src/core/lombok/javac/JavacResolution.java +++ b/src/core/lombok/javac/JavacResolution.java @@ -25,7 +25,6 @@ import static lombok.javac.Javac.*; import static lombok.javac.JavacTreeMaker.TypeTag.typeTag; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayDeque; import java.util.Collection; @@ -65,7 +64,6 @@ import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Name; -import lombok.Lombok; import lombok.core.debug.AssertionLogger; import lombok.permit.Permit; @@ -251,27 +249,27 @@ public class JavacResolution { private static class ReflectiveAccess { private static Method UPPER_BOUND; + private static Throwable initError; static { Method upperBound = null; try { upperBound = Permit.getMethod(Types.class, "upperBound", Type.class); - } catch (Throwable ignore) {} + } catch (Throwable e) { + initError = e; + } + if (upperBound == null) try { upperBound = Permit.getMethod(Types.class, "wildUpperBound", Type.class); - } catch (Throwable ignore) {} + } catch (Throwable e) { + initError = e; + } UPPER_BOUND = upperBound; } public static Type Types_upperBound(Types types, Type type) { - try { - return (Type) UPPER_BOUND.invoke(types, type); - } catch (InvocationTargetException e) { - throw Lombok.sneakyThrow(e.getCause()); - } catch (Exception e) { - throw Lombok.sneakyThrow(e); - } + return (Type) Permit.invokeSneaky(initError, UPPER_BOUND, types, type); } } diff --git a/src/core/lombok/javac/apt/InterceptingJavaFileObject.java b/src/core/lombok/javac/apt/InterceptingJavaFileObject.java index 368928d4..403b5672 100644 --- a/src/core/lombok/javac/apt/InterceptingJavaFileObject.java +++ b/src/core/lombok/javac/apt/InterceptingJavaFileObject.java @@ -38,6 +38,7 @@ import javax.tools.JavaFileObject; import lombok.Lombok; import lombok.core.DiagnosticsReceiver; import lombok.core.PostCompiler; +import lombok.permit.Permit; final class InterceptingJavaFileObject implements LombokFileObject { private final JavaFileObject delegate; @@ -63,16 +64,8 @@ final class InterceptingJavaFileObject implements LombokFileObject { } @Override public CharsetDecoder getDecoder(boolean ignoreEncodingErrors) { - if (decoderMethod == null) { - throw new UnsupportedOperationException(); - } - try { - return (CharsetDecoder) decoderMethod.invoke(delegate, ignoreEncodingErrors); - } catch (IllegalAccessException e) { - throw Lombok.sneakyThrow(e); - } catch (InvocationTargetException e) { - throw Lombok.sneakyThrow(e); - } + if (decoderMethod == null) throw new UnsupportedOperationException(); + return (CharsetDecoder) Permit.invokeSneaky(decoderMethod, delegate, ignoreEncodingErrors); } @Override public boolean equals(Object obj) { diff --git a/src/core/lombok/javac/apt/LombokProcessor.java b/src/core/lombok/javac/apt/LombokProcessor.java index 67df5b20..485b82a4 100644 --- a/src/core/lombok/javac/apt/LombokProcessor.java +++ b/src/core/lombok/javac/apt/LombokProcessor.java @@ -156,10 +156,10 @@ public class LombokProcessor extends AbstractProcessor { disablePartialReparseInNetBeansEditor(context); try { Method keyMethod = Permit.getMethod(Context.class, "key", Class.class); - Object key = keyMethod.invoke(context, JavaFileManager.class); + Object key = Permit.invoke(keyMethod, context, JavaFileManager.class); Field htField = Permit.getField(Context.class, "ht"); @SuppressWarnings("unchecked") - Map<Object,Object> ht = (Map<Object,Object>) htField.get(context); + Map<Object,Object> ht = (Map<Object,Object>) Permit.get(htField, context); final JavaFileManager originalFiler = (JavaFileManager) ht.get(key); if (!(originalFiler instanceof InterceptingJavaFileManager)) { final Messager messager = processingEnv.getMessager(); @@ -182,10 +182,10 @@ public class LombokProcessor extends AbstractProcessor { private void replaceFileManagerJdk9(Context context, JavaFileManager newFiler) { try { - JavaCompiler compiler = (JavaCompiler) Permit.getMethod(JavaCompiler.class, "instance", Context.class).invoke(null, context); + JavaCompiler compiler = (JavaCompiler) Permit.invoke(Permit.getMethod(JavaCompiler.class, "instance", Context.class), null, context); try { Field fileManagerField = Permit.getField(JavaCompiler.class, "fileManager"); - fileManagerField.set(compiler, newFiler); + Permit.set(fileManagerField, compiler, newFiler); } catch (Exception e) {} @@ -193,7 +193,7 @@ public class LombokProcessor extends AbstractProcessor { Field writerField = Permit.getField(JavaCompiler.class, "writer"); ClassWriter writer = (ClassWriter) writerField.get(compiler); Field fileManagerField = Permit.getField(ClassWriter.class, "fileManager"); - fileManagerField.set(writer, newFiler); + Permit.set(fileManagerField, writer, newFiler); } catch (Exception e) {} } @@ -215,8 +215,8 @@ public class LombokProcessor extends AbstractProcessor { private void disablePartialReparseInNetBeansEditor(Context context) { try { Class<?> cancelServiceClass = Class.forName("com.sun.tools.javac.util.CancelService"); - Method cancelServiceInstace = Permit.getMethod(cancelServiceClass, "instance", Context.class); - Object cancelService = cancelServiceInstace.invoke(null, context); + Method cancelServiceInstance = Permit.getMethod(cancelServiceClass, "instance", Context.class); + Object cancelService = Permit.invoke(cancelServiceInstance, null, context); if (cancelService == null) return; Field parserField = Permit.getField(cancelService.getClass(), "parser"); Object parser = parserField.get(cancelService); @@ -388,8 +388,8 @@ public class LombokProcessor extends AbstractProcessor { try { if (qualifiedNamableClass == null) qualifiedNamableClass = Class.forName("javax.lang.model.element.QualifiedNamable"); if (!qualifiedNamableClass.isInstance(element)) return null; - if (qualifiedNamableQualifiedNameMethod == null) qualifiedNamableQualifiedNameMethod = qualifiedNamableClass.getMethod("getQualifiedName"); - String name = qualifiedNamableQualifiedNameMethod.invoke(element).toString().trim(); + if (qualifiedNamableQualifiedNameMethod == null) qualifiedNamableQualifiedNameMethod = Permit.getMethod(qualifiedNamableClass, "getQualifiedName"); + String name = Permit.invoke(qualifiedNamableQualifiedNameMethod, element).toString().trim(); return name.isEmpty() ? null : name; } catch (ClassNotFoundException e) { return null; diff --git a/src/core/lombok/javac/handlers/HandleDelegate.java b/src/core/lombok/javac/handlers/HandleDelegate.java index d6e76ab1..ac414fbb 100644 --- a/src/core/lombok/javac/handlers/HandleDelegate.java +++ b/src/core/lombok/javac/handlers/HandleDelegate.java @@ -81,6 +81,7 @@ import lombok.javac.JavacResolution; import lombok.javac.JavacResolution.TypeNotConvertibleException; import lombok.javac.JavacTreeMaker; import lombok.javac.ResolutionResetNeeded; +import lombok.permit.Permit; @ProviderFor(JavacAnnotationHandler.class) @HandlerPriority(HandleDelegate.HANDLE_DELEGATE_PRIORITY) //2^16; to make sure that we also delegate generated methods. @@ -466,7 +467,7 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> { static { Method m = null; try { - m = Type.class.getDeclaredMethod("unannotatedType"); + m = Permit.getMethod(Type.class, "unannotatedType"); } catch (Exception e) {/* ignore */} unannotated = m; } @@ -474,7 +475,7 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> { static Type unannotatedType(Type t) { if (unannotated == null) return t; try { - return (Type) unannotated.invoke(t); + return (Type) Permit.invoke(unannotated, t); } catch (Exception e) { return t; } diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 8d21f903..df1eb438 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1183,7 +1183,7 @@ public class JavacHandlerUtil { try { Scope scope = (Scope) membersField.get(from); if (scope == null) return; - removeMethod.invoke(scope, toRemove); + Permit.invoke(removeMethod, scope, toRemove); } catch (Exception e) {} } @@ -1192,7 +1192,7 @@ public class JavacHandlerUtil { try { Scope scope = (Scope) membersField.get(from); if (scope == null) return; - enterMethod.invoke(scope, toEnter); + Permit.invoke(enterMethod, scope, toEnter); } catch (Exception e) {} } } |