aboutsummaryrefslogtreecommitdiff
path: root/src/netbeansAgent/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-12-01 13:53:07 +0100
committerReinier Zwitserloot <reinier@tipit.to>2009-12-01 13:53:07 +0100
commit199f7f74fd35462dced087280af066cf2cad7596 (patch)
tree6c0befb9bccede364c07bb843de4f4f5edb87404 /src/netbeansAgent/lombok
parent92e2afe9b0dccc7d0055b52d07ab3128c2adf4de (diff)
downloadlombok-199f7f74fd35462dced087280af066cf2cad7596.tar.gz
lombok-199f7f74fd35462dced087280af066cf2cad7596.tar.bz2
lombok-199f7f74fd35462dced087280af066cf2cad7596.zip
Generalized the agent mechanism; now 1 lombok.jar can serve as the agent for BOTH netbeans AND eclipse, and is future-ready for an IntelliJ agent.
Diffstat (limited to 'src/netbeansAgent/lombok')
-rw-r--r--src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java24
-rw-r--r--src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java20
2 files changed, 22 insertions, 22 deletions
diff --git a/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java b/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java
index 2a87ad6c..bffedfc2 100644
--- a/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java
+++ b/src/netbeansAgent/lombok/netbeans/agent/NetbeansPatcher.java
@@ -23,29 +23,29 @@ package lombok.netbeans.agent;
import java.lang.instrument.Instrumentation;
+import lombok.core.Agent;
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);
+/**
+ * This is a java-agent that patches some of netbeans's classes so that lombok is initialized as Javac TaskListener,
+ * allowing us to change AST nodes anytime netbeans parses source code. It also fixes some of the places in netbeans that
+ * can't deal with generated code.
+ *
+ * The hard work on figuring out where to patch has been done by Jan Lahoda (jlahoda@netbeans.org)
+ */
+public class NetbeansPatcher extends Agent {
+ @Override
+ public void runAgent(String agentArgs, Instrumentation instrumentation, boolean injected) throws Exception {
+ registerPatchScripts(instrumentation, injected);
}
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);
diff --git a/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java b/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java
index 4aa7f77c..3a58d381 100644
--- a/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java
+++ b/src/netbeansAgent/lombok/netbeans/agent/PatchFixes.java
@@ -48,16 +48,16 @@ public class PatchFixes {
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, taskListener);
-// } catch (InvocationTargetException e) {
-// throw e.getCause();
-// }
+ 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();
+ }
}
}