aboutsummaryrefslogtreecommitdiff
path: root/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-11-29 16:55:23 +0100
committerReinier Zwitserloot <reinier@tipit.to>2009-11-29 16:55:23 +0100
commit96b7c8ed471745366378d5b7cec8890d16532dee (patch)
treed16b82fd4d7207af6079f4d25960c43968bb6c92 /src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java
parentf0585f4ed491eb455fe9484c735365463ae4184e (diff)
downloadlombok-96b7c8ed471745366378d5b7cec8890d16532dee.tar.gz
lombok-96b7c8ed471745366378d5b7cec8890d16532dee.tar.bz2
lombok-96b7c8ed471745366378d5b7cec8890d16532dee.zip
work in progress.
Diffstat (limited to 'src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java')
-rw-r--r--src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java b/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java
new file mode 100644
index 00000000..26ddd1e4
--- /dev/null
+++ b/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java
@@ -0,0 +1,75 @@
+package lombok.netbeans.agent;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.lang.model.element.Element;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.Tree;
+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.util.Context;
+
+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 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) {
+ try {
+ Method m = JavacTaskImpl.class.getDeclaredMethod("wrap", TaskListener.class);
+ try {
+ m.setAccessible(true);
+ } catch (SecurityException ignore) {}
+ TaskListener w = (TaskListener)m.invoke(that, taskListener);
+ context.put(TaskListener.class, w);
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ //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 Tree returnNullForGeneratedNode(Trees trees, Element element, Object o) throws Throwable {
+ try {
+ Tree tree = trees.getTree(element);
+ if (tree == null) return null;
+ CompilationUnitTree unit = (CompilationUnitTree) o.getClass().getMethod("getCompilationUnit").invoke(o);
+ int startPos = (int) trees.getSourcePositions().getStartPosition(unit, tree);
+ if (startPos == -1) return null;
+ return tree;
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+
+ //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 long returnMinus1ForGeneratedNode(SourcePositions that, CompilationUnitTree cu, Tree tree) {
+ int start = (int) that.getStartPosition(cu, tree);
+ if (start < 0) return -1;
+ return that.getEndPosition(cu, tree);
+ }
+
+ //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() {
+ TaskListenerProvider p = /* Lookup.getDefault().lookup(TLP.class) */;
+ if (p != null) {
+ TaskListener l = p.create(context, cpInfo);
+ task.setTaskListener(l);
+ }
+
+ return;
+ }
+}