Logo Search packages:      
Sourcecode: janino version File versions  Download package

final ClassLoader org::codehaus::janino::SimpleCompiler::compileToClassLoader ( Java.CompilationUnit  compilationUnit,
EnumeratorSet  debuggingInformation 
) throws CompileException [inline, protected]

Compile the given compilation unit. (A "compilation unit" is typically the contents of a JavaTM source file.)

compilationUnit The parsed compilation unit
debuggingInformation What kind of debugging information to generate in the class file
The ClassLoader into which the compiled classes were defined

Definition at line 396 of file SimpleCompiler.java.

References org::codehaus::janino::util::ClassFile::getThisClassName(), and org::codehaus::janino::util::ClassFile::toByteArray().

Referenced by org::codehaus::janino::ClassBodyEvaluator::compileToClass(), and cook().

        if (SimpleCompiler.DEBUG) {
            UnparseVisitor.unparse(compilationUnit, new OutputStreamWriter(System.out));

        // Compile compilation unit to class files.
        ClassFile[] classFiles = new UnitCompiler(

        // Convert the class files to bytes and store them in a Map.
        Map classes = new HashMap(); // String className => byte[] data
        for (int i = 0; i < classFiles.length; ++i) {
            ClassFile cf = classFiles[i];
            classes.put(cf.getThisClassName(), cf.toByteArray());

        // Disassemble all generated classes (for debugging).
        if (SimpleCompiler.DEBUG) {
            for (Iterator it = classes.entrySet().iterator(); it.hasNext();) {
                Map.Entry me = (Map.Entry) it.next();
                String className = (String) me.getKey();
                byte[] bytecode = (byte[]) me.getValue();
                System.out.println("*** Disassembly of class \"" + className + "\":");
                try {
                    new Disassembler().disasm(new ByteArrayInputStream(bytecode));
                } catch (IOException ex) {
                    throw new RuntimeException("SNO: IOException despite ByteArrayInputStream");

        // Create a ClassLoader that loads the generated classes.
        this.result = new ByteArrayClassLoader(
            classes,         // classes
            this.classLoader // parent
        return this.result;

Generated by  Doxygen 1.6.0   Back to index