From 96b7c8ed471745366378d5b7cec8890d16532dee Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Sun, 29 Nov 2009 16:55:23 +0100 Subject: work in progress. --- deps/agent/.gitkeep | 1 - .../org.eclipse.core.runtime_3.5.0.v20090525.jar | Bin 0 -> 69761 bytes ...rg.eclipse.equinox.common_3.5.0.v20090520-1800.jar | Bin 0 -> 99430 bytes .../eclipse/org.eclipse.jdt.core_3.5.0.v_963.jar | Bin 0 -> 4471784 bytes .../org.eclipse.jdt.ui_3.5.1.r351_v20090821-0800.jar | Bin 0 -> 9803138 bytes .../eclipse/org.eclipse.osgi_3.5.0.v20090520.jar | Bin 0 -> 1122602 bytes .../org-netbeans-modules-java-source_6.8beta.jar | Bin 0 -> 2155618 bytes deps/netbeans.agent/.gitkeep | 1 - 8 files changed, 2 deletions(-) delete mode 100644 deps/agent/.gitkeep create mode 100644 deps/lombok/eclipse/org.eclipse.core.runtime_3.5.0.v20090525.jar create mode 100644 deps/lombok/eclipse/org.eclipse.equinox.common_3.5.0.v20090520-1800.jar create mode 100644 deps/lombok/eclipse/org.eclipse.jdt.core_3.5.0.v_963.jar create mode 100644 deps/lombok/eclipse/org.eclipse.jdt.ui_3.5.1.r351_v20090821-0800.jar create mode 100644 deps/lombok/eclipse/org.eclipse.osgi_3.5.0.v20090520.jar create mode 100644 deps/lombok/netbeans/org-netbeans-modules-java-source_6.8beta.jar delete mode 100644 deps/netbeans.agent/.gitkeep (limited to 'deps') diff --git a/deps/agent/.gitkeep b/deps/agent/.gitkeep deleted file mode 100644 index 2ded1cf3..00000000 --- a/deps/agent/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Empty dir placeholder diff --git a/deps/lombok/eclipse/org.eclipse.core.runtime_3.5.0.v20090525.jar b/deps/lombok/eclipse/org.eclipse.core.runtime_3.5.0.v20090525.jar new file mode 100644 index 00000000..a1cf295a Binary files /dev/null and b/deps/lombok/eclipse/org.eclipse.core.runtime_3.5.0.v20090525.jar differ diff --git a/deps/lombok/eclipse/org.eclipse.equinox.common_3.5.0.v20090520-1800.jar b/deps/lombok/eclipse/org.eclipse.equinox.common_3.5.0.v20090520-1800.jar new file mode 100644 index 00000000..8687a112 Binary files /dev/null and b/deps/lombok/eclipse/org.eclipse.equinox.common_3.5.0.v20090520-1800.jar differ diff --git a/deps/lombok/eclipse/org.eclipse.jdt.core_3.5.0.v_963.jar b/deps/lombok/eclipse/org.eclipse.jdt.core_3.5.0.v_963.jar new file mode 100644 index 00000000..0db68569 Binary files /dev/null and b/deps/lombok/eclipse/org.eclipse.jdt.core_3.5.0.v_963.jar differ diff --git a/deps/lombok/eclipse/org.eclipse.jdt.ui_3.5.1.r351_v20090821-0800.jar b/deps/lombok/eclipse/org.eclipse.jdt.ui_3.5.1.r351_v20090821-0800.jar new file mode 100644 index 00000000..fe3d9bee Binary files /dev/null and b/deps/lombok/eclipse/org.eclipse.jdt.ui_3.5.1.r351_v20090821-0800.jar differ diff --git a/deps/lombok/eclipse/org.eclipse.osgi_3.5.0.v20090520.jar b/deps/lombok/eclipse/org.eclipse.osgi_3.5.0.v20090520.jar new file mode 100644 index 00000000..b80140e0 Binary files /dev/null and b/deps/lombok/eclipse/org.eclipse.osgi_3.5.0.v20090520.jar differ diff --git a/deps/lombok/netbeans/org-netbeans-modules-java-source_6.8beta.jar b/deps/lombok/netbeans/org-netbeans-modules-java-source_6.8beta.jar new file mode 100644 index 00000000..04b51656 Binary files /dev/null and b/deps/lombok/netbeans/org-netbeans-modules-java-source_6.8beta.jar differ diff --git a/deps/netbeans.agent/.gitkeep b/deps/netbeans.agent/.gitkeep deleted file mode 100644 index 2ded1cf3..00000000 --- a/deps/netbeans.agent/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Empty dir placeholder -- cgit From dfa401018d0eff370b34f1e9d7bb1d5fd498a631 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 30 Nov 2009 00:49:42 +0100 Subject: All basic elements of netbeans support are here except the actual agent part. --- .classpath | 1 + deps/lombok/netbeans/org-openide-util_6.8beta.jar | Bin 0 -> 645380 bytes src/core/lombok/javac/JavacAST.java | 1 + .../lombok/netbeans/agent/NetbeansEntryPoint.java | 53 ++++++++++++++++++++ .../lombok/netbeans/agent/NetbeansPatcher.java | 11 ++++- .../lombok/netbeans/agent/PatchFixes.java | 55 +++++++++++++++++++-- .../netbeans/agent/TaskListenerProviderImpl.java | 12 +++++ 7 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 deps/lombok/netbeans/org-openide-util_6.8beta.jar create mode 100644 src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java create mode 100644 src/netbeansAgent/lombok/netbeans/agent/TaskListenerProviderImpl.java (limited to 'deps') diff --git a/.classpath b/.classpath index dcd7bd2f..5873a158 100644 --- a/.classpath +++ b/.classpath @@ -15,6 +15,7 @@ + diff --git a/deps/lombok/netbeans/org-openide-util_6.8beta.jar b/deps/lombok/netbeans/org-openide-util_6.8beta.jar new file mode 100644 index 00000000..b3dbeac6 Binary files /dev/null and b/deps/lombok/netbeans/org-openide-util_6.8beta.jar differ diff --git a/src/core/lombok/javac/JavacAST.java b/src/core/lombok/javac/JavacAST.java index 33c167f9..9cfe7f34 100644 --- a/src/core/lombok/javac/JavacAST.java +++ b/src/core/lombok/javac/JavacAST.java @@ -125,6 +125,7 @@ public class JavacAST extends AST { /** @return A TreeMaker instance that you can use to create new AST nodes. */ public TreeMaker getTreeMaker() { + treeMaker.at(-1); return treeMaker; } diff --git a/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java b/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java new file mode 100644 index 00000000..d825ae62 --- /dev/null +++ b/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java @@ -0,0 +1,53 @@ +package lombok.netbeans.agent; + +import java.util.Collections; + +import javax.annotation.processing.Messager; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.tools.Diagnostic.Kind; + +import lombok.javac.JavacTransformer; + +import com.sun.source.util.TaskEvent; +import com.sun.source.util.TaskListener; +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; +import com.sun.tools.javac.util.Context; + +public class NetbeansEntryPoint implements TaskListener { + public class DummyMessager implements Messager { + @Override public void printMessage(Kind kind, CharSequence msg) { + System.err.printf("%s: %s\n", kind, msg); + } + + @Override public void printMessage(Kind kind, CharSequence msg, Element e) { + printMessage(kind, msg); + } + + @Override public void printMessage(Kind kind, CharSequence msg, Element e, AnnotationMirror a) { + printMessage(kind, msg); + } + + @Override public void printMessage(Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) { + printMessage(kind, msg); + } + } + + private final Context context; + + public NetbeansEntryPoint(Context context) { + this.context = context; + } + + @Override public void started(TaskEvent event) { + //we run at the end, so all the action is in #finished. + } + + @Override public void finished(TaskEvent event) { + if (TaskEvent.Kind.PARSE == event.getKind()) { + JavacTransformer transformer = new JavacTransformer(new DummyMessager()); //TODO hook into netbeans error reporting! + transformer.transform(context, Collections.singleton((JCCompilationUnit)event.getCompilationUnit())); + } + } +} diff --git a/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java b/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java index 4210aa87..108b4c45 100644 --- a/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java +++ b/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java @@ -63,14 +63,14 @@ public class NetbeansPatcher { .build()); sm.addScript(ScriptBuilder.wrapReturnValue() - .request() + .request(StackRequest.RETURN_VALUE, StackRequest.PARAM1) .transplant() .target(new MethodTarget("org.netbeans.modules.java.source.parsing.JavacParser", "createJavacTask", "com.sun.tools.javac.api.JavacTaskImpl", "ClasspathInfo", "DiagnosticListener", "java.lang.String", "boolean", "ClassNamesForFileOraculum", "CancelService")) .wrapMethod(new Hook("lombok/netbeans/agent/PatchFixes", "addTaskListenerWhenCallingJavac", - "()V")) + "(Lcom/sun/tools/javac/api/JavacTaskImpl;Lorg/netbeans/api/java/source/ClasspathInfo;)V")) .build()); } @@ -94,5 +94,12 @@ public class NetbeansPatcher { .replacementMethod(new Hook("lombok/netbeans/agent/PatchFixes", "returnMinus1ForGeneratedNode", "(Lcom/sun/source/util/SourcePositions;Lcom/sun/source/tree/CompilationUnitTree;Lcom/sun/source/tree/Tree;)J")) .build()); + + sm.addScript(ScriptBuilder.wrapMethodCall() + .target(new MethodTarget("org.netbeans.modules.java.source.save.CasualDiff", "filterHidden")) + .methodToWrap(new Hook("java/lang/Iterable", "iterator", "()L/java/util/Iterator;")) + .wrapMethod(new Hook("lombok/netbeans/agent/PatchFixes", "filterGenerated", + "(Ljava/util/Iterator;)L/java/util/Iterator;")) + .transplant().build()); } } diff --git a/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java b/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java index c12e6dad..aea01b1a 100644 --- a/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java +++ b/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java @@ -2,10 +2,13 @@ package lombok.netbeans.agent; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.NoSuchElementException; import javax.lang.model.element.Element; import org.netbeans.api.java.source.ClasspathInfo; +import org.openide.util.Lookup; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.Tree; @@ -13,6 +16,7 @@ import com.sun.source.util.SourcePositions; import com.sun.source.util.TaskListener; import com.sun.source.util.Trees; import com.sun.tools.javac.api.JavacTaskImpl; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.Context; public class PatchFixes { @@ -65,13 +69,54 @@ public class PatchFixes { //Contributed by Jan Lahoda (jlahoda@netbeans.org) //Turned into a patch script by rzwitserloot. //see http://code.google.com/p/projectlombok/issues/detail?id=20#c3 - public static void addTaskListenerWhenCallingJavac(Context context, ClasspathInfo cpInfo) { - TaskListenerProvider p = /* Lookup.getDefault().lookup(TaskListenerProvider.class) */; + public static void addTaskListenerWhenCallingJavac(JavacTaskImpl task, ClasspathInfo cpInfo) { + TaskListenerProvider p = Lookup.getDefault().lookup(TaskListenerProvider.class); if (p != null) { - TaskListener l = p.create(context, cpInfo); + TaskListener l = p.create(task.getContext(), cpInfo); task.setTaskListener(l); } - - return; + } + + //Contributed by Jan Lahoda (jlahoda@netbeans.org) + //Turned into a patch script by rzwitserloot. + //see http://code.google.com/p/projectlombok/issues/detail?id=20#c3 + public static Iterator filterGenerated(final Iterator it) { + return new Iterator() { + private JCTree next; + private boolean hasNext; + + { + calc(); + } + + private void calc() { + while (it.hasNext()) { + JCTree n = it.next(); + if (n.pos != -1) { + hasNext = true; + next = n; + return; + } + } + + hasNext = false; + next = null; + } + + @Override public boolean hasNext() { + return hasNext; + } + + @Override public JCTree next() { + if (!hasNext) throw new NoSuchElementException(); + JCTree n = next; + calc(); + return n; + } + + @Override public void remove() { + throw new UnsupportedOperationException(); + } + }; } } diff --git a/src/netbeansAgent/lombok/netbeans/agent/TaskListenerProviderImpl.java b/src/netbeansAgent/lombok/netbeans/agent/TaskListenerProviderImpl.java new file mode 100644 index 00000000..3ebf5475 --- /dev/null +++ b/src/netbeansAgent/lombok/netbeans/agent/TaskListenerProviderImpl.java @@ -0,0 +1,12 @@ +package lombok.netbeans.agent; + +import org.netbeans.api.java.source.ClasspathInfo; + +import com.sun.source.util.TaskListener; +import com.sun.tools.javac.util.Context; + +public class TaskListenerProviderImpl implements TaskListenerProvider { + public TaskListener create(final Context context, ClasspathInfo cpInfo) { + return new NetbeansEntryPoint(context); + } +} -- cgit From 8165f4628f75618f1cd105ad8901f273ada261e4 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 2 Dec 2009 00:05:21 +0100 Subject: netbeans agent now works! --- .classpath | 3 +- deps/lombok/netbeans/boot_6.8beta.jar | Bin 0 -> 263129 bytes .../lombok/netbeans/agent/NetbeansEntryPoint.java | 3 +- .../lombok/netbeans/agent/NetbeansPatcher.java | 30 +++++++++++ .../lombok/netbeans/agent/PatchFixes.java | 56 ++++++++++++++++++++- 5 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 deps/lombok/netbeans/boot_6.8beta.jar (limited to 'deps') diff --git a/.classpath b/.classpath index 5873a158..02129162 100644 --- a/.classpath +++ b/.classpath @@ -14,8 +14,9 @@ - + + diff --git a/deps/lombok/netbeans/boot_6.8beta.jar b/deps/lombok/netbeans/boot_6.8beta.jar new file mode 100644 index 00000000..f82709d2 Binary files /dev/null and b/deps/lombok/netbeans/boot_6.8beta.jar differ diff --git a/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java b/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java index 0a13a474..963b70b5 100644 --- a/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java +++ b/src/netbeansAgent/lombok/netbeans/agent/NetbeansEntryPoint.java @@ -68,7 +68,8 @@ public class NetbeansEntryPoint implements TaskListener { @Override public void finished(TaskEvent event) { if (TaskEvent.Kind.PARSE == event.getKind()) { JavacTransformer transformer = new JavacTransformer(new DummyMessager()); //TODO hook into netbeans error reporting! - transformer.transform(context, Collections.singleton((JCCompilationUnit)event.getCompilationUnit())); + JCCompilationUnit compilationUnit = (JCCompilationUnit) event.getCompilationUnit(); + transformer.transform(context, Collections.singleton(compilationUnit)); } } } diff --git a/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java b/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java index bffedfc2..39df269b 100644 --- a/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java +++ b/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java @@ -47,12 +47,42 @@ public class NetbeansPatcher extends Agent { ScriptManager sm = new ScriptManager(); sm.registerTransformer(instrumentation); + patchNetbeansClassLoader(sm); patchNetbeansJavac(sm); patchNetbeansMissingPositionAwareness(sm); if (reloadExistingClasses) sm.reloadClasses(instrumentation); } + private static void patchNetbeansClassLoader(ScriptManager sm) { + sm.addScript(ScriptBuilder.exitEarly() + .transplant().request(StackRequest.PARAM1, StackRequest.PARAM2) + .target(new MethodTarget("org.netbeans.StandardModule$OneModuleClassLoader", "")) + .decisionMethod(new Hook("lombok/netbeans/agent/PatchFixes", "addSelfToClassLoader", "(Lorg/netbeans/Module;Ljava/util/List;)Z")) + .build()); + sm.addScript(ScriptBuilder.exitEarly() + .transplant() + .request(StackRequest.THIS, StackRequest.PARAM1) + .target(new MethodTarget("org.netbeans.ProxyClassLoader", "getResource")) + .decisionMethod(new Hook("lombok/netbeans/agent/PatchFixes", "getResource_decision", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Z")) + .valueMethod(new Hook("lombok/netbeans/agent/PatchFixes", "getResource_value", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/net/URL;")) + .build()); + sm.addScript(ScriptBuilder.exitEarly() + .transplant() + .request(StackRequest.THIS, StackRequest.PARAM1) + .target(new MethodTarget("org.netbeans.ProxyClassLoader", "getResources")) + .decisionMethod(new Hook("lombok/netbeans/agent/PatchFixes", "getResources_decision", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Z")) + .valueMethod(new Hook("lombok/netbeans/agent/PatchFixes", "getResources_value", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/util/Enumeration;")) + .build()); + sm.addScript(ScriptBuilder.exitEarly() + .transplant() + .target(new MethodTarget("org.netbeans.ProxyClassLoader", "loadClass")) + .request(StackRequest.THIS, StackRequest.PARAM1) + .decisionMethod(new Hook("lombok/netbeans/agent/PatchFixes", "loadClass_decision", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Z")) + .valueMethod(new Hook("lombok/netbeans/agent/PatchFixes", "loadClass_value", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;")) + .build()); + } + private static void patchNetbeansJavac(ScriptManager sm) { sm.addScript(ScriptBuilder.wrapReturnValue() .request(StackRequest.THIS, StackRequest.PARAM1) diff --git a/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java b/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java index 3a58d381..d9b858cd 100644 --- a/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java +++ b/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java @@ -21,13 +21,22 @@ */ package lombok.netbeans.agent; +import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.net.URL; +import java.util.Enumeration; import java.util.Iterator; +import java.util.List; import java.util.NoSuchElementException; import javax.lang.model.element.Element; +import lombok.Lombok; +import lombok.patcher.inject.LiveInjector; + +import org.netbeans.Module; +import org.netbeans.ProxyClassLoader; import org.netbeans.api.java.source.ClasspathInfo; import com.sun.source.tree.CompilationUnitTree; @@ -43,8 +52,50 @@ import com.sun.tools.javac.util.Context; // This footwork was converted into a patch script form by me (rzwitserloot). See: // http://code.google.com/p/projectlombok/issues/detail?id=20#c3 public class PatchFixes { + public static boolean loadClass_decision(@SuppressWarnings("unused") ClassLoader loader, String name) throws Exception { + return name.startsWith("lombok."); + } + + public static Class loadClass_value(ClassLoader loader, String name) throws Exception { + int last = name.lastIndexOf('.'); + String pkg = (last >= 0) ? name.substring(0, last) : ""; + Method m = ProxyClassLoader.class.getDeclaredMethod("selfLoadClass", String.class, String.class); + m.setAccessible(true); + return (Class)m.invoke(loader, pkg, name); + } + + public static boolean getResource_decision(@SuppressWarnings("unused") ClassLoader loader, String name) throws Exception { + return name.startsWith("META-INF/services/lombok."); + } + + public static URL getResource_value(ClassLoader loader, String name) throws Exception { + Method m = ProxyClassLoader.class.getDeclaredMethod("findResource", String.class); + m.setAccessible(true); + return (URL) m.invoke(loader, name); + } + + public static boolean getResources_decision(@SuppressWarnings("unused") ClassLoader loader, String name) throws Exception { + return name.startsWith("META-INF/services/lombok."); + } + + public static Enumeration getResources_value(ClassLoader loader, String name) throws Exception { + Method m = ProxyClassLoader.class.getDeclaredMethod("findResources", String.class); + m.setAccessible(true); + return (Enumeration) m.invoke(loader, name); + } + + public static boolean addSelfToClassLoader(Module module, List classPath) { + if (module.getJarFile().getName().equals("org-netbeans-libs-javacimpl.jar")) { + String lombokJarLoc = LiveInjector.findPathJar(Lombok.class); + classPath.add(new File(lombokJarLoc)); + } + + return false; + } + public static void fixContentOnSetTaskListener(JavacTaskImpl that, TaskListener taskListener) throws Throwable { Context context = that.getContext(); + if (context.get(TaskListener.class) != null) context.put(TaskListener.class, (TaskListener)null); if (taskListener != null) { @@ -81,8 +132,9 @@ public class PatchFixes { } public static void addTaskListenerWhenCallingJavac(JavacTaskImpl task, - @SuppressWarnings("unused") /* Will come in handy later */ ClasspathInfo cpInfo) { - task.setTaskListener(new NetbeansEntryPoint(task.getContext())); + @SuppressWarnings("unused") /* Will come in handy later */ ClasspathInfo cpInfo) throws Exception { + Class entryPoint = JavacTaskImpl.class.getClassLoader().loadClass("lombok.netbeans.agent.NetbeansEntryPoint"); + task.setTaskListener((TaskListener) entryPoint.getConstructor(Context.class).newInstance(task.getContext())); } public static Iterator filterGenerated(final Iterator it) { -- cgit