From 199f7f74fd35462dced087280af066cf2cad7596 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 1 Dec 2009 13:53:07 +0100 Subject: 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. --- .../lombok/netbeans/agent/NetbeansPatcher.java | 24 +++++++++++----------- .../lombok/netbeans/agent/PatchFixes.java | 20 +++++++++--------- 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'src/netbeansAgent/lombok') 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(); + } } } -- cgit