Search in sources :

Example 1 with JavaAstLoader

use of kalang.compiler.JavaAstLoader in project kalang by kasonyang.

the class FileSystemCompiler method compile.

public void compile() throws IOException {
    if (outputDir == null) {
        throw new IllegalStateException("output diretory is null");
    }
    URLClassLoader pathClassLoader = new URLClassLoader(classPaths.toArray(new URL[classPaths.size()]), this.classLoader);
    AstLoader astLoader = new JavaAstLoader(this.parentAstLoader, pathClassLoader);
    KalangCompiler compiler = new KalangCompiler(astLoader) {

        @Override
        public CodeGenerator createCodeGenerator(CompilationUnit compilationUnit) {
            FileSystemOutputManager om = new FileSystemOutputManager(outputDir, extension);
            return new ClassWriter(om);
        }
    };
    compiler.setConfiguration(configuration);
    for (Map.Entry<String, File> e : sourceFiles.entrySet()) {
        String className = e.getKey();
        File file = e.getValue();
        compiler.addSource(className, FileUtils.readFileToString(file), file.getName());
    }
    FileSystemSourceLoader sourceLoader = new FileSystemSourceLoader(sourcePaths.toArray(new File[sourcePaths.size()]), new String[] { "kl", "kalang" });
    compiler.setSourceLoader(sourceLoader);
    if (diagnosisHandler != null) {
        compiler.setDiagnosisHandler(diagnosisHandler);
    }
    compiler.compile();
}
Also used : CompilationUnit(kalang.compiler.CompilationUnit) AstLoader(kalang.compiler.AstLoader) JavaAstLoader(kalang.compiler.JavaAstLoader) KalangCompiler(kalang.compiler.KalangCompiler) JavaAstLoader(kalang.compiler.JavaAstLoader)

Aggregations

AstLoader (kalang.compiler.AstLoader)1 CompilationUnit (kalang.compiler.CompilationUnit)1 JavaAstLoader (kalang.compiler.JavaAstLoader)1 KalangCompiler (kalang.compiler.KalangCompiler)1