Search in sources :

Example 6 with CeylonFileObject

use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.

the class LanguageCompiler method loadCompiledModules.

private List<JCCompilationUnit> loadCompiledModules(List<JCCompilationUnit> trees, LinkedList<JCCompilationUnit> moduleTrees) {
    compilerDelegate.visitModules(phasedUnits);
    Modules modules = ceylonContext.getModules();
    // now make sure the phase units have their modules and packages set correctly
    for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
        Package pkg = pu.getPackage();
        loadModuleFromSource(pkg, modules, moduleTrees, trees);
    }
    // also make sure we have packages and modules set up for every Java file we compile
    for (JCCompilationUnit cu : trees) {
        // skip Ceylon CUs
        if (cu instanceof CeylonCompilationUnit)
            continue;
        String packageName = "";
        if (cu.pid != null)
            packageName = TreeInfo.fullName(cu.pid).toString();
        /*
             * Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
             */
        Package pkg = modelLoader.findOrCreateModulelessPackage(packageName);
        loadModuleFromSource(pkg, modules, moduleTrees, trees);
    }
    for (PhasedUnit phasedUnit : phasedUnits.getPhasedUnits()) {
        for (Tree.ModuleDescriptor modDescr : phasedUnit.getCompilationUnit().getModuleDescriptors()) {
            String name = phasedUnit.getPackage().getNameAsString();
            CeylonPhasedUnit cpu = (CeylonPhasedUnit) phasedUnit;
            CeylonFileObject cfo = (CeylonFileObject) cpu.getFileObject();
            moduleNamesToFileObjects.put(name, cfo);
        }
    }
    for (JCCompilationUnit moduleTree : moduleTrees) {
        trees = trees.append(moduleTree);
    }
    return trees;
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) CeylonCompilationUnit(com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit) ModuleDescriptor(com.redhat.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor) Modules(com.redhat.ceylon.model.typechecker.model.Modules) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Package(com.redhat.ceylon.model.typechecker.model.Package) CeylonFileObject(com.redhat.ceylon.compiler.java.codegen.CeylonFileObject) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)

Aggregations

CeylonFileObject (com.redhat.ceylon.compiler.java.codegen.CeylonFileObject)6 JavaFileObject (javax.tools.JavaFileObject)4 Package (com.redhat.ceylon.model.typechecker.model.Package)2 CeylonClassWriter (com.redhat.ceylon.compiler.java.codegen.CeylonClassWriter)1 CeylonCompilationUnit (com.redhat.ceylon.compiler.java.codegen.CeylonCompilationUnit)1 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)1 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)1 ImportModule (com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportModule)1 ModuleDescriptor (com.redhat.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor)1 Module (com.redhat.ceylon.model.typechecker.model.Module)1 Modules (com.redhat.ceylon.model.typechecker.model.Modules)1 CompletionFailure (com.sun.tools.javac.code.Symbol.CompletionFailure)1 ClassWriter (com.sun.tools.javac.jvm.ClassWriter)1 JCTree (com.sun.tools.javac.tree.JCTree)1 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)1 DiagnosticSource (com.sun.tools.javac.util.DiagnosticSource)1 ListBuffer (com.sun.tools.javac.util.ListBuffer)1 ArrayList (java.util.ArrayList)1