diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-11-29 16:55:23 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-11-29 16:55:23 +0100 |
commit | 96b7c8ed471745366378d5b7cec8890d16532dee (patch) | |
tree | d16b82fd4d7207af6079f4d25960c43968bb6c92 | |
parent | f0585f4ed491eb455fe9484c735365463ae4184e (diff) | |
download | lombok-96b7c8ed471745366378d5b7cec8890d16532dee.tar.gz lombok-96b7c8ed471745366378d5b7cec8890d16532dee.tar.bz2 lombok-96b7c8ed471745366378d5b7cec8890d16532dee.zip |
work in progress.
-rw-r--r-- | .classpath | 12 | ||||
-rw-r--r-- | deps/agent/.gitkeep | 1 | ||||
-rw-r--r-- | deps/lombok/eclipse/org.eclipse.core.runtime_3.5.0.v20090525.jar | bin | 0 -> 69761 bytes | |||
-rw-r--r-- | deps/lombok/eclipse/org.eclipse.equinox.common_3.5.0.v20090520-1800.jar | bin | 0 -> 99430 bytes | |||
-rw-r--r-- | deps/lombok/eclipse/org.eclipse.jdt.core_3.5.0.v_963.jar | bin | 0 -> 4471784 bytes | |||
-rw-r--r-- | deps/lombok/eclipse/org.eclipse.jdt.ui_3.5.1.r351_v20090821-0800.jar | bin | 0 -> 9803138 bytes | |||
-rw-r--r-- | deps/lombok/eclipse/org.eclipse.osgi_3.5.0.v20090520.jar | bin | 0 -> 1122602 bytes | |||
-rw-r--r-- | deps/lombok/netbeans/org-netbeans-modules-java-source_6.8beta.jar | bin | 0 -> 2155618 bytes | |||
-rw-r--r-- | deps/netbeans.agent/.gitkeep | 1 | ||||
-rw-r--r-- | src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java | 98 | ||||
-rw-r--r-- | src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java | 75 | ||||
-rw-r--r-- | src/netbeansAgent/lombok/netbeans/agent/TaskListenerProvider.java | 5 | ||||
-rw-r--r-- | src/netbeansAgent/lombok/netbeans/agent/package-info.java | 26 |
13 files changed, 211 insertions, 7 deletions
@@ -2,17 +2,19 @@ <classpath> <classpathentry kind="src" path="src/core"/> <classpathentry kind="src" path="src/eclipseAgent"/> + <classpathentry kind="src" path="src/netbeansAgent"/> <classpathentry kind="src" path="src/installer"/> <classpathentry kind="src" path="src/delombok"/> <classpathentry kind="src" path="experimental/src"/> <classpathentry kind="src" path="test/delombok/src"/> <classpathentry kind="src" path="test/core/src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="lib" path="deps/lombok/org.eclipse.jdt.core_3.5.0.v_963.jar"/> - <classpathentry kind="lib" path="deps/lombok/org.eclipse.jdt.ui_3.5.1.r351_v20090821-0800.jar"/> - <classpathentry kind="lib" path="deps/lombok/org.eclipse.core.runtime_3.5.0.v20090525.jar"/> - <classpathentry kind="lib" path="deps/lombok/org.eclipse.osgi_3.5.0.v20090520.jar"/> - <classpathentry kind="lib" path="deps/lombok/org.eclipse.equinox.common_3.5.0.v20090520-1800.jar"/> + <classpathentry kind="lib" path="deps/lombok/eclipse/org.eclipse.jdt.core_3.5.0.v_963.jar"/> + <classpathentry kind="lib" path="deps/lombok/eclipse/org.eclipse.jdt.ui_3.5.1.r351_v20090821-0800.jar"/> + <classpathentry kind="lib" path="deps/lombok/eclipse/org.eclipse.core.runtime_3.5.0.v20090525.jar"/> + <classpathentry kind="lib" path="deps/lombok/eclipse/org.eclipse.osgi_3.5.0.v20090520.jar"/> + <classpathentry kind="lib" path="deps/lombok/eclipse/org.eclipse.equinox.common_3.5.0.v20090520-1800.jar"/> + <classpathentry kind="lib" path="deps/lombok/netbeans/org-netbeans-modules-java-source_6.8beta.jar"/> <classpathentry kind="lib" path="deps/junit-4.7.jar"/> <classpathentry kind="lib" path="deps/lombok/ant.jar"/> <classpathentry combineaccessrules="false" kind="src" path="/lombok.patcher"/> 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 Binary files differnew file mode 100644 index 00000000..a1cf295a --- /dev/null +++ b/deps/lombok/eclipse/org.eclipse.core.runtime_3.5.0.v20090525.jar 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 Binary files differnew file mode 100644 index 00000000..8687a112 --- /dev/null +++ b/deps/lombok/eclipse/org.eclipse.equinox.common_3.5.0.v20090520-1800.jar 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 Binary files differnew file mode 100644 index 00000000..0db68569 --- /dev/null +++ b/deps/lombok/eclipse/org.eclipse.jdt.core_3.5.0.v_963.jar 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 Binary files differnew file mode 100644 index 00000000..fe3d9bee --- /dev/null +++ b/deps/lombok/eclipse/org.eclipse.jdt.ui_3.5.1.r351_v20090821-0800.jar 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 Binary files differnew file mode 100644 index 00000000..b80140e0 --- /dev/null +++ b/deps/lombok/eclipse/org.eclipse.osgi_3.5.0.v20090520.jar 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 Binary files differnew file mode 100644 index 00000000..04b51656 --- /dev/null +++ b/deps/lombok/netbeans/org-netbeans-modules-java-source_6.8beta.jar 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 diff --git a/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java b/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java new file mode 100644 index 00000000..4210aa87 --- /dev/null +++ b/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java @@ -0,0 +1,98 @@ +/* + * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.netbeans.agent; + +import java.lang.instrument.Instrumentation; + +import lombok.patcher.Hook; +import lombok.patcher.MethodTarget; +import lombok.patcher.ScriptManager; +import lombok.patcher.StackRequest; +import lombok.patcher.equinox.EquinoxClassLoader; +import lombok.patcher.scripts.ScriptBuilder; + +public class NetbeansPatcher { + private NetbeansPatcher() {} + + public static void agentmain(@SuppressWarnings("unused") String agentArgs, Instrumentation instrumentation) throws Exception { + registerPatchScripts(instrumentation, true); + } + + public static void premain(@SuppressWarnings("unused") String agentArgs, Instrumentation instrumentation) throws Exception { + registerPatchScripts(instrumentation, false); + } + + private static void registerPatchScripts(Instrumentation instrumentation, boolean reloadExistingClasses) { + ScriptManager sm = new ScriptManager(); + sm.registerTransformer(instrumentation); + EquinoxClassLoader.addPrefix("lombok."); + EquinoxClassLoader.registerScripts(sm); + + patchNetbeansJavac(sm); + patchNetbeansMissingPositionAwareness(sm); + + if (reloadExistingClasses) sm.reloadClasses(instrumentation); + } + + private static void patchNetbeansJavac(ScriptManager sm) { + sm.addScript(ScriptBuilder.wrapReturnValue() + .request(StackRequest.THIS, StackRequest.PARAM1) + .transplant() + .target(new MethodTarget("com.sun.tools.javac.api.JavacTaskImpl", "setTaskListener")) + .wrapMethod(new Hook("lombok/netbeans/agent/PatchFixes", "fixContentOnSetTaskListener", + "(Lcom/sun/tools/javac/api/JavacTaskImpl;Lcom/sun/source/util/TaskListener;)V")) + .build()); + + sm.addScript(ScriptBuilder.wrapReturnValue() + .request() + .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")) + .build()); + } + + private static void patchNetbeansMissingPositionAwareness(ScriptManager sm) { + sm.addScript(ScriptBuilder.replaceMethodCall() + .target(new MethodTarget("org.netbeans.modules.java.editor.overridden.ComputeAnnotations", + "createAnnotations")) + .methodToReplace(new Hook("com/sun/source/util/Trees", "getTree", + "(Ljavax/lang/model/element/Element;)Lcom/sun/source/tree/Tree;")) + .replacementMethod(new Hook("lombok/netbeans/agent/PatchFixes", "returnNullForGeneratedNode", + "(Lcom/sun/source/util/Trees;Ljavax/lang/model/element/Element;Ljava/lang/Object;)" + + "Lcom/sun/source/tree/Tree;")) + .requestExtra(StackRequest.PARAM1) + .build()); + + sm.addScript(ScriptBuilder.replaceMethodCall() + .target(new MethodTarget("org.netbeans.modules.java.source.parsing.FindMethodRegionsVisitor", + "visitMethod")) + .methodToReplace(new Hook("com/sun/source/util/SourcePositions", "getEndPosition", + "(Lcom/sun/source/tree/CompilationUnitTree;Lcom/sun/source/tree/Tree;)J")) + .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()); + } +} 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; + } +} diff --git a/src/netbeansAgent/lombok/netbeans/agent/TaskListenerProvider.java b/src/netbeansAgent/lombok/netbeans/agent/TaskListenerProvider.java new file mode 100644 index 00000000..59ac6c54 --- /dev/null +++ b/src/netbeansAgent/lombok/netbeans/agent/TaskListenerProvider.java @@ -0,0 +1,5 @@ +package lombok.netbeans.agent; + +public interface TaskListenerProvider { + public TaskListener create(Context c, ClasspathInfo info); +} diff --git a/src/netbeansAgent/lombok/netbeans/agent/package-info.java b/src/netbeansAgent/lombok/netbeans/agent/package-info.java new file mode 100644 index 00000000..a6a2f2db --- /dev/null +++ b/src/netbeansAgent/lombok/netbeans/agent/package-info.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * Contains the mechanism that instruments netbeans by being loaded as a javaagent. + */ +package lombok.netbeans.agent; |