mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 20:15:59 +00:00
netbeans agent now works!
This commit is contained in:
1 parent
199f7f74fd
commit
8165f4628f
5 files changed
+88
-4
No files matched your search
+2
-1
@@ -14,8 +14,9 @@
|
||||
<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/lombok/netbeans/boot_6.8beta.jar"/>
|
||||
<classpathentry kind="lib" path="deps/lombok/netbeans/org-openide-util_6.8beta.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"/>
|
||||
|
||||
BIN
Binary file not shown.
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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", "<init>"))
|
||||
.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)
|
||||
|
||||
@@ -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<File> 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<JCTree> filterGenerated(final Iterator<JCTree> it) {
|
||||
|
||||
Reference in new issue
Block a user