diff options
Diffstat (limited to 'src')
5 files changed, 125 insertions, 7 deletions
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<JavacAST, JavacNode, JCTree> { /** @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<JCTree> filterGenerated(final Iterator<JCTree> it) { + return new Iterator<JCTree>() { + 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); + } +} |