diff options
-rw-r--r-- | src/lombok/core/AnnotationValues.java | 2 | ||||
-rw-r--r-- | src/lombok/core/ShowUserHelp.java | 5 | ||||
-rw-r--r-- | src/lombok/eclipse/EclipseAST.java | 19 | ||||
-rw-r--r-- | src/lombok/eclipse/EclipseASTAdapter.java | 42 | ||||
-rw-r--r-- | src/lombok/eclipse/EclipseASTVisitor.java | 42 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/HandleCleanup.java | 9 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/HandleData.java | 6 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/HandleGetter.java | 2 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/HandlePrintAST.java | 2 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/HandleSetter.java | 2 | ||||
-rw-r--r-- | src/lombok/javac/JavacAST.java | 4 | ||||
-rw-r--r-- | src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java | 31 |
12 files changed, 81 insertions, 85 deletions
diff --git a/src/lombok/core/AnnotationValues.java b/src/lombok/core/AnnotationValues.java index e08d4169..432d507f 100644 --- a/src/lombok/core/AnnotationValues.java +++ b/src/lombok/core/AnnotationValues.java @@ -87,7 +87,7 @@ public class AnnotationValues<A extends Annotation> { public A getInstance() throws AnnotationValueDecodeFail { if ( cachedInstance != null ) return cachedInstance; InvocationHandler invocations = new InvocationHandler() { - @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { AnnotationValue v = values.get(method.getName()); if ( v == null ) { Object defaultValue = method.getDefaultValue(); diff --git a/src/lombok/core/ShowUserHelp.java b/src/lombok/core/ShowUserHelp.java index 0596dcc4..443de833 100644 --- a/src/lombok/core/ShowUserHelp.java +++ b/src/lombok/core/ShowUserHelp.java @@ -1,6 +1,5 @@ package lombok.core; -import java.awt.Desktop; import java.net.URI; /** @@ -13,7 +12,9 @@ public class ShowUserHelp { public static void main(String[] args) { boolean browserOpened = false; try { - Desktop.getDesktop().browse(ABOUT_LOMBOK_URL); + //java.awt.Desktop doesn't exist in 1.5, and for IDE's sakes, we may want to work in java1.5 someday, so... + Object desktop = Class.forName("java.awt.Desktop").getMethod("getDesktop").invoke(null); + Class.forName("java.awt.Desktop").getMethod("browse", URI.class).invoke(desktop, ABOUT_LOMBOK_URL); browserOpened = true; } catch ( Exception ignore ) {} diff --git a/src/lombok/eclipse/EclipseAST.java b/src/lombok/eclipse/EclipseAST.java index d202613b..c5bdd2ff 100644 --- a/src/lombok/eclipse/EclipseAST.java +++ b/src/lombok/eclipse/EclipseAST.java @@ -14,7 +14,6 @@ import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.Argument; -import org.eclipse.jdt.internal.compiler.ast.Block; import org.eclipse.jdt.internal.compiler.ast.Clinit; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; @@ -22,7 +21,6 @@ import org.eclipse.jdt.internal.compiler.ast.ImportReference; import org.eclipse.jdt.internal.compiler.ast.Initializer; import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; import org.eclipse.jdt.internal.compiler.ast.Statement; -import org.eclipse.jdt.internal.compiler.ast.TryStatement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; @@ -149,23 +147,6 @@ public class EclipseAST extends AST<ASTNode> { super(node, children, kind); } - public void rebuild() { - super.rebuild(); - System.out.println("REBUILD COMPLETE"); - AbstractMethodDeclaration me = (AbstractMethodDeclaration) get(); - for ( Statement outer : me.statements ) { - System.out.println("OUTER: "+ outer); - if ( outer instanceof TryStatement ) { - TryStatement ts = (TryStatement)outer; - Block tb = ((TryStatement) outer).tryBlock; - for ( Statement inner : tb.statements ) { - System.out.println("INNER: " + inner); - } - } - } - System.out.println("/REBUILD COMPLETE"); - } - public void traverse(EclipseASTVisitor visitor) { switch ( getKind() ) { case COMPILATION_UNIT: diff --git a/src/lombok/eclipse/EclipseASTAdapter.java b/src/lombok/eclipse/EclipseASTAdapter.java index 61d161d1..da040037 100644 --- a/src/lombok/eclipse/EclipseASTAdapter.java +++ b/src/lombok/eclipse/EclipseASTAdapter.java @@ -13,25 +13,25 @@ import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; public abstract class EclipseASTAdapter implements EclipseASTVisitor { - @Override public void visitCompilationUnit(Node top, CompilationUnitDeclaration unit) {} - @Override public void endVisitCompilationUnit(Node top, CompilationUnitDeclaration unit) {} - @Override public void visitType(Node typeNode, TypeDeclaration type) {} - @Override public void visitAnnotationOnType(TypeDeclaration type, Node annotationNode, Annotation annotation) {} - @Override public void endVisitType(Node typeNode, TypeDeclaration type) {} - @Override public void visitInitializer(Node initializerNode, Initializer initializer) {} - @Override public void endVisitInitializer(Node initializerNode, Initializer initializer) {} - @Override public void visitField(Node fieldNode, FieldDeclaration field) {} - @Override public void visitAnnotationOnField(FieldDeclaration field, Node annotationNode, Annotation annotation) {} - @Override public void endVisitField(Node fieldNode, FieldDeclaration field) {} - @Override public void visitMethod(Node methodNode, AbstractMethodDeclaration method) {} - @Override public void visitAnnotationOnMethod(AbstractMethodDeclaration method, Node annotationNode, Annotation annotation) {} - @Override public void endVisitMethod(Node methodNode, AbstractMethodDeclaration method) {} - @Override public void visitMethodArgument(Node argNode, Argument arg, AbstractMethodDeclaration method) {} - @Override public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, Node annotationNode, Annotation annotation) {} - @Override public void endVisitMethodArgument(Node argNode, Argument arg, AbstractMethodDeclaration method) {} - @Override public void visitLocal(Node localNode, LocalDeclaration local) {} - @Override public void visitAnnotationOnLocal(LocalDeclaration local, Node annotationNode, Annotation annotation) {} - @Override public void endVisitLocal(Node localNode, LocalDeclaration local) {} - @Override public void visitStatement(Node statementNode, Statement statement) {} - @Override public void endVisitStatement(Node statementNode, Statement statement) {} + public void visitCompilationUnit(Node top, CompilationUnitDeclaration unit) {} + public void endVisitCompilationUnit(Node top, CompilationUnitDeclaration unit) {} + public void visitType(Node typeNode, TypeDeclaration type) {} + public void visitAnnotationOnType(TypeDeclaration type, Node annotationNode, Annotation annotation) {} + public void endVisitType(Node typeNode, TypeDeclaration type) {} + public void visitInitializer(Node initializerNode, Initializer initializer) {} + public void endVisitInitializer(Node initializerNode, Initializer initializer) {} + public void visitField(Node fieldNode, FieldDeclaration field) {} + public void visitAnnotationOnField(FieldDeclaration field, Node annotationNode, Annotation annotation) {} + public void endVisitField(Node fieldNode, FieldDeclaration field) {} + public void visitMethod(Node methodNode, AbstractMethodDeclaration method) {} + public void visitAnnotationOnMethod(AbstractMethodDeclaration method, Node annotationNode, Annotation annotation) {} + public void endVisitMethod(Node methodNode, AbstractMethodDeclaration method) {} + public void visitMethodArgument(Node argNode, Argument arg, AbstractMethodDeclaration method) {} + public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, Node annotationNode, Annotation annotation) {} + public void endVisitMethodArgument(Node argNode, Argument arg, AbstractMethodDeclaration method) {} + public void visitLocal(Node localNode, LocalDeclaration local) {} + public void visitAnnotationOnLocal(LocalDeclaration local, Node annotationNode, Annotation annotation) {} + public void endVisitLocal(Node localNode, LocalDeclaration local) {} + public void visitStatement(Node statementNode, Statement statement) {} + public void endVisitStatement(Node statementNode, Statement statement) {} } diff --git a/src/lombok/eclipse/EclipseASTVisitor.java b/src/lombok/eclipse/EclipseASTVisitor.java index bebabc6b..49a8696b 100644 --- a/src/lombok/eclipse/EclipseASTVisitor.java +++ b/src/lombok/eclipse/EclipseASTVisitor.java @@ -129,7 +129,7 @@ public interface EclipseASTVisitor { return sb.toString(); } - @Override public void visitCompilationUnit(Node node, CompilationUnitDeclaration unit) { + public void visitCompilationUnit(Node node, CompilationUnitDeclaration unit) { out.println("---------------------------------------------------------"); out.println(node.isCompleteParse() ? "COMPLETE" : "incomplete"); @@ -137,26 +137,26 @@ public interface EclipseASTVisitor { indent++; } - @Override public void endVisitCompilationUnit(Node node, CompilationUnitDeclaration unit) { + public void endVisitCompilationUnit(Node node, CompilationUnitDeclaration unit) { indent--; print("</CUD>"); } - @Override public void visitType(Node node, TypeDeclaration type) { + public void visitType(Node node, TypeDeclaration type) { print("<TYPE %s>", str(type.name)); indent++; } - @Override public void visitAnnotationOnType(TypeDeclaration type, Node node, Annotation annotation) { + public void visitAnnotationOnType(TypeDeclaration type, Node node, Annotation annotation) { forcePrint("<ANNOTATION: %s />", annotation); } - @Override public void endVisitType(Node node, TypeDeclaration type) { + public void endVisitType(Node node, TypeDeclaration type) { indent--; print("</TYPE %s>", str(type.name)); } - @Override public void visitInitializer(Node node, Initializer initializer) { + public void visitInitializer(Node node, Initializer initializer) { Block block = initializer.block; boolean s = (block != null && block.statements != null); print("<%s INITIALIZER: %s>", @@ -169,13 +169,13 @@ public interface EclipseASTVisitor { } } - @Override public void endVisitInitializer(Node node, Initializer initializer) { + public void endVisitInitializer(Node node, Initializer initializer) { if ( printContent ) disablePrinting--; indent--; print("</%s INITIALIZER>", (initializer.modifiers & Modifier.STATIC) != 0 ? "static" : "instance"); } - @Override public void visitField(Node node, FieldDeclaration field) { + public void visitField(Node node, FieldDeclaration field) { print("<FIELD %s %s = %s>", str(field.type), str(field.name), field.initialization); indent++; if ( printContent ) { @@ -184,17 +184,17 @@ public interface EclipseASTVisitor { } } - @Override public void visitAnnotationOnField(FieldDeclaration field, Node node, Annotation annotation) { + public void visitAnnotationOnField(FieldDeclaration field, Node node, Annotation annotation) { forcePrint("<ANNOTATION: %s />", annotation); } - @Override public void endVisitField(Node node, FieldDeclaration field) { + public void endVisitField(Node node, FieldDeclaration field) { if ( printContent ) disablePrinting--; indent--; print("</FIELD %s %s>", str(field.type), str(field.name)); } - @Override public void visitMethod(Node node, AbstractMethodDeclaration method) { + public void visitMethod(Node node, AbstractMethodDeclaration method) { String type = method instanceof ConstructorDeclaration ? "CONSTRUCTOR" : "METHOD"; print("<%s %s: %s>", type, str(method.selector), method.statements != null ? "filled" : "blank"); indent++; @@ -204,52 +204,52 @@ public interface EclipseASTVisitor { } } - @Override public void visitAnnotationOnMethod(AbstractMethodDeclaration method, Node node, Annotation annotation) { + public void visitAnnotationOnMethod(AbstractMethodDeclaration method, Node node, Annotation annotation) { forcePrint("<ANNOTATION: %s />", annotation); } - @Override public void endVisitMethod(Node node, AbstractMethodDeclaration method) { + public void endVisitMethod(Node node, AbstractMethodDeclaration method) { if ( printContent ) disablePrinting--; String type = method instanceof ConstructorDeclaration ? "CONSTRUCTOR" : "METHOD"; indent--; print("</%s %s>", type, str(method.selector)); } - @Override public void visitMethodArgument(Node node, Argument arg, AbstractMethodDeclaration method) { + public void visitMethodArgument(Node node, Argument arg, AbstractMethodDeclaration method) { print("<METHODARG %s %s = %s>", str(arg.type), str(arg.name), arg.initialization); indent++; } - @Override public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, Node node, Annotation annotation) { + public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, Node node, Annotation annotation) { print("<ANNOTATION: %s />", annotation); } - @Override public void endVisitMethodArgument(Node node, Argument arg, AbstractMethodDeclaration method) { + public void endVisitMethodArgument(Node node, Argument arg, AbstractMethodDeclaration method) { indent--; print("</METHODARG %s %s>", str(arg.type), str(arg.name)); } - @Override public void visitLocal(Node node, LocalDeclaration local) { + public void visitLocal(Node node, LocalDeclaration local) { print("<LOCAL %s %s = %s>", str(local.type), str(local.name), local.initialization); indent++; } - @Override public void visitAnnotationOnLocal(LocalDeclaration local, Node node, Annotation annotation) { + public void visitAnnotationOnLocal(LocalDeclaration local, Node node, Annotation annotation) { print("<ANNOTATION: %s />", annotation); } - @Override public void endVisitLocal(Node node, LocalDeclaration local) { + public void endVisitLocal(Node node, LocalDeclaration local) { indent--; print("</LOCAL %s %s>", str(local.type), str(local.name)); } - @Override public void visitStatement(Node node, Statement statement) { + public void visitStatement(Node node, Statement statement) { print("<%s>", statement.getClass()); indent++; print("%s", statement); } - @Override public void endVisitStatement(Node node, Statement statement) { + public void endVisitStatement(Node node, Statement statement) { indent--; print("</%s>", statement.getClass()); } diff --git a/src/lombok/eclipse/handlers/HandleCleanup.java b/src/lombok/eclipse/handlers/HandleCleanup.java index 908a9b04..f381f25e 100644 --- a/src/lombok/eclipse/handlers/HandleCleanup.java +++ b/src/lombok/eclipse/handlers/HandleCleanup.java @@ -35,9 +35,9 @@ import org.mangosdk.spi.ProviderFor; @ProviderFor(EclipseAnnotationHandler.class) public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> { - @Override public boolean handle(AnnotationValues<Cleanup> annotation, Annotation ast, Node annotationNode) { + public boolean handle(AnnotationValues<Cleanup> annotation, Annotation ast, Node annotationNode) { String cleanupName = annotation.getInstance().cleanupMethod(); - if ( cleanupName.isEmpty() ) { + if ( cleanupName.length() == 0 ) { annotationNode.addError("cleanupName cannot be the empty string."); return true; } @@ -49,6 +49,7 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> { LocalDeclaration decl = (LocalDeclaration)annotationNode.up().get(); + Node ancestor = annotationNode.up().directUp(); ASTNode blockNode = annotationNode.up().directUp().get(); final boolean isSwitch; @@ -124,7 +125,7 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> { //Remove the stuff we just dumped into the tryBlock, AND the close() call, and then leave room for the try node and the unique name. Statement[] newStatements = new Statement[statements.length - (end-start) +1]; System.arraycopy(statements, 0, newStatements, 0, start); - if ( statements.length - end > 0 ) System.arraycopy(statements, end+1, newStatements, start+2, statements.length - end -1); + System.arraycopy(statements, end+1, newStatements, start+2, statements.length - end -1); TryStatement tryStatement = new TryStatement(); newStatements[start+1] = tryStatement; LocalDeclaration tempVar = new LocalDeclaration(("$lombok$cleanup$" + new String(decl.name)).toCharArray(), 0, 0); @@ -200,6 +201,8 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> { ((SwitchStatement)blockNode).statements = newStatements; } + ancestor.rebuild(); + return true; } } diff --git a/src/lombok/eclipse/handlers/HandleData.java b/src/lombok/eclipse/handlers/HandleData.java index c26a2697..c17757c9 100644 --- a/src/lombok/eclipse/handlers/HandleData.java +++ b/src/lombok/eclipse/handlers/HandleData.java @@ -69,7 +69,7 @@ import org.mangosdk.spi.ProviderFor; @ProviderFor(EclipseAnnotationHandler.class) public class HandleData implements EclipseAnnotationHandler<Data> { - @Override public boolean handle(AnnotationValues<Data> annotation, Annotation ast, Node annotationNode) { + public boolean handle(AnnotationValues<Data> annotation, Annotation ast, Node annotationNode) { Data ann = annotation.getInstance(); Node typeNode = annotationNode.up(); @@ -105,11 +105,11 @@ public class HandleData implements EclipseAnnotationHandler<Data> { if ( constructorExists(typeNode) == MethodExistsResult.NOT_EXISTS ) { ConstructorDeclaration constructor = createConstructor( - ann.staticConstructor().isEmpty(), typeNode, nodesForConstructorAndToString, ast); + ann.staticConstructor().length() == 0, typeNode, nodesForConstructorAndToString, ast); injectMethod(typeNode, constructor); } - if ( !ann.staticConstructor().isEmpty() ) { + if ( ann.staticConstructor().length() > 0 ) { if ( methodExists("of", typeNode) == MethodExistsResult.NOT_EXISTS ) { MethodDeclaration staticConstructor = createStaticConstructor( ann.staticConstructor(), typeNode, nodesForConstructorAndToString, ast); diff --git a/src/lombok/eclipse/handlers/HandleGetter.java b/src/lombok/eclipse/handlers/HandleGetter.java index 28e61358..159b49fd 100644 --- a/src/lombok/eclipse/handlers/HandleGetter.java +++ b/src/lombok/eclipse/handlers/HandleGetter.java @@ -45,7 +45,7 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> { createGetterForField(level, fieldNode, errorNode, pos, whineIfExists); } - @Override public boolean handle(AnnotationValues<Getter> annotation, Annotation ast, Node annotationNode) { + public boolean handle(AnnotationValues<Getter> annotation, Annotation ast, Node annotationNode) { Node fieldNode = annotationNode.up(); AccessLevel level = annotation.getInstance().value(); return createGetterForField(level, fieldNode, annotationNode, annotationNode.get(), true); diff --git a/src/lombok/eclipse/handlers/HandlePrintAST.java b/src/lombok/eclipse/handlers/HandlePrintAST.java index cbd2cae1..a2ccad77 100644 --- a/src/lombok/eclipse/handlers/HandlePrintAST.java +++ b/src/lombok/eclipse/handlers/HandlePrintAST.java @@ -16,7 +16,7 @@ import lombok.eclipse.EclipseAST.Node; @ProviderFor(EclipseAnnotationHandler.class) public class HandlePrintAST implements EclipseAnnotationHandler<PrintAST> { - @Override public boolean handle(AnnotationValues<PrintAST> annotation, Annotation ast, Node annotationNode) { + public boolean handle(AnnotationValues<PrintAST> annotation, Annotation ast, Node annotationNode) { if ( !annotationNode.isCompleteParse() ) return false; PrintStream stream = System.out; diff --git a/src/lombok/eclipse/handlers/HandleSetter.java b/src/lombok/eclipse/handlers/HandleSetter.java index 2367d66d..28332bdd 100644 --- a/src/lombok/eclipse/handlers/HandleSetter.java +++ b/src/lombok/eclipse/handlers/HandleSetter.java @@ -49,7 +49,7 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> { createSetterForField(level, fieldNode, errorNode, pos, whineIfExists); } - @Override public boolean handle(AnnotationValues<Setter> annotation, Annotation ast, Node annotationNode) { + public boolean handle(AnnotationValues<Setter> annotation, Annotation ast, Node annotationNode) { Node fieldNode = annotationNode.up(); if ( fieldNode.getKind() != Kind.FIELD ) return false; AccessLevel level = annotation.getInstance().value(); diff --git a/src/lombok/javac/JavacAST.java b/src/lombok/javac/JavacAST.java index ad2be523..a253f8cd 100644 --- a/src/lombok/javac/JavacAST.java +++ b/src/lombok/javac/JavacAST.java @@ -423,8 +423,4 @@ public class JavacAST extends AST<JCTree> { //Very unfortunate, but in most cases it still works fine, so we'll silently swallow it. } } - - @Override protected Node buildStatement(Object statement) { - return buildStatementOrExpression((JCTree) statement); - } } diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java index fd247d5b..cea8e514 100644 --- a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java @@ -5,8 +5,8 @@ import java.io.IOException; import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.IllegalClassFormatException; import java.lang.instrument.Instrumentation; -import java.lang.instrument.UnmodifiableClassException; import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; import java.net.URLDecoder; @@ -20,7 +20,7 @@ public class EclipsePatcher { private EclipsePatcher() {} private static class Patcher implements ClassFileTransformer { - @Override public byte[] transform(ClassLoader loader, String className, + public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { @@ -67,9 +67,17 @@ public class EclipsePatcher { private static void addLombokToSearchPaths(Instrumentation instrumentation) throws Exception { String path = findPathOfOurClassloader(); - instrumentation.appendToSystemClassLoaderSearch(new JarFile(path + "/lombok.jar")); - instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(path + "/lombok.eclipse.agent.jar")); - + //On java 1.5, you don't have these methods, so you'll be forced to manually -Xbootclasspath/a them in. +// instrumentation.appendToSystemClassLoaderSearch(new JarFile(path + "/lombok.jar")); +// instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(path + "/lombok.eclipse.agent.jar")); + tryCallMethod(instrumentation, "appendToSystemClassLoaderSearch", path + "/lombok.jar"); + tryCallMethod(instrumentation, "appendToBootstrapClassLoaderSearch", path + "/lombok.eclipse.agent.jar"); + } + + private static void tryCallMethod(Object o, String methodName, String path) { + try { + Instrumentation.class.getMethod(methodName, JarFile.class).invoke(o, new JarFile(path)); + } catch ( Throwable ignore ) {} } private static String findPathOfOurClassloader() throws Exception { @@ -85,21 +93,28 @@ public class EclipsePatcher { } public static void premain(String agentArgs, Instrumentation instrumentation) throws Exception { + System.out.println("JAVA.VERSION: " + System.getProperty("java.version", "unknown")); registerPatcher(instrumentation, false); addLombokToSearchPaths(instrumentation); } private static void registerPatcher(Instrumentation instrumentation, boolean transformExisting) throws IOException { - instrumentation.addTransformer(new Patcher(), true); + instrumentation.addTransformer(new Patcher()/*, true*/); if ( transformExisting ) for ( Class<?> c : instrumentation.getAllLoadedClasses() ) { if ( c.getName().equals(ECLIPSE_PARSER_CLASS_NAME) || c.getName().equals(ECLIPSE_CUD_CLASS_NAME) ) { try { - instrumentation.retransformClasses(c); - } catch ( UnmodifiableClassException ex ) { + //instrumentation.retransformClasses(c); - //not in java 1.5. + Instrumentation.class.getMethod("retransformClasses", Class[].class).invoke(instrumentation, + new Object[] { new Class[] {c }}); + } catch ( InvocationTargetException e ) { throw new UnsupportedOperationException( "The eclipse parser class is already loaded and cannot be modified. " + "You'll have to restart eclipse in order to use Lombok in eclipse."); + } catch ( Throwable t ) { + throw new UnsupportedOperationException( + "This appears to be a java 1.5 instance, which cannot reload already loaded classes. " + + "You'll have to restart eclipse in order to use Lombok in eclipse."); } } } |