Created
January 13, 2012 21:46
-
-
Save nickman/1608875 to your computer and use it in GitHub Desktop.
Dumping Inner Closures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.helios.gmx.classloading.*; | |
| import org.codehaus.groovy.control.* | |
| def instrumentation = ByteCodeRepository.getInstance().agentInstrumentation.getInstrumentation(); | |
| class ByteCodeNet implements java.lang.instrument.ClassFileTransformer { | |
| public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] classfileBuffer) { | |
| if(ByteCodeRepository.getInstance().isGeneratedClosure(classfileBuffer)) { | |
| println "Generated Closure: $className"; | |
| } | |
| return classfileBuffer; | |
| } | |
| } | |
| cft = new ByteCodeNet(); | |
| cu = new CompilationUnit(); | |
| instrumentation.addTransformer(cft, true); | |
| cu.addSource("ClosureFactory.groovy", "public class ClosureFactory3 { public Closure getClosure() { return { it.getDeclaredMethods().each() { println it.toGenericString(); } } } }"); | |
| cu.compile(); | |
| Class.forName("ClosureFactory3").newInstance().getClosure()(cft.getClass()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment