Post-compilation works in both Eclipse and ecj

This commit is contained in:
Roel Spilker committed 2010-08-08 22:27:22 +02:00
1 parent 2683c24ee9
commit d4247f2e8b
2 files changed
+47

No files matched your search

@@ -64,11 +64,39 @@ public class EclipsePatcher extends Agent {
patchSetGeneratedFlag(sm);
patchHideGeneratedNodes(sm);
patchLiveDebug(sm);
patchPostCompileHookEclipse(sm);
} else {
patchPostCompileHookEcj(sm);
}
if (reloadExistingClasses) sm.reloadClasses(instrumentation);
}
private static void patchPostCompileHookEclipse(ScriptManager sm) {
sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder", "writeClassFileContents"))
.target(new MethodTarget("org.eclipse.jdt.internal.core.builder.AbstractImageBuilder", "writeClassFileContents"))
.methodToWrap(new Hook("org.eclipse.jdt.internal.compiler.ClassFile", "getBytes", "byte[]"))
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "runPostCompiler", "byte[]", "byte[]", "java.lang.String"))
.requestExtra(StackRequest.PARAM3)
.transplant()
.build());
}
private static void patchPostCompileHookEcj(ScriptManager sm) {
sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl", "outputClassFiles"))
.methodToWrap(new Hook("javax.tools.JavaFileObject", "openOutputStream", "java.io.OutputStream"))
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "runPostCompiler", "java.io.OutputStream", "java.io.OutputStream"))
.build());
sm.addScript(ScriptBuilder.wrapMethodCall()
.target(new MethodTarget("org.eclipse.jdt.internal.compiler.util.Util", "writeToDisk"))
.methodToWrap(new Hook("java.io.BufferedOutputStream", "<init>", "void", "java.io.OutputStream", "int"))
.wrapMethod(new Hook("lombok.eclipse.agent.PatchFixes", "runPostCompiler", "java.io.BufferedOutputStream", "java.io.BufferedOutputStream"))
.build());
}
private static void patchHideGeneratedNodes(ScriptManager sm) {
sm.addScript(ScriptBuilder.wrapReturnValue()
.target(new MethodTarget("org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder", "findByNode"))
@@ -22,10 +22,16 @@
package lombok.eclipse.agent;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import lombok.core.DiagnosticsReceiver;
import lombok.core.PostCompiler;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.SimpleName;
@@ -107,4 +113,17 @@ public class PatchFixes {
}
return newSimpleNames;
}
public static byte[] runPostCompiler(byte[] bytes, String className) {
byte[] transformed = PostCompiler.applyTransformations(bytes, className, DiagnosticsReceiver.CONSOLE);
return transformed == null ? bytes : transformed;
}
public static OutputStream runPostCompiler(OutputStream out) throws IOException {
return PostCompiler.wrapOutputStream(out, "TEST", DiagnosticsReceiver.CONSOLE);
}
public static BufferedOutputStream runPostCompiler(BufferedOutputStream out) throws IOException {
return new BufferedOutputStream(PostCompiler.wrapOutputStream(out, "TEST", DiagnosticsReceiver.CONSOLE));
}
}