Search in sources :

Example 16 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class JsCompiler method getStitchedFile.

VirtualFile getStitchedFile(final Declaration d, final String suffix) {
    String fqn = d.getQualifiedNameString();
    String name = d.getName();
    if (name == null && d instanceof Constructor) {
        name = "default$constructor";
        if (fqn.endsWith(".null")) {
            fqn = fqn.substring(0, fqn.length() - 4);
        }
        fqn = fqn + name;
    }
    if (fqn.startsWith("ceylon.language")) {
        fqn = fqn.substring(15);
    }
    if (fqn.startsWith("::")) {
        fqn = fqn.substring(2);
    }
    fqn = fqn.replace('.', '/').replace("::", "/");
    File path;
    if (isCompilingLanguageModule()) {
        path = new File(Stitcher.LANGMOD_JS_SRC, fqn + suffix);
    } else {
        PhasedUnit pu = tc.getPhasedUnitFromRelativePath(d.getUnit().getRelativePath());
        path = new File(getFullPath(pu).getParentFile(), name + suffix);
    }
    return findFile(path);
}
Also used : Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 17 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class TestModelClasses method initTests.

@SuppressWarnings("unchecked")
@BeforeClass
public static void initTests() {
    TestModelMethodsAndAttributes.initTypechecker();
    MetamodelVisitor mmg = null;
    for (PhasedUnit pu : TestModelMethodsAndAttributes.tc.getPhasedUnits().getPhasedUnits()) {
        if (pu.getPackage().getModule().getNameAsString().equals("t2")) {
            if (mmg == null) {
                mmg = new MetamodelVisitor(pu.getPackage().getModule());
            }
            pu.getCompilationUnit().visit(mmg);
        }
    }
    topLevelModel = mmg.getModel();
    model = (Map<String, Object>) topLevelModel.get("t2");
}
Also used : MetamodelVisitor(org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) BeforeClass(org.junit.BeforeClass)

Example 18 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class TestModelMethodsAndAttributes method initModel.

@SuppressWarnings("unchecked")
@BeforeClass
public static void initModel() {
    initTypechecker();
    MetamodelVisitor mmg = null;
    for (PhasedUnit pu : tc.getPhasedUnits().getPhasedUnits()) {
        if (pu.getPackage().getModule().getNameAsString().equals("t1")) {
            if (mmg == null) {
                mmg = new MetamodelVisitor(pu.getPackage().getModule());
            }
            pu.getCompilationUnit().visit(mmg);
        }
    }
    topLevelModel = mmg.getModel();
    model = (Map<String, Object>) topLevelModel.get("t1");
}
Also used : MetamodelVisitor(org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) BeforeClass(org.junit.BeforeClass)

Example 19 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

the class LanguageCompiler method initRound.

@Override
public void initRound(JavaCompiler prev) {
    super.initRound(prev);
    // round compilers don't add module trees, it's already done by the first one
    addModuleTrees = false;
    PhasedUnits oldPUs = ((LanguageCompiler) prev).phasedUnits;
    ModuleManager moduleManager = phasedUnits.getModuleManager();
    ModuleSourceMapper moduleSourceMapper = phasedUnits.getModuleSourceMapper();
    for (PhasedUnit pu : oldPUs.getPhasedUnits()) {
        if (pu instanceof CeylonPhasedUnit) {
            CeylonPhasedUnit cpu = (CeylonPhasedUnit) pu;
            // FIXME: this is bad in many ways
            String pkgName;
            try {
                pkgName = getPackage(((CeylonPhasedUnit) pu).getFileObject());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                continue;
            }
            // make a Package with no module yet, we will resolve them later
            /*
                 * Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
                 */
            org.eclipse.ceylon.model.typechecker.model.Package p = modelLoader.findOrCreateModulelessPackage(pkgName == null ? "" : pkgName);
            CeylonPhasedUnit newPu = new CeylonPhasedUnit(pu.getUnitFile(), pu.getSrcDir(), pu.getCompilationUnit(), p, moduleManager, moduleSourceMapper, ceylonContext, cpu.getFileObject(), cpu.getLineMap());
            phasedUnits.addPhasedUnit(pu.getUnitFile(), newPu);
        } else {
            phasedUnits.addPhasedUnit(pu.getUnitFile(), pu);
        }
    }
}
Also used : Package(org.eclipse.ceylon.model.typechecker.model.Package) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) ModuleSourceMapper(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper) IOException(java.io.IOException) ModuleManager(org.eclipse.ceylon.model.typechecker.util.ModuleManager) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 20 with PhasedUnit

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.

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()) {
        if (!phasedUnit.getCompilationUnit().getModuleDescriptors().isEmpty()) {
            String name = phasedUnit.getPackage().getNameAsString();
            CeylonPhasedUnit cpu = (CeylonPhasedUnit) phasedUnit;
            CeylonFileObject cfo = (CeylonFileObject) cpu.getFileObject();
            moduleNamesToFileObjects.put(name, cfo);
        }
    }
    if (addModuleTrees) {
        for (JCCompilationUnit moduleTree : moduleTrees) {
            trees = trees.append(moduleTree);
        }
    }
    return trees;
}
Also used : JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) CeylonCompilationUnit(org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit) Modules(org.eclipse.ceylon.model.typechecker.model.Modules) Package(org.eclipse.ceylon.model.typechecker.model.Package) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Aggregations

PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)28 File (java.io.File)9 Package (org.eclipse.ceylon.model.typechecker.model.Package)7 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)6 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)5 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)5 HashMap (java.util.HashMap)4 CeylonCompilationUnit (org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit)4 MetamodelVisitor (org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor)4 PhasedUnits (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits)4 Node (org.eclipse.ceylon.compiler.typechecker.tree.Node)4 Visitor (org.eclipse.ceylon.compiler.typechecker.tree.Visitor)4 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)4 Module (org.eclipse.ceylon.model.typechecker.model.Module)4 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)4 Map (java.util.Map)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3