Package org.codehaus.janino

Examples of org.codehaus.janino.SimpleCompiler


   
  public static void main(String args[]) throws Exception{
   
    StringBuffer classContext = new StringBuffer();
    classContext.append("public class TestClass{ String a;}");
    SimpleCompiler compiler = new SimpleCompiler();
    compiler.cook(new StringBufferInputStream(classContext.toString()));
    Class testcls = compiler.getClassLoader().loadClass("TestClass");
    System.out.println(testcls);
   
   
   
    JFrame testFrm = new JFrame();
View Full Code Here


      }
        }.traverseCompilationUnit(cu);

        String clsName = (String)clsNames.get(0);
       
        SimpleCompiler compiler = new SimpleCompiler();
    compiler.setParentClassLoader(GlobalContext.class.getClassLoader());
    compiler.cook(new ByteArrayInputStream(javaSource.getBytes()));
    //compiler.getClassLoader().
   
    classLoader = compiler.getClassLoader();
    typeClass = classLoader.loadClass(clsName);
   
    return typeClass;
  }
View Full Code Here

    public Iterable<? extends ByteCode> compile(Iterable<? extends SourceCode> sources) {
        if (sources== null) {           
            throw new IllegalArgumentException("sources==null");
        }
       
        SimpleCompiler compiler = new SimpleCompiler();
        for( SourceCode sc : sources ){
            try {
                compiler.cook(sc.getSourceCode());
            } catch (CompileException ex) {
                Logger.getLogger(JaninoCompiler.class.getName()).log(Level.SEVERE, null, ex);
                throw new Error(ex);
            }
        }
       
        //...........
        ClassLoader cl = compiler.getClassLoader();
        if( !(cl instanceof ByteArrayClassLoader) )
            throw new Error("class loader not instance of org.codehaus.janino.ByteArrayClassLoader");
       
        ByteArrayClassLoader bcl = (ByteArrayClassLoader)cl;
       
View Full Code Here

    public Collection<AObjectMappingDef> getCompiledObjectMappingDefs() {
        return compiledObjectMappingDefs;
    }

    AObjectMappingDef compileObjectMappingDef(ACompilableObjectMappingDef orig) throws Exception {
        final SimpleCompiler compiler = new SimpleCompiler();
        compiler.setDebuggingInformation(true, true, true);
        final ACodeBuilderForMappingDef builder = new ACodeBuilderForMappingDef(AObjectMappingDef.class.getName(), logger);

        final ACodeSnippet codeForMap  = orig.javaCodeForMap(AMappingDefCompiler.OBJECT_MAPPING_SOURCE_SNIPPET, AMappingDefCompiler.OBJECT_MAPPING_TARGET_SNIPPET, compCtx);
        final ACodeSnippet codeForDiff = orig.javaCodeForDiff(AMappingDefCompiler.OBJECT_MAPPING_SOURCE_OLD_SNIPPET, AMappingDefCompiler.OBJECT_MAPPING_SOURCE_NEW_SNIPPET, compCtx);

        builder.addInjectedFields(codeForMap. getInjectedFields());
        builder.addInjectedFields(codeForDiff.getInjectedFields());

        // only raw types in the signatures because neither Janino nor Javassist support generics

        builder.addMethod("public Object map(Object source, Object targetRaw, " +
                AQualifiedSourceAndTargetType.class.getName() + " types, " +
                AMapperWorker.class.getName() + " worker, " +
                AMap.class.getName() + " context, " +
                APath.class.getName() + " path) throws Exception {",
                codeForMap.getCode());

        builder.addMethod("public void diff(" +
                ADiffBuilder.class.getName() + " diff, Object sourceOld, Object sourceNew, " +
                AQualifiedSourceAndTargetType.class.getName() + " types, " +
                AMapperDiffWorker.class.getName() + " worker, " +
                AMap.class.getName() + " contextOld, " +
                AMap.class.getName() + " contextNew, " +
                APath.class.getName() + " path, boolean isDerived) throws Exception {",
                codeForDiff.getCode());

        compiler.cook(builder.build());
        final Class omCls = compiler.getClassLoader().loadClass(builder.fqn);

        // this assumes only one constructor. Seems a somewhat brittle, but no reason comes to mind why there should
        //  every be more than one
        final Constructor ctor = omCls.getConstructors()[0];
View Full Code Here

    public Collection<AObjectMappingDef> getCompiledObjectMappingDefs() {
        return compiledObjectMappingDefs;
    }

    AObjectMappingDef compileObjectMappingDef(ACompilableObjectMappingDef orig) throws Exception {
        final SimpleCompiler compiler = new SimpleCompiler();
        compiler.setDebuggingInformation(true, true, true);
        final ACodeBuilderForMappingDef builder = new ACodeBuilderForMappingDef(AObjectMappingDef.class.getName(), logger);

        final ACodeSnippet codeForMap  = orig.javaCodeForMap(AMappingDefCompiler.OBJECT_MAPPING_SOURCE_SNIPPET, AMappingDefCompiler.OBJECT_MAPPING_TARGET_SNIPPET, compCtx);
        final ACodeSnippet codeForDiff = orig.javaCodeForDiff(AMappingDefCompiler.OBJECT_MAPPING_SOURCE_OLD_SNIPPET, AMappingDefCompiler.OBJECT_MAPPING_SOURCE_NEW_SNIPPET, compCtx);

        builder.addInjectedFields(codeForMap. getInjectedFields());
        builder.addInjectedFields(codeForDiff.getInjectedFields());

        // only raw types in the signatures because neither Janino nor Javassist support generics

        builder.addMethod("public Object map(Object source, Object targetRaw, " +
                AQualifiedSourceAndTargetType.class.getName() + " types, " +
                AMapperWorker.class.getName() + " worker, " +
                AMap.class.getName() + " context, " +
                APath.class.getName() + " path) throws Exception {",
                codeForMap.getCode());

        builder.addMethod("public void diff(" +
                ADiffBuilder.class.getName() + " diff, Object sourceOld, Object sourceNew, " +
                AQualifiedSourceAndTargetType.class.getName() + " types, " +
                AMapperDiffWorker.class.getName() + " worker, " +
                AMap.class.getName() + " contextOld, " +
                AMap.class.getName() + " contextNew, " +
                APath.class.getName() + " path, boolean isDerived) throws Exception {",
                codeForDiff.getCode());

        compiler.cook(builder.build());
        final Class omCls = compiler.getClassLoader().loadClass(builder.fqn);

        // this assumes only one constructor. Seems a somewhat brittle, but no reason comes to mind why there should
        //  every be more than one
        final Constructor ctor = omCls.getConstructors()[0];
View Full Code Here

TOP

Related Classes of org.codehaus.janino.SimpleCompiler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.