aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-12-23 03:36:17 +0100
committerReinier Zwitserloot <reinier@tipit.to>2009-12-23 03:36:17 +0100
commit0917f20f74728ab311160252e06b5368d6ab4a55 (patch)
tree0db940060594f44d24d516f7130236d6978cca86 /src/core/lombok
parente56395a49f37e627d16a5afc05f60bf00ad4e047 (diff)
downloadlombok-0917f20f74728ab311160252e06b5368d6ab4a55.tar.gz
lombok-0917f20f74728ab311160252e06b5368d6ab4a55.tar.bz2
lombok-0917f20f74728ab311160252e06b5368d6ab4a55.zip
work in progress on ecj support.
Diffstat (limited to 'src/core/lombok')
-rw-r--r--src/core/lombok/eclipse/apt/Processor.java79
1 files changed, 79 insertions, 0 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;
+ }
+ }
+}