From 27a3efeb1cb6f79ecefc6e641ba78de6d69406c3 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Sat, 26 Sep 2009 09:00:12 +0200 Subject: Rewrite of the eclipse agent to use the new lombok.patcher project. --- .classpath | 1 + lib/eclipse.agent/lombok-patcher.jar | Bin 0 -> 66886 bytes .../java/lombok/eclipse/ClassLoaderWorkaround.java | 4 + .../java/lombok/eclipse/PatchFixes.java | 14 ++ .../agent/EclipseASTConverterTransformer.java | 95 ----------- .../eclipse/agent/EclipseASTNodeTransformer.java | 68 -------- .../eclipse/agent/EclipseCUDTransformer.java | 66 -------- .../eclipse/agent/EclipseParserTransformer.java | 178 --------------------- .../lombok/eclipse/agent/EclipsePatcher.java | 59 +++++++ 9 files changed, 78 insertions(+), 407 deletions(-) create mode 100644 lib/eclipse.agent/lombok-patcher.jar create mode 100644 src_eclipseagent/java/lombok/eclipse/PatchFixes.java delete mode 100644 src_eclipseagent/lombok/eclipse/agent/EclipseASTConverterTransformer.java delete mode 100644 src_eclipseagent/lombok/eclipse/agent/EclipseASTNodeTransformer.java delete mode 100644 src_eclipseagent/lombok/eclipse/agent/EclipseCUDTransformer.java delete mode 100644 src_eclipseagent/lombok/eclipse/agent/EclipseParserTransformer.java diff --git a/.classpath b/.classpath index adbcc311..95ce615b 100644 --- a/.classpath +++ b/.classpath @@ -18,5 +18,6 @@ + diff --git a/lib/eclipse.agent/lombok-patcher.jar b/lib/eclipse.agent/lombok-patcher.jar new file mode 100644 index 00000000..3c22f4f0 Binary files /dev/null and b/lib/eclipse.agent/lombok-patcher.jar differ diff --git a/src_eclipseagent/java/lombok/eclipse/ClassLoaderWorkaround.java b/src_eclipseagent/java/lombok/eclipse/ClassLoaderWorkaround.java index f5c8bbd3..3d8e9ec9 100644 --- a/src_eclipseagent/java/lombok/eclipse/ClassLoaderWorkaround.java +++ b/src_eclipseagent/java/lombok/eclipse/ClassLoaderWorkaround.java @@ -52,6 +52,10 @@ public class ClassLoaderWorkaround { private static final Map transform = new HashMap(); + public static void transformCompilationUnitDeclarationSwapped(Object cud, Object parser) throws Exception { + transformCompilationUnitDeclaration(parser, cud); + } + public static void transformCompilationUnitDeclaration(Object parser, Object cud) throws Exception { Method transformMethod = getTransformMethod(cud); try { diff --git a/src_eclipseagent/java/lombok/eclipse/PatchFixes.java b/src_eclipseagent/java/lombok/eclipse/PatchFixes.java new file mode 100644 index 00000000..23c60d32 --- /dev/null +++ b/src_eclipseagent/java/lombok/eclipse/PatchFixes.java @@ -0,0 +1,14 @@ +package java.lombok.eclipse; + +public class PatchFixes { + public static int fixRetrieveStartingCatchPosition(int in) { + return in; + } + + private static final int BIT24 = 0x800000; + + public static boolean checkBit24(Object node) throws Exception { + int bits = (Integer)(node.getClass().getField("bits").get(node)); + return (bits & BIT24) != 0; + } +} diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipseASTConverterTransformer.java b/src_eclipseagent/lombok/eclipse/agent/EclipseASTConverterTransformer.java deleted file mode 100644 index 4245e246..00000000 --- a/src_eclipseagent/lombok/eclipse/agent/EclipseASTConverterTransformer.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package lombok.eclipse.agent; - -import org.mangosdk.spi.ProviderFor; -import org.objectweb.asm.ClassAdapter; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.MethodAdapter; -import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; - -/** - * Transforms Eclipse's org.eclipse.jdt.core.dom.ASTConverter class, which sometimes rescans bits and pieces - * of source files because Eclipse's own AST doesn't actually have enough information for eclipse (why they don't just fix - * the AST tree generator is beyond me). At any rate, for catch blocks generated by lombok, eclipse tries to rescan the - * source file to find the source position of the catch statement, which will of course fail as there's nothing there. - * We will fix the code to return the original starting position, which is a pretty good simile, instead of '-1', which - * screws up all sorts of things. - * - * Transformations applied:
    - *
  • The retrieveStartingCatchPosition(int, int) method is instrumented to return its first parameter - * instead of the constant -1.
- */ -@ProviderFor(EclipseTransformer.class) -public class EclipseASTConverterTransformer implements EclipseTransformer { - public byte[] transform(byte[] classfileBuffer) { - ClassReader reader = new ClassReader(classfileBuffer); - ClassWriter writer = new ClassWriter(reader, 0); - - ClassAdapter adapter = new ASTConverterPatcherAdapter(writer); - reader.accept(adapter, 0); - return writer.toByteArray(); - } - - private static class ASTConverterPatcherAdapter extends ClassAdapter { - public ASTConverterPatcherAdapter(ClassVisitor cv) { - super(cv); - } - - @Override public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - MethodVisitor writerVisitor = super.visitMethod(access, name, desc, signature, exceptions); - if ( !name.equals("retrieveStartingCatchPosition") ) return writerVisitor; - - return new RetrieveStartingCatchPositionPatcher(writerVisitor); - } - } - - static class RetrieveStartingCatchPositionPatcher extends MethodAdapter { - RetrieveStartingCatchPositionPatcher(MethodVisitor mv) { - super(mv); - } - - int count = 0; - @Override public void visitInsn(int opcode) { - if ( opcode == Opcodes.IRETURN ) { - if ( count++ == 0 ) { - super.visitInsn(opcode); - return; - } - //replaces: "return -1" with "return [firstParam]"; - super.visitInsn(Opcodes.POP); - super.visitVarInsn(Opcodes.ILOAD, 1); - super.visitInsn(Opcodes.IRETURN); - } else { - super.visitInsn(opcode); - } - } - } - - @Override public String getTargetClassName() { - return "org/eclipse/jdt/core/dom/ASTConverter"; - } -} diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipseASTNodeTransformer.java b/src_eclipseagent/lombok/eclipse/agent/EclipseASTNodeTransformer.java deleted file mode 100644 index e27aa08c..00000000 --- a/src_eclipseagent/lombok/eclipse/agent/EclipseASTNodeTransformer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package lombok.eclipse.agent; - -import org.mangosdk.spi.ProviderFor; -import org.objectweb.asm.ClassAdapter; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.Opcodes; - -/** - * Transforms Eclipse's {@code org.eclipse.jdt.internal.compiler.ast.ASTNode} class, - * which is the super-class of all AST Node class for Eclipse. - * - * Transformations applied:
    - *
  • A field is added: 'public transient ASTNode $generatedBy = null;'. It is set to something other than {@code null} if - * this node is generated; the reference then points at the node that is responsible for its generation (example: a {@code @Data} annotation).
- */ -@ProviderFor(EclipseTransformer.class) -public class EclipseASTNodeTransformer implements EclipseTransformer { - private static final String ASTNODE = "org/eclipse/jdt/internal/compiler/ast/ASTNode"; - - public byte[] transform(byte[] classfileBuffer) { - ClassReader reader = new ClassReader(classfileBuffer); - ClassWriter writer = new ClassWriter(reader, 0); - - ClassAdapter adapter = new ASTNodePatcherAdapter(writer); - reader.accept(adapter, 0); - return writer.toByteArray(); - } - - private static class ASTNodePatcherAdapter extends ClassAdapter { - ASTNodePatcherAdapter(ClassVisitor cv) { - super(cv); - } - - @Override public void visitEnd() { - FieldVisitor fv = cv.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$generatedBy", "L" + ASTNODE + ";", null, null); - fv.visitEnd(); - cv.visitEnd(); - } - } - - @Override public String getTargetClassName() { - return ASTNODE; - } -} diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipseCUDTransformer.java b/src_eclipseagent/lombok/eclipse/agent/EclipseCUDTransformer.java deleted file mode 100644 index b18a1ff1..00000000 --- a/src_eclipseagent/lombok/eclipse/agent/EclipseCUDTransformer.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package lombok.eclipse.agent; - -import org.mangosdk.spi.ProviderFor; -import org.objectweb.asm.ClassAdapter; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.Opcodes; - -/** - * Transforms Eclipse's org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration class, - * which is the top-level AST Node class for Eclipse. - * - * Transformations applied:
    - *
  • A field is added: 'public transient Object $lombokAST = null;'. We use it to cache our own AST object, - * usually of type lombok.eclipse.EclipseAST.
- */ -@ProviderFor(EclipseTransformer.class) -public class EclipseCUDTransformer implements EclipseTransformer { - public byte[] transform(byte[] classfileBuffer) { - ClassReader reader = new ClassReader(classfileBuffer); - ClassWriter writer = new ClassWriter(reader, 0); - - ClassAdapter adapter = new CUDPatcherAdapter(writer); - reader.accept(adapter, 0); - return writer.toByteArray(); - } - - private static class CUDPatcherAdapter extends ClassAdapter { - CUDPatcherAdapter(ClassVisitor cv) { - super(cv); - } - - @Override public void visitEnd() { - FieldVisitor fv = cv.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$lombokAST", "Ljava/lang/Object;", null, null); - fv.visitEnd(); - cv.visitEnd(); - } - } - - @Override public String getTargetClassName() { - return "org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration"; - } -} diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipseParserTransformer.java b/src_eclipseagent/lombok/eclipse/agent/EclipseParserTransformer.java deleted file mode 100644 index 38917332..00000000 --- a/src_eclipseagent/lombok/eclipse/agent/EclipseParserTransformer.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package lombok.eclipse.agent; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import lombok.Lombok; - -import org.mangosdk.spi.ProviderFor; -import org.objectweb.asm.ClassAdapter; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodAdapter; -import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; - -/** - * Transforms Eclipse's org.eclipse.jdt.internal.compiler.parser.Parser class, - * which handles all the actual java source to AST tree conversion in eclipse. - * - * Transformations applied:
    - *
  • The CompilationUnitDeclaration endParse(int) method is instrumented to call - * the lombok framework via ClassLoaderWorkaround to TransformEclipseAST with the CompilationUnitDeclaration - * right before it returns the CompilationUnitDeclaration.
  • - *
  • The getMethodBodies(CompilationUnitDeclaration) is similarly instrumented; eclipse uses a - * 2-step parsing system, where the bodies of methods aren't filled in until its actually neccessary. Lombok - * gets a chance to change the AST immediately after either step.
  • - *
  • The parse(MethodDeclaration, CUD), parse(ConstructorDeclaration, CUD) and - * parse(Initializer, TypeDeclaration, CUD) methods are all instrumented to not attempt to - * complete parsing a method generated by lombok, as the source positions are obviously all wrong - * (the method content isn't in the source file!) - lombok has already filled in the complete AST. - * - * Bit24 on the flags field on all ASTNode objects is used as a marker.
- */ -@ProviderFor(EclipseTransformer.class) -public class EclipseParserTransformer implements EclipseTransformer { - private static final String COMPILER_PKG = - "Lorg/eclipse/jdt/internal/compiler/ast/"; - private static final String TARGET_STATIC_CLASS = "java/lombok/eclipse/ClassLoaderWorkaround"; - private static final String TARGET_STATIC_METHOD_NAME = "transformCompilationUnitDeclaration"; - private static final String TARGET_STATIC_METHOD_DESC = "(Ljava/lang/Object;Ljava/lang/Object;)V"; - - private static final Map> rewriters; - - static { - Map> map = new HashMap>(); - map.put(String.format("endParse(I)%sCompilationUnitDeclaration;", COMPILER_PKG), EndParsePatcher.class); - map.put(String.format("getMethodBodies(%sCompilationUnitDeclaration;)V", COMPILER_PKG), GetMethodBodiesPatcher.class); - map.put(String.format("parse(%1$sMethodDeclaration;%1$sCompilationUnitDeclaration;)V", COMPILER_PKG), ParseBlockContainerPatcher.class); - map.put(String.format("parse(%1$sConstructorDeclaration;%1$sCompilationUnitDeclaration;Z)V", COMPILER_PKG), ParseBlockContainerPatcher.class); - map.put(String.format("parse(%1$sInitializer;%1$sTypeDeclaration;%1$sCompilationUnitDeclaration;)V", COMPILER_PKG), ParseBlockContainerPatcher.class); - rewriters = Collections.unmodifiableMap(map); - } - - public byte[] transform(byte[] classfileBuffer) { - ClassReader reader = new ClassReader(classfileBuffer); - ClassWriter writer = new ClassWriter(reader, 0); - - ClassAdapter adapter = new ParserPatcherAdapter(writer); - reader.accept(adapter, 0); - return writer.toByteArray(); - } - - private static class ParserPatcherAdapter extends ClassAdapter { - public ParserPatcherAdapter(ClassVisitor cv) { - super(cv); - } - - @Override public MethodVisitor visitMethod(int access, String name, String desc, - String signature, String[] exceptions) { - MethodVisitor writerVisitor = super.visitMethod(access, name, desc, signature, exceptions); - Class targetVisitorClass = rewriters.get(name+desc); - if ( targetVisitorClass == null ) return writerVisitor; - - try { - Constructor c = targetVisitorClass.getDeclaredConstructor(MethodVisitor.class); - c.setAccessible(true); - return c.newInstance(writerVisitor); - } catch ( InvocationTargetException e ) { - throw Lombok.sneakyThrow(e.getCause()); - } catch ( Exception e ) { - //NoSuchMethodException: We know they exist. - //IllegalAccessException: We called setAccessible. - //InstantiationException: None of these classes are abstract. - throw Lombok.sneakyThrow(e); - } - } - } - - private static final int BIT24 = 0x800000; - - static class GetMethodBodiesPatcher extends MethodAdapter { - GetMethodBodiesPatcher(MethodVisitor mv) { - super(mv); - } - - @Override public void visitInsn(int opcode) { - if ( opcode == Opcodes.RETURN ) { - //injects: ClassLoaderWorkaround.transformCUD(parser, compilationUnitDeclaration); - super.visitVarInsn(Opcodes.ALOAD, 0); - super.visitVarInsn(Opcodes.ALOAD, 1); - super.visitMethodInsn(Opcodes.INVOKESTATIC, TARGET_STATIC_CLASS, - TARGET_STATIC_METHOD_NAME, TARGET_STATIC_METHOD_DESC); - } - super.visitInsn(opcode); - } - } - - static class ParseBlockContainerPatcher extends MethodAdapter { - ParseBlockContainerPatcher(MethodVisitor mv) { - super(mv); - } - - @Override public void visitCode() { - //injects: if ( constructorDeclaration.bits & BIT24 > 0 ) return; - mv.visitVarInsn(Opcodes.ALOAD, 1); - mv.visitFieldInsn(Opcodes.GETFIELD, "org/eclipse/jdt/internal/compiler/ast/ASTNode", "bits", "I"); - mv.visitLdcInsn(Integer.valueOf(BIT24)); - mv.visitInsn(Opcodes.IAND); - Label l0 = new Label(); - mv.visitJumpInsn(Opcodes.IFLE, l0); - mv.visitInsn(Opcodes.RETURN); - mv.visitLabel(l0); - mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); - super.visitCode(); - } - } - - static class EndParsePatcher extends MethodAdapter { - private static final String TARGET_STATIC_METHOD_NAME = "transformCompilationUnitDeclaration"; - - EndParsePatcher(MethodVisitor mv) { - super(mv); - } - - @Override public void visitInsn(int opcode) { - if ( opcode == Opcodes.ARETURN ) { - //injects: ClassLoaderWorkaround.transformCUD(parser, compilationUnitDeclaration); - super.visitInsn(Opcodes.DUP); - super.visitVarInsn(Opcodes.ALOAD, 0); - super.visitInsn(Opcodes.SWAP); - super.visitMethodInsn(Opcodes.INVOKESTATIC, TARGET_STATIC_CLASS, - TARGET_STATIC_METHOD_NAME, TARGET_STATIC_METHOD_DESC); - } - - super.visitInsn(opcode); - } - } - - @Override public String getTargetClassName() { - return "org/eclipse/jdt/internal/compiler/parser/Parser"; - } -} diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java index 7659302c..c7aa48ff 100644 --- a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java @@ -37,8 +37,17 @@ import java.util.jar.JarFile; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.objectweb.asm.Opcodes; + import lombok.Lombok; import lombok.core.SpiLoadUtil; +import lombok.patcher.Hook; +import lombok.patcher.MethodTarget; +import lombok.patcher.ScriptManager; +import lombok.patcher.StackRequest; +import lombok.patcher.scripts.AddFieldScript; +import lombok.patcher.scripts.ExitFromMethodEarlyScript; +import lombok.patcher.scripts.WrapReturnValuesScript; /** * This is a java-agent that patches some of eclipse's classes so AST Nodes are handed off to Lombok @@ -108,6 +117,56 @@ public class EclipsePatcher { public static void premain(String agentArgs, Instrumentation instrumentation) throws Exception { registerPatcher(instrumentation, false); addLombokToSearchPaths(instrumentation); + ScriptManager sm = new ScriptManager(); + sm.registerTransformer(instrumentation); + + sm.addScript(new WrapReturnValuesScript( + new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveStartingCatchPosition"), + new Hook("java/lombok/eclipse/PatchFixes", "fixRetrieveStartingCatchPosition", "(I)I"), + StackRequest.PARAM1)); + + sm.addScript(new AddFieldScript("org.eclipse.jdt.internal.compiler.ast.ASTNode", + Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$generatedBy", "Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;")); + + sm.addScript(new AddFieldScript("org.eclipse.jdt.core.dom.ASTNode", + Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$isGenerated", "Z")); + + sm.addScript(new AddFieldScript("org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", + Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$lombokAST", "Ljava/lang/Object;")); + + sm.addScript(new WrapReturnValuesScript( + new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "getMethodBodies", "void", + "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"), + new Hook("java/lombok/eclipse/ClassLoaderWorkaround", "transformCompilationUnitDeclaration", + "(Ljava/lang/Object;Ljava/lang/Object;)V"), StackRequest.THIS, StackRequest.PARAM1)); + + sm.addScript(new WrapReturnValuesScript( + new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "endParse", + "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", "int"), + new Hook("java/lombok/eclipse/ClassLoaderWorkaround", "transformCompilationUnitDeclarationSwapped", + "(Ljava/lang/Object;Ljava/lang/Object;)V"), StackRequest.THIS, StackRequest.RETURN_VALUE)); + + sm.addScript(new ExitFromMethodEarlyScript( + new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "parse", "void", + "org.eclipse.jdt.internal.compiler.ast.MethodDeclaration", + "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"), + new Hook("java/lombok/eclipse/PatchFixes", "checkBit24", + "(Ljava/lang/Object;)Z"), null, StackRequest.PARAM1)); + + sm.addScript(new ExitFromMethodEarlyScript( + new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "parse", "void", + "org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration", + "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", "boolean"), + new Hook("java/lombok/eclipse/PatchFixes", "checkBit24", + "(Ljava/lang/Object;)Z"), null, StackRequest.PARAM1)); + + sm.addScript(new ExitFromMethodEarlyScript( + new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "parse", "void", + "org.eclipse.jdt.internal.compiler.ast.Initializer", + "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", + "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"), + new Hook("java/lombok/eclipse/PatchFixes", "checkBit24", + "(Ljava/lang/Object;)Z"), null, StackRequest.PARAM1)); } private static void registerPatcher(Instrumentation instrumentation, boolean transformExisting) throws IOException { -- cgit From b3d191e30023a4d80ffc88646446f2df0bc2f353 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 29 Sep 2009 17:15:24 +0200 Subject: Everything seems to be working smoothly! Perhaps time to make this the main branch... --- lib/eclipse.agent/lombok-patcher.jar | Bin 66886 -> 84217 bytes src/lombok/eclipse/TransformEclipseAST.java | 4 + .../java/lombok/eclipse/ClassLoaderWorkaround.java | 134 --------------- .../java/lombok/eclipse/PatchFixes.java | 14 -- .../java/lombok/eclipse/package-info.java | 27 --- .../lombok/eclipse/agent/EclipsePatcher.java | 186 +++++++-------------- .../lombok/eclipse/agent/PatchFixes.java | 14 ++ 7 files changed, 74 insertions(+), 305 deletions(-) delete mode 100644 src_eclipseagent/java/lombok/eclipse/ClassLoaderWorkaround.java delete mode 100644 src_eclipseagent/java/lombok/eclipse/PatchFixes.java delete mode 100644 src_eclipseagent/java/lombok/eclipse/package-info.java create mode 100644 src_eclipseagent/lombok/eclipse/agent/PatchFixes.java diff --git a/lib/eclipse.agent/lombok-patcher.jar b/lib/eclipse.agent/lombok-patcher.jar index 3c22f4f0..18a8ba63 100644 Binary files a/lib/eclipse.agent/lombok-patcher.jar and b/lib/eclipse.agent/lombok-patcher.jar differ diff --git a/src/lombok/eclipse/TransformEclipseAST.java b/src/lombok/eclipse/TransformEclipseAST.java index 365b65a2..b975dc3e 100644 --- a/src/lombok/eclipse/TransformEclipseAST.java +++ b/src/lombok/eclipse/TransformEclipseAST.java @@ -90,6 +90,10 @@ public class TransformEclipseAST { //potential speedup: if trace contains org.eclipse.swt.widgets. -> stop - nothing interesting ever follows that. I think. } + public static void transform_swapped(CompilationUnitDeclaration ast, Parser parser) { + transform(parser, ast); + } + /** * This method is called immediately after Eclipse finishes building a CompilationUnitDeclaration, which is * the top-level AST node when Eclipse parses a source file. The signature is 'magic' - you should not diff --git a/src_eclipseagent/java/lombok/eclipse/ClassLoaderWorkaround.java b/src_eclipseagent/java/lombok/eclipse/ClassLoaderWorkaround.java deleted file mode 100644 index 3d8e9ec9..00000000 --- a/src_eclipseagent/java/lombok/eclipse/ClassLoaderWorkaround.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package java.lombok.eclipse; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - - -/** - * Allows you to inject the lombok classes into any classloader, even if that classloader does not - * know how to find the lombok classes. - * - * Example: Injecting lombok's Eclipse Parser patching code into eclipse's OSGi BundleLoader. - * - * @author rzwitserloot - */ -public class ClassLoaderWorkaround { - static RuntimeException sneakyThrow(Throwable t) { - if ( t == null ) throw new NullPointerException("t"); - ClassLoaderWorkaround.sneakyThrow0(t); - return null; - } - - @SuppressWarnings("unchecked") - private static void sneakyThrow0(Throwable t) throws T { - throw (T)t; - } - - private static final Map transform = new HashMap(); - - public static void transformCompilationUnitDeclarationSwapped(Object cud, Object parser) throws Exception { - transformCompilationUnitDeclaration(parser, cud); - } - - public static void transformCompilationUnitDeclaration(Object parser, Object cud) throws Exception { - Method transformMethod = getTransformMethod(cud); - try { - transformMethod.invoke(null, parser, cud); - } catch ( InvocationTargetException e ) { - throw sneakyThrow(e.getCause()); - } - } - - private static Method getTransformMethod(Object cud) throws ClassNotFoundException { - ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); - - synchronized ( transform ) { - if ( !transform.containsKey(contextLoader)) { - transform.put(contextLoader, findTransformMethod(cud)); - } - - Method m = transform.get(contextLoader); - if ( m == null ) throw new ClassNotFoundException("lombok.eclipse.TransformEclipseAST"); - return m; - - } - } - - private static Method findTransformMethod(Object cud) throws ClassNotFoundException { - final ClassLoader parent = cud.getClass().getClassLoader(); - ClassLoader loader = new ClassLoader() { - @Override public Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - if ( name.startsWith("lombok.") ) { - InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream(name.replace(".", "/") + ".class"); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - byte[] b = new byte[65536]; - try { - while ( true ) { - int r = in.read(b); - if ( r == -1 ) break; - if ( r > 0 ) out.write(b, 0, r); - } - - in.close(); - byte[] data = out.toByteArray(); - Class result = defineClass(name, data, 0, data.length); - if ( resolve ) resolveClass(result); - return result; - } catch ( IOException e ) { - throw new ClassNotFoundException(); - } - } else { - try { - Class result = ClassLoader.getSystemClassLoader().loadClass(name); - if ( resolve ) resolveClass(result); - return result; - } catch ( ClassNotFoundException e ) { - Class result = parent.loadClass(name); - if ( resolve ) resolveClass(result); - return result; - } - } - } - }; - - Class c = loader.loadClass("lombok.eclipse.TransformEclipseAST"); - for ( Method method : c.getMethods() ) { - if ( method.getName().equals("transform") ) { - Class[] types = method.getParameterTypes(); - if ( types.length != 2 ) continue; - if ( !types[0].getName().equals("org.eclipse.jdt.internal.compiler.parser.Parser") ) continue; - if ( !types[1].getName().equals("org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration") ) continue; - return method; - } - } - - throw new ClassNotFoundException("lombok.eclipse.TransformEclipseAST"); - } -} diff --git a/src_eclipseagent/java/lombok/eclipse/PatchFixes.java b/src_eclipseagent/java/lombok/eclipse/PatchFixes.java deleted file mode 100644 index 23c60d32..00000000 --- a/src_eclipseagent/java/lombok/eclipse/PatchFixes.java +++ /dev/null @@ -1,14 +0,0 @@ -package java.lombok.eclipse; - -public class PatchFixes { - public static int fixRetrieveStartingCatchPosition(int in) { - return in; - } - - private static final int BIT24 = 0x800000; - - public static boolean checkBit24(Object node) throws Exception { - int bits = (Integer)(node.getClass().getField("bits").get(node)); - return (bits & BIT24) != 0; - } -} diff --git a/src_eclipseagent/java/lombok/eclipse/package-info.java b/src_eclipseagent/java/lombok/eclipse/package-info.java deleted file mode 100644 index 2ec8031f..00000000 --- a/src_eclipseagent/java/lombok/eclipse/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -/** - * Workaround package to avoid the OSGi class loader system, which will always refer to the system class loader for any classes in a package - * that starts with java. - */ -package java.lombok.eclipse; diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java index c7aa48ff..83b6ec94 100644 --- a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java @@ -21,33 +21,14 @@ */ package lombok.eclipse.agent; -import java.io.File; -import java.io.IOException; -import java.lang.instrument.ClassFileTransformer; -import java.lang.instrument.IllegalClassFormatException; import java.lang.instrument.Instrumentation; -import java.lang.reflect.InvocationTargetException; -import java.net.URI; -import java.net.URLDecoder; -import java.nio.charset.Charset; -import java.security.ProtectionDomain; -import java.util.HashMap; -import java.util.Map; -import java.util.jar.JarFile; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.objectweb.asm.Opcodes; - -import lombok.Lombok; -import lombok.core.SpiLoadUtil; import lombok.patcher.Hook; import lombok.patcher.MethodTarget; import lombok.patcher.ScriptManager; import lombok.patcher.StackRequest; -import lombok.patcher.scripts.AddFieldScript; -import lombok.patcher.scripts.ExitFromMethodEarlyScript; -import lombok.patcher.scripts.WrapReturnValuesScript; +import lombok.patcher.equinox.EquinoxClassLoader; +import lombok.patcher.scripts.ScriptBuilder; /** * This is a java-agent that patches some of eclipse's classes so AST Nodes are handed off to Lombok @@ -59,135 +40,80 @@ import lombok.patcher.scripts.WrapReturnValuesScript; public class EclipsePatcher { private EclipsePatcher() {} - private static Map transformers = new HashMap(); - static { - try { - for ( EclipseTransformer transformer : SpiLoadUtil.findServices(EclipseTransformer.class) ) { - String targetClassName = transformer.getTargetClassName(); - transformers.put(targetClassName, transformer); - } - } catch ( Throwable t ) { - throw Lombok.sneakyThrow(t); - } - } - - private static class Patcher implements ClassFileTransformer { - public byte[] transform(ClassLoader loader, String className, - Class classBeingRedefined, - ProtectionDomain protectionDomain, byte[] classfileBuffer) - throws IllegalClassFormatException { - -// ClassLoader classLoader = Patcher.class.getClassLoader(); -// if ( classLoader == null ) classLoader = ClassLoader.getSystemClassLoader(); - - EclipseTransformer transformer = transformers.get(className); - if ( transformer != null ) return transformer.transform(classfileBuffer); - - return null; - } - } - public static void agentmain(String agentArgs, Instrumentation instrumentation) throws Exception { - registerPatcher(instrumentation, true); - addLombokToSearchPaths(instrumentation); - } - - private static void addLombokToSearchPaths(Instrumentation instrumentation) throws Exception { - String path = findPathOfOurClassloader(); - //On java 1.5, you don't have these methods, so you'll be forced to manually -Xbootclasspath/a them in. - tryCallMethod(instrumentation, "appendToSystemClassLoaderSearch", path + "/lombok.jar"); - tryCallMethod(instrumentation, "appendToBootstrapClassLoaderSearch", path + "/lombok.eclipse.agent.jar"); + registerPatchScripts(instrumentation, true); } - 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 { - URI uri = EclipsePatcher.class.getResource("/" + EclipsePatcher.class.getName().replace('.', '/') + ".class").toURI(); - Pattern p = Pattern.compile("^jar:file:([^\\!]+)\\!.*\\.class$"); - Matcher m = p.matcher(uri.toString()); - if ( !m.matches() ) return "."; - String rawUri = m.group(1); - return new File(URLDecoder.decode(rawUri, Charset.defaultCharset().name())).getParent(); + public static void premain(String agentArgs, Instrumentation instrumentation) throws Exception { + registerPatchScripts(instrumentation, false); } - public static void premain(String agentArgs, Instrumentation instrumentation) throws Exception { - registerPatcher(instrumentation, false); - addLombokToSearchPaths(instrumentation); + private static void registerPatchScripts(Instrumentation instrumentation, boolean reloadExistingClasses) { ScriptManager sm = new ScriptManager(); sm.registerTransformer(instrumentation); + EquinoxClassLoader.getInstance().addPrefix("lombok."); + EquinoxClassLoader.getInstance().registerScripts(sm); - sm.addScript(new WrapReturnValuesScript( - new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveStartingCatchPosition"), - new Hook("java/lombok/eclipse/PatchFixes", "fixRetrieveStartingCatchPosition", "(I)I"), - StackRequest.PARAM1)); + sm.addScript(ScriptBuilder.wrapReturnValue() + .target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "retrieveStartingCatchPosition")) + .wrapMethod(new Hook("lombok/eclipse/agent/PatchFixes", "fixRetrieveStartingCatchPosition", "(I)I")) + .transplant().request(StackRequest.PARAM1).build()); - sm.addScript(new AddFieldScript("org.eclipse.jdt.internal.compiler.ast.ASTNode", - Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$generatedBy", "Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;")); + sm.addScript(ScriptBuilder.addField() + .targetClass("org.eclipse.jdt.internal.compiler.ast.ASTNode") + .fieldName("$generatedBy") + .fieldType("Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;") + .setPublic().setTransient().build()); - sm.addScript(new AddFieldScript("org.eclipse.jdt.core.dom.ASTNode", - Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$isGenerated", "Z")); + sm.addScript(ScriptBuilder.addField() + .targetClass("org.eclipse.jdt.core.dom.ASTNode") + .fieldName("$isGenerated").fieldType("Z") + .setPublic().setTransient().build()); - sm.addScript(new AddFieldScript("org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", - Opcodes.ACC_PUBLIC | Opcodes.ACC_TRANSIENT, "$lombokAST", "Ljava/lang/Object;")); + sm.addScript(ScriptBuilder.addField() + .targetClass("org.eclipse.jdt.internal.compiler.CompilationUnitDeclaration") + .fieldName("$lombokAST").fieldType("Ljava/lang/Object;") + .setPublic().setTransient().build()); - sm.addScript(new WrapReturnValuesScript( - new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "getMethodBodies", "void", - "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"), - new Hook("java/lombok/eclipse/ClassLoaderWorkaround", "transformCompilationUnitDeclaration", - "(Ljava/lang/Object;Ljava/lang/Object;)V"), StackRequest.THIS, StackRequest.PARAM1)); + final String PARSER_SIG1 = "org.eclipse.jdt.internal.compiler.parser.Parser"; + final String PARSER_SIG2 = "Lorg/eclipse/jdt/internal/compiler/parser/Parser;"; + final String CUD_SIG1 = "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"; + final String CUD_SIG2 = "Lorg/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration;"; - sm.addScript(new WrapReturnValuesScript( - new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "endParse", - "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", "int"), - new Hook("java/lombok/eclipse/ClassLoaderWorkaround", "transformCompilationUnitDeclarationSwapped", - "(Ljava/lang/Object;Ljava/lang/Object;)V"), StackRequest.THIS, StackRequest.RETURN_VALUE)); + sm.addScript(ScriptBuilder.wrapReturnValue() + .target(new MethodTarget(PARSER_SIG1, "getMethodBodies", "void", CUD_SIG1)) + .wrapMethod(new Hook("lombok/eclipse/TransformEclipseAST", "transform", + "(" + PARSER_SIG2 + CUD_SIG2 + ")V")) + .request(StackRequest.THIS, StackRequest.PARAM1).build()); - sm.addScript(new ExitFromMethodEarlyScript( - new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "parse", "void", + sm.addScript(ScriptBuilder.wrapReturnValue() + .target(new MethodTarget(PARSER_SIG1, "endParse", CUD_SIG1, "int")) + .wrapMethod(new Hook("lombok/eclipse/TransformEclipseAST", "transform_swapped", + "(" + CUD_SIG2 + PARSER_SIG2 + ")V")) + .request(StackRequest.THIS, StackRequest.RETURN_VALUE).build()); + + sm.addScript(ScriptBuilder.exitEarly() + .target(new MethodTarget(PARSER_SIG1, "parse", "void", "org.eclipse.jdt.internal.compiler.ast.MethodDeclaration", - "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"), - new Hook("java/lombok/eclipse/PatchFixes", "checkBit24", - "(Ljava/lang/Object;)Z"), null, StackRequest.PARAM1)); + "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration")) + .decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z")) + .transplant().request(StackRequest.PARAM1).build()); - sm.addScript(new ExitFromMethodEarlyScript( - new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "parse", "void", + sm.addScript(ScriptBuilder.exitEarly() + .target(new MethodTarget(PARSER_SIG1, "parse", "void", "org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration", - "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", "boolean"), - new Hook("java/lombok/eclipse/PatchFixes", "checkBit24", - "(Ljava/lang/Object;)Z"), null, StackRequest.PARAM1)); + "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration", "boolean")) + .decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z")) + .transplant().request(StackRequest.PARAM1).build()); - sm.addScript(new ExitFromMethodEarlyScript( - new MethodTarget("org.eclipse.jdt.internal.compiler.parser.Parser", "parse", "void", + sm.addScript(ScriptBuilder.exitEarly() + .target(new MethodTarget(PARSER_SIG1, "parse", "void", "org.eclipse.jdt.internal.compiler.ast.Initializer", "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", - "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration"), - new Hook("java/lombok/eclipse/PatchFixes", "checkBit24", - "(Ljava/lang/Object;)Z"), null, StackRequest.PARAM1)); - } - - private static void registerPatcher(Instrumentation instrumentation, boolean transformExisting) throws IOException { - instrumentation.addTransformer(new Patcher()/*, true*/); + "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration")) + .decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z")) + .transplant().request(StackRequest.PARAM1).build()); - if ( transformExisting ) for ( Class c : instrumentation.getAllLoadedClasses() ) { - if ( transformers.containsKey(c.getName()) ) { - try { - //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."); - } - } - } + if (reloadExistingClasses) sm.reloadClasses(instrumentation); } } diff --git a/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java b/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java new file mode 100644 index 00000000..e36823b2 --- /dev/null +++ b/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java @@ -0,0 +1,14 @@ +package lombok.eclipse.agent; + +public class PatchFixes { + public static int fixRetrieveStartingCatchPosition(int in) { + return in; + } + + private static final int BIT24 = 0x800000; + + public static boolean checkBit24(Object node) throws Exception { + int bits = (Integer)(node.getClass().getField("bits").get(node)); + return (bits & BIT24) != 0; + } +} -- cgit From 9096735921a607244806c14ab651a9329862fb9e Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 29 Sep 2009 19:01:08 +0200 Subject: bugfix in name of class to patch. --- src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java index 83b6ec94..c8fdab28 100644 --- a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java @@ -71,7 +71,7 @@ public class EclipsePatcher { .setPublic().setTransient().build()); sm.addScript(ScriptBuilder.addField() - .targetClass("org.eclipse.jdt.internal.compiler.CompilationUnitDeclaration") + .targetClass("org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration") .fieldName("$lombokAST").fieldType("Ljava/lang/Object;") .setPublic().setTransient().build()); -- cgit From dba1a7c64f9c56efcbbb7cf01be4e25938fed69b Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 29 Sep 2009 19:01:33 +0200 Subject: latest version of lombok-patcher. --- lib/eclipse.agent/lombok-patcher.jar | Bin 84217 -> 83840 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/eclipse.agent/lombok-patcher.jar b/lib/eclipse.agent/lombok-patcher.jar index 18a8ba63..d7f58c31 100644 Binary files a/lib/eclipse.agent/lombok-patcher.jar and b/lib/eclipse.agent/lombok-patcher.jar differ -- cgit From 1f9d6089cd4392eeaeef55fcc4ff0dcb5b382f3a Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 7 Oct 2009 20:48:07 +0200 Subject: build.xml was getting rather large, so its been split up into separate scripts. The scripts have also gained the ability to build certain dependencies, such as lombok.patcher which is being worked on in tandem with this project, automatically. Also, the deps system has been changed slightly; the agents builds and the main lombok build now all work off of a single dependency directory. Also removed the website/publish script, as we haven't used github's project hosting for some time now. --- .classpath | 3 +- build.xml | 419 +++-------------------------------- buildScripts/compile.ant.xml | 131 +++++++++++ buildScripts/deps.ant.xml | 46 ++++ buildScripts/maven.ant.xml | 111 ++++++++++ buildScripts/publish.ant.xml | 75 +++++++ buildScripts/website.ant.xml | 224 +++++++++++++++++++ deps/README | 3 +- deps/eclipse.agent/spi-0.2.3-pre.jar | Bin 23926 -> 0 bytes deps/lombok/tools.jar | Bin 0 -> 12546055 bytes deps/tools.jar | Bin 12546055 -> 0 bytes website/publish | 37 ---- 12 files changed, 619 insertions(+), 430 deletions(-) create mode 100644 buildScripts/compile.ant.xml create mode 100644 buildScripts/deps.ant.xml create mode 100644 buildScripts/maven.ant.xml create mode 100644 buildScripts/publish.ant.xml create mode 100644 buildScripts/website.ant.xml delete mode 100644 deps/eclipse.agent/spi-0.2.3-pre.jar create mode 100644 deps/lombok/tools.jar delete mode 100644 deps/tools.jar delete mode 100755 website/publish diff --git a/.classpath b/.classpath index 95ce615b..f1f8e5fa 100644 --- a/.classpath +++ b/.classpath @@ -3,7 +3,6 @@ - @@ -17,7 +16,7 @@ - + diff --git a/build.xml b/build.xml index 3cfa376c..54f1266b 100644 --- a/build.xml +++ b/build.xml @@ -20,208 +20,14 @@ THE SOFTWARE. --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + This buildfile is part of projectlombok.org. It is the main entry point that contains +the common tasks and can be called on to run the main aspects of all the sub-scripts. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Now upload dist/website.tar.bz2 to the webserver. - If you want to host projectlombok.org on github, run the website/publish script, but this is not where the site is currently hosted. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - lombok.javac.apt.Processor - - - - - - - - - - - - - - - - - - - - - - - - + Lombok version: ${lombok.version} - - - - - - - Welcome to the lombok javadoc. If you're just looking to learn more about using lombok - You probably want to look at the feature documentation. Otherwise, - check the lombok package. If you're trying to extend lombok or - write your own plugins, the other packages are what you're looking for. - ]]> - - - - -
Lombok - ]]>v${lombok.version}
- Copyright © 2009 Reinier Zwitserloot and Roel Spilker, licensed under the MIT licence.]]> -
- - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - + + + + + - - - - - + + + + - - #username=[your google account name without @gmail.com] -#password=[your googlecode password, is NOT your gmail password] - + + + + - - - - - + + + + - - - - - - - - - - - - - - - + + + + - - - - - - - - - - <version>${lombok.version}</version> - - - - - - - - - - - - - - - - - - - - ${mvn.bin.md5} - ${mvn.bin.sha1} - - - - ${mvn.src.md5} - ${mvn.src.sha1} - - - - - - - - - - ${mvn.pom.md5} - ${mvn.pom.sha1} - - - org.projectlombok - lombok - ${lombok.version} - - - ${lombok.version} -${mvn.oldversions} - - ${now.millis} - - -]]> - - - ${mvn.manifest.md5} - ${mvn.manifest.sha1} - - - - Now copy maven.tar.bz2 to the website and unpack it in the mavenrepo directory, overwriting whatever's there. + + + +
diff --git a/buildScripts/compile.ant.xml b/buildScripts/compile.ant.xml new file mode 100644 index 00000000..82ee07f7 --- /dev/null +++ b/buildScripts/compile.ant.xml @@ -0,0 +1,131 @@ + + + This buildfile is part of projectlombok.org. It responsible for compiling the main +lombok code including the various agents. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lombok.javac.apt.Processor + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/buildScripts/deps.ant.xml b/buildScripts/deps.ant.xml new file mode 100644 index 00000000..648685dc --- /dev/null +++ b/buildScripts/deps.ant.xml @@ -0,0 +1,46 @@ + + + This buildfile is part of projectlombok.org. It responsible for finding, downloading, +and building dependencies. + + + + + + + + + + + + + + + + + + ** UPDATED: lib/eclipse.agent/lombok-patcher.jar + + diff --git a/buildScripts/maven.ant.xml b/buildScripts/maven.ant.xml new file mode 100644 index 00000000..783303f2 --- /dev/null +++ b/buildScripts/maven.ant.xml @@ -0,0 +1,111 @@ + + + This buildfile is part of projectlombok.org. It is responsible for creating and maintaining +the maven repository that contains lombok's deliverables for those using maven. + + + + + + + + + + + + + + + + + + + + + + + + + + <version>${lombok.version}</version> + + + + + + + + + + + + + + + + + + + + ${mvn.bin.md5} + ${mvn.bin.sha1} + + + + ${mvn.src.md5} + ${mvn.src.sha1} + + + + + + + + + + ${mvn.pom.md5} + ${mvn.pom.sha1} + + + org.projectlombok + lombok + ${lombok.version} + + + ${lombok.version} + ${mvn.oldversions} + + ${now.millis} + + +]]> + + + ${mvn.manifest.md5} + ${mvn.manifest.sha1} + + + + Now copy maven.tar.bz2 to the website and unpack it in the mavenrepo directory. Let it overwrite files. + + diff --git a/buildScripts/publish.ant.xml b/buildScripts/publish.ant.xml new file mode 100644 index 00000000..6c31b42b --- /dev/null +++ b/buildScripts/publish.ant.xml @@ -0,0 +1,75 @@ + + + This buildfile is part of projectlombok.org. It is responsible for turning the build results +into the actual deliverable form, and uploading it to the distribution websites. + + + + + + + + + + + + + + + + + + + + + + + + #username=[your google account name without @gmail.com] +#password=[your googlecode password, is NOT your gmail password] + + + + + + + + + + diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml new file mode 100644 index 00000000..d4b0605d --- /dev/null +++ b/buildScripts/website.ant.xml @@ -0,0 +1,224 @@ + + + +This buildfile is part of projectlombok.org. It is responsible for building the website and all website-related aspects, +such as converting the changelog into HTML, and creating javadoc. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Now upload dist/website.tar.bz2 to the webserver. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Welcome to the lombok javadoc. If you're just looking to learn more about using lombok + You probably want to look at the feature documentation. Otherwise, + check the lombok package. If you're trying to extend lombok or + write your own plugins, the other packages are what you're looking for. + ]]> + + + + +
Lombok - ]]>v${lombok.version}
+ Copyright © 2009 Reinier Zwitserloot and Roel Spilker, licensed under the MIT licence.]]> +
+ + + + + + + + + + + + +
+
diff --git a/deps/README b/deps/README index cda42040..3a260349 100644 --- a/deps/README +++ b/deps/README @@ -1,5 +1,4 @@ 'deps' are defined as those things which are required to compile or develop lombok, but which aren't required when -actually running lombok. The main lombok code is dependent on all libraries in the 'lombok' directory, whilst the agents -are dependent on both the contents of the 'agent' directory and the agent's specific directory (e.g. 'eclipse.agent'). +actually running lombok. For dependencies which need to be available at runtime, see the 'lib' directory. diff --git a/deps/eclipse.agent/spi-0.2.3-pre.jar b/deps/eclipse.agent/spi-0.2.3-pre.jar deleted file mode 100644 index ecd70464..00000000 Binary files a/deps/eclipse.agent/spi-0.2.3-pre.jar and /dev/null differ diff --git a/deps/lombok/tools.jar b/deps/lombok/tools.jar new file mode 100644 index 00000000..bc3e0bef Binary files /dev/null and b/deps/lombok/tools.jar differ diff --git a/deps/tools.jar b/deps/tools.jar deleted file mode 100644 index bc3e0bef..00000000 Binary files a/deps/tools.jar and /dev/null differ diff --git a/website/publish b/website/publish deleted file mode 100755 index 412c71f6..00000000 --- a/website/publish +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -if [ ! -e src/lombok/core/Version.java ]; then - echo Run this script from the lombok project home directory. - exit -fi - -if [ ! -e dist/website.tar.bz2 ]; then - echo There is no dist/website.tar.bz2 file! Run: - echo ant website - echo then restart this script - exit -fi - -mkdir -p build/temp || exit -cd build/temp || exit -git clone -l -n ../.. websitegit || exit -cd websitegit || exit -BRANCHOK="foo" -git branch gh-pages origin/gh-pages || BRANCHOK="bar" -if [ $BRANCHOK == "bar" ]; then -echo If you get error fatal: Not a valid object name: origin/gh-pages. -echo then run: git branch gh-pages origin/gh-pages -echo first before running this script - exit -fi -git checkout gh-pages || exit -rm -r * || exit -tar xfj ../../../dist/website.tar.bz2 || exit -git add . || exit -git commit -a -m website || exit -git push origin gh-pages || exit -cd .. || exit -rm -rf websitegit || exit - -echo Your gh-pages branch has been updated. Do not forget to run: -echo git push origin gh-pages -- cgit From e8c706a7b6c543be12fa4be84f64041c392bb162 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 7 Oct 2009 20:50:02 +0200 Subject: Fully moved to using the lombok.patcher project. Means our dependency on ASM is no longer needed (our dep on lombok-patcher takes care of it), and the old EclipseTransformer system has been removed. --- lib/eclipse.agent/asm-3.1.jar | Bin 43035 -> 0 bytes lib/eclipse.agent/lombok-patcher.jar | Bin 83840 -> 1488746 bytes .../agent/EclipseLinkedNodeFinderTransformer.java | 169 --------------------- .../lombok/eclipse/agent/EclipsePatcher.java | 71 +++++++-- .../lombok/eclipse/agent/EclipseTransformer.java | 8 - .../lombok/eclipse/agent/PatchFixes.java | 37 +++++ 6 files changed, 97 insertions(+), 188 deletions(-) delete mode 100644 lib/eclipse.agent/asm-3.1.jar delete mode 100644 src_eclipseagent/lombok/eclipse/agent/EclipseLinkedNodeFinderTransformer.java delete mode 100644 src_eclipseagent/lombok/eclipse/agent/EclipseTransformer.java diff --git a/lib/eclipse.agent/asm-3.1.jar b/lib/eclipse.agent/asm-3.1.jar deleted file mode 100644 index b3baf3fe..00000000 Binary files a/lib/eclipse.agent/asm-3.1.jar and /dev/null differ diff --git a/lib/eclipse.agent/lombok-patcher.jar b/lib/eclipse.agent/lombok-patcher.jar index d7f58c31..0e15ac17 100644 Binary files a/lib/eclipse.agent/lombok-patcher.jar and b/lib/eclipse.agent/lombok-patcher.jar differ diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipseLinkedNodeFinderTransformer.java b/src_eclipseagent/lombok/eclipse/agent/EclipseLinkedNodeFinderTransformer.java deleted file mode 100644 index 9a1ebbb2..00000000 --- a/src_eclipseagent/lombok/eclipse/agent/EclipseLinkedNodeFinderTransformer.java +++ /dev/null @@ -1,169 +0,0 @@ -package lombok.eclipse.agent; - -import org.mangosdk.spi.ProviderFor; -import org.objectweb.asm.ClassAdapter; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; -import static org.objectweb.asm.Opcodes.*; - -@ProviderFor(EclipseTransformer.class) -public class EclipseLinkedNodeFinderTransformer implements EclipseTransformer { - private static final String LINKED_NODE_FINDER = "org/eclipse/jdt/core/internal/corext/dom/LinkedNodeFinder"; - - @Override public String getTargetClassName() { - return LINKED_NODE_FINDER; - } - - @Override public byte[] transform(byte[] in) { - ClassReader reader = new ClassReader(in); - ClassWriter writer = new ClassWriter(reader, 0); - - ClassAdapter adapter = new LinkedNodeFinderPatcherAdapter(writer); - reader.accept(adapter, 0); - return writer.toByteArray(); - } - - private static class LinkedNodeFinderPatcherAdapter extends ClassAdapter { - private int originalAccess; - private String originalDesc; - private String originalSignature; - private String[] originalExceptions; - - LinkedNodeFinderPatcherAdapter(ClassVisitor cv) { - super(cv); - } - - @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { - if ( !name.equals("findByNode") ) return super.visitMethod(access, name, desc, signature, exceptions); - - originalAccess = access; - originalDesc = desc; - originalSignature = signature; - originalExceptions = exceptions; - - return super.visitMethod(0, "findByNode0", desc, signature, exceptions); - } - - private static final String SIMPLENAME = "org/eclipse/jdt/core/dom/SimpleName"; - private static final String SIMPLENAME_ARRAY = "[L" + SIMPLENAME + ";"; - private static final String ASTNODE = "Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;"; - - /* - * code generated by running ASMifier on: - * - public SimpleName[] findByNode(ASTNode a, SimpleName b) { - SimpleName[] ps = this.findByNode0(a, b); - int count = 0; - for (int i = 0; i < ps.length; i++) { - if ( ps[i] == null || ps[i].$generatedBy == null ) count++; - } - if (count == ps.length) return ps; - SimpleName[] newPs = new SimpleName[count]; - count = 0; - for (int i = 0; i < ps.length; i++) { - if ( ps[i] == null || ps[i].p == null ) newPs[count++] = ps[i]; - } - return newPs; - } - */ - @Override public void visitEnd() { - MethodVisitor mv = super.visitMethod(originalAccess, "findByNode", originalDesc, originalSignature, originalExceptions); - mv.visitCode(); - mv.visitCode(); - mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 1); - mv.visitVarInsn(ALOAD, 2); - mv.visitMethodInsn(INVOKESPECIAL, LINKED_NODE_FINDER, "findByNode0", originalDesc); - mv.visitVarInsn(ASTORE, 3); - mv.visitInsn(ICONST_0); - mv.visitVarInsn(ISTORE, 4); - mv.visitInsn(ICONST_0); - mv.visitVarInsn(ISTORE, 5); - Label l0 = new Label(); - mv.visitLabel(l0); - mv.visitFrame(F_APPEND,3, new Object[] {SIMPLENAME_ARRAY, INTEGER, INTEGER}, 0, null); - mv.visitVarInsn(ILOAD, 5); - mv.visitVarInsn(ALOAD, 3); - mv.visitInsn(ARRAYLENGTH); - Label l1 = new Label(); - mv.visitJumpInsn(IF_ICMPGE, l1); - mv.visitVarInsn(ALOAD, 3); - mv.visitVarInsn(ILOAD, 5); - mv.visitInsn(AALOAD); - Label l2 = new Label(); - mv.visitJumpInsn(IFNULL, l2); - mv.visitVarInsn(ALOAD, 3); - mv.visitVarInsn(ILOAD, 5); - mv.visitInsn(AALOAD); - mv.visitFieldInsn(GETFIELD, SIMPLENAME, "$generatedBy", ASTNODE); - Label l3 = new Label(); - mv.visitJumpInsn(IFNONNULL, l3); - mv.visitLabel(l2); - mv.visitFrame(F_SAME, 0, null, 0, null); - mv.visitIincInsn(4, 1); - mv.visitLabel(l3); - mv.visitFrame(F_SAME, 0, null, 0, null); - mv.visitIincInsn(5, 1); - mv.visitJumpInsn(GOTO, l0); - mv.visitLabel(l1); - mv.visitFrame(F_CHOP,1, null, 0, null); - mv.visitVarInsn(ILOAD, 4); - mv.visitVarInsn(ALOAD, 3); - mv.visitInsn(ARRAYLENGTH); - Label l4 = new Label(); - mv.visitJumpInsn(IF_ICMPNE, l4); - mv.visitVarInsn(ALOAD, 3); - mv.visitInsn(ARETURN); - mv.visitLabel(l4); - mv.visitFrame(F_SAME, 0, null, 0, null); - mv.visitVarInsn(ILOAD, 4); - mv.visitTypeInsn(ANEWARRAY, SIMPLENAME); - mv.visitVarInsn(ASTORE, 5); - mv.visitInsn(ICONST_0); - mv.visitVarInsn(ISTORE, 4); - mv.visitInsn(ICONST_0); - mv.visitVarInsn(ISTORE, 6); - Label l5 = new Label(); - mv.visitLabel(l5); - mv.visitFrame(F_APPEND,2, new Object[] {SIMPLENAME_ARRAY, INTEGER}, 0, null); - mv.visitVarInsn(ILOAD, 6); - mv.visitVarInsn(ALOAD, 3); - mv.visitInsn(ARRAYLENGTH); - Label l6 = new Label(); - mv.visitJumpInsn(IF_ICMPGE, l6); - mv.visitVarInsn(ALOAD, 3); - mv.visitVarInsn(ILOAD, 6); - mv.visitInsn(AALOAD); - Label l7 = new Label(); - mv.visitJumpInsn(IFNULL, l7); - mv.visitVarInsn(ALOAD, 3); - mv.visitVarInsn(ILOAD, 6); - mv.visitInsn(AALOAD); - mv.visitFieldInsn(GETFIELD, SIMPLENAME, "$generatedBy", ASTNODE); - Label l8 = new Label(); - mv.visitJumpInsn(IFNONNULL, l8); - mv.visitLabel(l7); - mv.visitFrame(F_SAME, 0, null, 0, null); - mv.visitVarInsn(ALOAD, 5); - mv.visitVarInsn(ILOAD, 4); - mv.visitIincInsn(4, 1); - mv.visitVarInsn(ALOAD, 3); - mv.visitVarInsn(ILOAD, 6); - mv.visitInsn(AALOAD); - mv.visitInsn(AASTORE); - mv.visitLabel(l8); - mv.visitFrame(F_SAME, 0, null, 0, null); - mv.visitIincInsn(6, 1); - mv.visitJumpInsn(GOTO, l5); - mv.visitLabel(l6); - mv.visitFrame(F_CHOP,1, null, 0, null); - mv.visitVarInsn(ALOAD, 5); - mv.visitInsn(ARETURN); - mv.visitMaxs(4, 7); - super.visitEnd(); - } - } -} diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java index c8fdab28..1f36b02a 100644 --- a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java @@ -22,11 +22,15 @@ package lombok.eclipse.agent; import java.lang.instrument.Instrumentation; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import lombok.patcher.Hook; import lombok.patcher.MethodTarget; import lombok.patcher.ScriptManager; import lombok.patcher.StackRequest; +import lombok.patcher.TargetMatcher; import lombok.patcher.equinox.EquinoxClassLoader; import lombok.patcher.scripts.ScriptBuilder; @@ -59,17 +63,6 @@ public class EclipsePatcher { .wrapMethod(new Hook("lombok/eclipse/agent/PatchFixes", "fixRetrieveStartingCatchPosition", "(I)I")) .transplant().request(StackRequest.PARAM1).build()); - sm.addScript(ScriptBuilder.addField() - .targetClass("org.eclipse.jdt.internal.compiler.ast.ASTNode") - .fieldName("$generatedBy") - .fieldType("Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;") - .setPublic().setTransient().build()); - - sm.addScript(ScriptBuilder.addField() - .targetClass("org.eclipse.jdt.core.dom.ASTNode") - .fieldName("$isGenerated").fieldType("Z") - .setPublic().setTransient().build()); - sm.addScript(ScriptBuilder.addField() .targetClass("org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration") .fieldName("$lombokAST").fieldType("Ljava/lang/Object;") @@ -114,6 +107,62 @@ public class EclipsePatcher { .decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z")) .transplant().request(StackRequest.PARAM1).build()); + sm.addScript(ScriptBuilder.addField() + .targetClass("org.eclipse.jdt.internal.compiler.ast.ASTNode") + .fieldName("$generatedBy") + .fieldType("Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;") + .setPublic().setTransient().build()); + + sm.addScript(ScriptBuilder.addField() + .targetClass("org.eclipse.jdt.core.dom.ASTNode") + .fieldName("$isGenerated").fieldType("Z") + .setPublic().setTransient().build()); + + sm.addScript(ScriptBuilder.wrapReturnValue() + .target(new TargetMatcher() { + @Override public boolean matches(String classSpec, String methodName, String descriptor) { + if (!"convert".equals(methodName)) return false; + + List fullDesc = MethodTarget.decomposeFullDesc(descriptor); + if ("V".equals(fullDesc.get(0))) return false; + return fullDesc.size() == 2; + } + + @Override public Collection getAffectedClasses() { + return Collections.singleton("org.eclipse.jdt.core.dom.ASTConverter"); + } + }).request(StackRequest.PARAM1, StackRequest.RETURN_VALUE) + .wrapMethod(new Hook("lombok/eclipse/agent/PatchFixes", "setIsGeneratedFlag", + "(Lorg/eclipse/jdt/core/dom/ASTNode;Lorg/eclipse/jdt/internal/compiler/ast/ASTNode;)V")) + .transplant().build()); + + sm.addScript(ScriptBuilder.wrapMethodCall() + .target(new TargetMatcher() { + @Override public boolean matches(String classSpec, String methodName, String descriptor) { + if (!methodName.startsWith("convert")) return false; + + List fullDesc = MethodTarget.decomposeFullDesc(descriptor); + if (fullDesc.size() < 2) return false; + if (!fullDesc.get(1).startsWith("Lorg/eclipse/jdt/internal/compiler/ast/")) return false; + + return true; + } + + @Override public Collection getAffectedClasses() { + return Collections.singleton("org.eclipse.jdt.core.dom.ASTConverter"); + } + }).methodToWrap(new Hook("org/eclipse/jdt/core/dom/SimpleName", "", "(Lorg/eclipse/jdt/core/dom/AST;)V")) + .requestExtra(StackRequest.PARAM1) + .replacementMethod(new Hook("lombok/eclipse/agent/PatchFixes", "setIsGeneratedFlagForSimpleName", + "(Lorg/eclipse/jdt/core/dom/SimpleName;Ljava/lang/Object;)V")) + .transplant().build()); + + sm.addScript(ScriptBuilder.wrapReturnValue() + .target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode")) + .wrapMethod(new Hook("lombok/eclipse/agent/PatchFixes", "removeGeneratedSimpleNames", + "([Lorg/eclipse/jdt/core/dom/SimpleName;)[Lorg/eclipse/jdt/core/dom/SimpleName;")) + .request(StackRequest.RETURN_VALUE).build()); + if (reloadExistingClasses) sm.reloadClasses(instrumentation); } } diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipseTransformer.java b/src_eclipseagent/lombok/eclipse/agent/EclipseTransformer.java deleted file mode 100644 index 31f8413f..00000000 --- a/src_eclipseagent/lombok/eclipse/agent/EclipseTransformer.java +++ /dev/null @@ -1,8 +0,0 @@ -package lombok.eclipse.agent; - -public interface EclipseTransformer { - /** slash and not dot separated */ - String getTargetClassName(); - - byte[] transform(byte[] in); -} diff --git a/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java b/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java index e36823b2..3ec5af90 100644 --- a/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java +++ b/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java @@ -1,5 +1,9 @@ package lombok.eclipse.agent; +import java.lang.reflect.Field; + +import org.eclipse.jdt.core.dom.SimpleName; + public class PatchFixes { public static int fixRetrieveStartingCatchPosition(int in) { return in; @@ -11,4 +15,37 @@ public class PatchFixes { int bits = (Integer)(node.getClass().getField("bits").get(node)); return (bits & BIT24) != 0; } + + public static void setIsGeneratedFlag(org.eclipse.jdt.core.dom.ASTNode domNode, + org.eclipse.jdt.internal.compiler.ast.ASTNode internalNode) throws Exception { + boolean isGenerated = internalNode.getClass().getField("$generatedBy").get(internalNode) != null; + if (isGenerated) domNode.getClass().getField("$isGenerated").set(domNode, true); + } + + public static void setIsGeneratedFlagForSimpleName(SimpleName name, Object internalNode) throws Exception { + System.out.println("Setting isGenerated on SimpleName"); + if (internalNode instanceof org.eclipse.jdt.internal.compiler.ast.ASTNode) { + if (internalNode.getClass().getField("$generatedBy").get(internalNode) != null) { + name.getClass().getField("$isGenerated").set(name, true); + } + } + } + + public static SimpleName[] removeGeneratedSimpleNames(SimpleName[] in) throws Exception { + System.out.print("Removing is generated..."); + Field f = SimpleName.class.getField("$isGenerated"); + + int count = 0; + for (int i = 0; i < in.length; i++) { + if ( in[i] == null || !((Boolean)f.get(in[i])).booleanValue() ) count++; + } + System.out.println("" + (in.length - count)); + if (count == in.length) return in; + SimpleName[] newSimpleNames = new SimpleName[count]; + count = 0; + for (int i = 0; i < in.length; i++) { + if ( in[i] == null || !((Boolean)f.get(in[i])).booleanValue() ) newSimpleNames[count++] = in[i]; + } + return newSimpleNames; + } } -- cgit From a65b7320f28a1f53436eed5dd3c9650a9b1dea2a Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 7 Oct 2009 23:52:56 +0200 Subject: Removed debug prints --- src_eclipseagent/lombok/eclipse/agent/PatchFixes.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java b/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java index 3ec5af90..1914bba7 100644 --- a/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java +++ b/src_eclipseagent/lombok/eclipse/agent/PatchFixes.java @@ -23,7 +23,6 @@ public class PatchFixes { } public static void setIsGeneratedFlagForSimpleName(SimpleName name, Object internalNode) throws Exception { - System.out.println("Setting isGenerated on SimpleName"); if (internalNode instanceof org.eclipse.jdt.internal.compiler.ast.ASTNode) { if (internalNode.getClass().getField("$generatedBy").get(internalNode) != null) { name.getClass().getField("$isGenerated").set(name, true); @@ -32,14 +31,12 @@ public class PatchFixes { } public static SimpleName[] removeGeneratedSimpleNames(SimpleName[] in) throws Exception { - System.out.print("Removing is generated..."); Field f = SimpleName.class.getField("$isGenerated"); int count = 0; for (int i = 0; i < in.length; i++) { if ( in[i] == null || !((Boolean)f.get(in[i])).booleanValue() ) count++; } - System.out.println("" + (in.length - count)); if (count == in.length) return in; SimpleName[] newSimpleNames = new SimpleName[count]; count = 0; -- cgit From 49d1be131218b1afac22adab2b88cce057fa5d3d Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 7 Oct 2009 23:53:16 +0200 Subject: Fixed one of our patch scripts that presumed any convert() method with 1 parameter was always receiving an ASTNode child. One of the methods actually gets an array of those, which isn't of course a subclass of ASTNode itself. --- src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java index 1f36b02a..c39a7d4e 100644 --- a/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src_eclipseagent/lombok/eclipse/agent/EclipsePatcher.java @@ -125,7 +125,9 @@ public class EclipsePatcher { List fullDesc = MethodTarget.decomposeFullDesc(descriptor); if ("V".equals(fullDesc.get(0))) return false; - return fullDesc.size() == 2; + if (fullDesc.size() < 2) return false; + if (!fullDesc.get(1).startsWith("Lorg/eclipse/jdt/internal/compiler/ast/")) return false; + return true; } @Override public Collection getAffectedClasses() { -- cgit From 23da5b1e80bd03ee3fc02b7d7ee03130f158e7c4 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 7 Oct 2009 23:53:50 +0200 Subject: New version of lombok-patcher. --- lib/eclipse.agent/lombok-patcher.jar | Bin 1488746 -> 1489463 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/eclipse.agent/lombok-patcher.jar b/lib/eclipse.agent/lombok-patcher.jar index 0e15ac17..7818fc1d 100644 Binary files a/lib/eclipse.agent/lombok-patcher.jar and b/lib/eclipse.agent/lombok-patcher.jar differ -- cgit