1 46 47 package org.codehaus.groovy.classgen; 48 49 import groovy.lang.GroovyClassLoader; 50 51 import java.io.OutputStreamWriter ; 52 import java.io.PrintWriter ; 53 import java.io.StringWriter ; 54 55 import org.codehaus.groovy.ast.ClassNode; 56 import org.codehaus.groovy.ast.CompileUnit; 57 import org.codehaus.groovy.control.CompilationUnit; 58 import org.codehaus.groovy.control.CompilerConfiguration; 59 import org.objectweb.asm.ClassVisitor; 60 import org.objectweb.asm.Constants; 61 import org.objectweb.asm.util.CheckClassAdapter; 62 import org.objectweb.asm.util.ASMifierClassVisitor; 63 64 71 public class DumpingClassLoader extends GroovyClassLoader implements Constants { 72 73 protected static boolean CHECK_CLASS = false; 74 protected static boolean DUMP_CLASS = true; 75 76 public DumpingClassLoader(ClassLoader parentLoader) { 77 super(parentLoader); 78 } 79 80 81 protected class DebugCollector extends ClassCollector { 82 83 DebugCollector(GroovyClassLoader cl, CompilationUnit unit) { 84 super(cl, unit); 85 } 86 87 public void call(ClassVisitor classWriter, ClassNode classNode) { 88 if (DUMP_CLASS) { 90 dumper.visitClass(classNode); 91 } 92 93 if (CHECK_CLASS) { 94 checker.visitClass(classNode); 95 } 96 97 super.call(classWriter, classNode); 98 } 99 } 100 101 protected ClassCollector createCollector(CompilationUnit unit) { 102 return new DebugCollector(this, unit); 103 } 104 105 protected ASMifierClassVisitor dumpVisitor = new ASMifierClassVisitor(new PrintWriter (new OutputStreamWriter (System.out))); 106 protected ASMifierClassVisitor invisibleDumpVisitor = new ASMifierClassVisitor(new PrintWriter (new StringWriter ())); 107 protected CompileUnit unit = new CompileUnit(this, new CompilerConfiguration()); 108 protected ClassGenerator checker = 109 new AsmClassGenerator2(new GeneratorContext(unit), new CheckClassAdapter(invisibleDumpVisitor), this, null); 110 protected ClassGenerator dumper = new AsmClassGenerator2(new GeneratorContext(unit), dumpVisitor, this, null); 111 112 } 113 | Popular Tags |