diff options
-rw-r--r-- | src/core/lombok/eclipse/apt/Processor.java | 79 | ||||
-rw-r--r-- | src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java | 14 |
2 files changed, 86 insertions, 7 deletions
diff --git a/src/core/lombok/eclipse/apt/Processor.java b/src/core/lombok/eclipse/apt/Processor.java new file mode 100644 index 00000000..1457589e --- /dev/null +++ b/src/core/lombok/eclipse/apt/Processor.java @@ -0,0 +1,79 @@ +package lombok.eclipse.apt; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; + +import lombok.eclipse.TransformEclipseAST; +import lombok.patcher.inject.LiveInjector; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.util.HashtableOfType; + +@SupportedAnnotationTypes("*") +@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class Processor extends AbstractProcessor { + private BaseProcessingEnvImpl processingEnv; + + @Override public synchronized void init(ProcessingEnvironment procEnv) { + super.init(procEnv); + + this.processingEnv = (BaseProcessingEnvImpl)procEnv; + + new LiveInjector().injectSelf(); + } + + /** {@inheritDoc} */ + @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + try { + Field unitsField = roundEnv.getClass().getDeclaredField("_units"); + unitsField.setAccessible(true); + CompilationUnitDeclaration[] roots = (CompilationUnitDeclaration[]) unitsField.get(roundEnv); + + if (roots == null) System.out.println("roots is null: " + roundEnv.processingOver()); + else System.out.println("rootscount: " + roots.length); + + if (roots != null) for (CompilationUnitDeclaration cud : roots) { + TransformEclipseAST.transform(null, cud); + } + + Field f = processingEnv.getLookupEnvironment().getClass().getDeclaredField("stepCompleted"); + f.setAccessible(true); + f.set(processingEnv.getLookupEnvironment(), 1); + if (roots != null) for (CompilationUnitDeclaration cud : roots) { + Field f2 = cud.scope.fPackage.getClass().getDeclaredField("knownTypes"); + f2.setAccessible(true); + HashtableOfType turd = (HashtableOfType) f2.get(cud.scope.fPackage); + int idx = 0; + for (char[] x : turd.keyTable) { + if (CharOperation.equals(x, cud.types[0].name)) turd.keyTable[idx] = null; + idx++; + } + Method m = HashtableOfType.class.getDeclaredMethod("rehash"); + m.setAccessible(true); + m.invoke(turd); + cud.scope = null; + cud.types[0].binding = null; + cud.types[0].scope = null; + processingEnv.getLookupEnvironment().buildTypeBindings(cud, null); + } + + processingEnv.getLookupEnvironment().completeTypeBindings(); + return false; + } catch (Throwable t) { + System.out.println("Scream and shout!"); + t.printStackTrace(); + return false; + } + } +} diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index 741328f1..b8f9f9a3 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -54,11 +54,11 @@ public class EclipsePatcher extends Agent { EquinoxClassLoader.addPrefix("lombok."); EquinoxClassLoader.registerScripts(sm); - patchLombokizeAST(sm); +// patchLombokizeAST(sm); patchAvoidReparsingGeneratedCode(sm); - patchCatchReparse(sm); - patchSetGeneratedFlag(sm); - patchHideGeneratedNodes(sm); +// patchCatchReparse(sm); +// patchSetGeneratedFlag(sm); +// patchHideGeneratedNodes(sm); if (reloadExistingClasses) sm.reloadClasses(instrumentation); } @@ -167,14 +167,14 @@ public class EclipsePatcher extends Agent { "org.eclipse.jdt.internal.compiler.ast.MethodDeclaration", "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration")) .decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z")) - .transplant().request(StackRequest.PARAM1).build()); + .request(StackRequest.PARAM1).build()); 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")) .decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z")) - .transplant().request(StackRequest.PARAM1).build()); + .request(StackRequest.PARAM1).build()); sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget(PARSER_SIG1, "parse", "void", @@ -182,7 +182,7 @@ public class EclipsePatcher extends Agent { "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration")) .decisionMethod(new Hook("lombok/eclipse/agent/PatchFixes", "checkBit24", "(Ljava/lang/Object;)Z")) - .transplant().request(StackRequest.PARAM1).build()); + .request(StackRequest.PARAM1).build()); } private static void patchLombokizeAST(ScriptManager sm) { |