Search in sources :

Example 1 with PhasedUnits

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.

the class CeylonDocModuleSourceMapper method createPhasedUnits.

@Override
protected PhasedUnits createPhasedUnits() {
    PhasedUnits units = super.createPhasedUnits();
    String fileEncoding = tool.getEncoding();
    if (fileEncoding == null) {
        fileEncoding = CeylonConfig.get(DefaultToolOptions.DEFAULTS_ENCODING);
    }
    if (fileEncoding != null) {
        units.setEncoding(fileEncoding);
    }
    return units;
}
Also used : PhasedUnits(com.redhat.ceylon.compiler.typechecker.context.PhasedUnits)

Example 2 with PhasedUnits

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.

the class CeylonVersionTool method run.

@Override
public void run() throws IOException, RecognitionException {
    // TODO if version is empty? Prompt? Or should --set have an optional argument?
    TypeCheckerBuilder tcb = new TypeCheckerBuilder();
    for (File path : this.sourceFolders) {
        tcb.addSrcDirectory(applyCwd(path));
    }
    TypeChecker tc = tcb.getTypeChecker();
    PhasedUnits pus = tc.getPhasedUnits();
    pus.visitModules();
    ArrayList<Module> moduleList = new ArrayList<Module>(pus.getModuleSourceMapper().getCompiledModules());
    Collections.sort(moduleList, new Comparator<Module>() {

        @Override
        public int compare(Module m1, Module m2) {
            if (match(m1) && !match(m2)) {
                return -1;
            } else if (!match(m1) && match(m2)) {
                return +1;
            }
            int cmp = m1.getNameAsString().compareToIgnoreCase(m2.getNameAsString());
            if (cmp == 0) {
                cmp = m1.getVersion().compareTo(m2.getVersion());
            }
            return cmp;
        }
    });
    // first update all module versions and remember which version we assigned to which module
    // because the user can update every individual version
    Map<String, String> updatedModuleVersions = new HashMap<String, String>();
    for (Module module : moduleList) {
        boolean isMatch = match(module);
        if (newVersion == null) {
            output(module, isMatch);
        } else if (isMatch) {
            if (!updateModuleVersion(module, updatedModuleVersions)) {
                return;
            }
        }
    }
    // now do dependencies because we know which modules we did update
    if (newVersion != null && !noUpdateDependencies) {
        for (Module module : moduleList) {
            if (!updateModuleImports(module, updatedModuleVersions)) {
                return;
            }
        }
    }
}
Also used : TypeChecker(com.redhat.ceylon.compiler.typechecker.TypeChecker) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TypeCheckerBuilder(com.redhat.ceylon.compiler.typechecker.TypeCheckerBuilder) PhasedUnits(com.redhat.ceylon.compiler.typechecker.context.PhasedUnits) ImportModule(com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportModule) Module(com.redhat.ceylon.model.typechecker.model.Module) File(java.io.File)

Example 3 with PhasedUnits

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.

the class CeylonModuleRunner method postCompile.

private void postCompile(Context context, ErrorCollector listener, String moduleName, File srcDir, String[] dependencies, Set<String> removeAtRuntime, String[] modulesUsingCheckFunction, String[] modulesUsingCheckModule) throws Exception {
    // now fetch stuff from the context
    PhasedUnits phasedUnits = LanguageCompiler.getPhasedUnitsInstance(context);
    List<Runner> moduleRunners = new LinkedList<Runner>();
    // Get a class loader for the car
    // XXX Need to use CMR if the module has dependencies
    URL[] carUrls = getCarUrls(moduleName, dependencies, removeAtRuntime, outRepo);
    URLClassLoader cl = classLoaderForModule(carUrls);
    Runnable moduleInitialiser = getModuleInitialiser(moduleName, carUrls, dependencies, removeAtRuntime, cl);
    if (cl != null) {
        loadCompiledTests(moduleRunners, srcDir, cl, phasedUnits, moduleName, modulesUsingCheckFunction, modulesUsingCheckModule);
    }
    CeylonTestGroup ceylonTestGroup = new CeylonTestGroup(moduleRunners, moduleName, moduleInitialiser);
    children.put(ceylonTestGroup, ceylonTestGroup.getDescription());
}
Also used : Runner(org.junit.runner.Runner) ParentRunner(org.junit.runners.ParentRunner) URLClassLoader(java.net.URLClassLoader) PhasedUnits(com.redhat.ceylon.compiler.typechecker.context.PhasedUnits) LinkedList(java.util.LinkedList) URL(java.net.URL)

Example 4 with PhasedUnits

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.

the class NamingTests method getDecls.

protected List<Declaration> getDecls(String resource) throws Exception {
    final String name = PKGNAME.replace('.', '/') + "/" + resource;
    File file = new File("test/src", name);
    if (!file.exists()) {
        throw new RuntimeException("Unable to find resource " + name);
    }
    RepositoryManagerBuilder builder = new RepositoryManagerBuilder(new NullLogger(), false, 20000, java.net.Proxy.NO_PROXY);
    RepositoryManager repoManager = builder.buildRepository();
    VFS vfs = new VFS();
    Context context = new Context(repoManager, vfs);
    PhasedUnits pus = new PhasedUnits(context);
    // Make the module manager think we're looking at this package
    // even though there's no module descriptor
    pus.getModuleSourceMapper().push(PKGNAME);
    pus.parseUnit(vfs.getFromFile(file), vfs.getFromFile(new File("test-src")));
    final java.util.List<PhasedUnit> listOfUnits = pus.getPhasedUnits();
    PhasedUnit pu = listOfUnits.get(0);
    pu.validateTree();
    pu.scanDeclarations();
    pu.scanTypeDeclarations();
    pu.validateRefinement();
    pu.analyseTypes();
    pu.analyseFlow();
    return pu.getDeclarations();
}
Also used : Context(com.redhat.ceylon.compiler.typechecker.context.Context) VFS(com.redhat.ceylon.compiler.typechecker.io.VFS) RepositoryManagerBuilder(com.redhat.ceylon.cmr.api.RepositoryManagerBuilder) PhasedUnits(com.redhat.ceylon.compiler.typechecker.context.PhasedUnits) RepositoryManager(com.redhat.ceylon.cmr.api.RepositoryManager) File(java.io.File) PhasedUnit(com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)

Example 5 with PhasedUnits

use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.

the class LanguageCompiler method getPhasedUnitsInstance.

/**
 * Get the PhasedUnits instance for this context.
 */
public static PhasedUnits getPhasedUnitsInstance(final Context context) {
    PhasedUnits phasedUnits = context.get(phasedUnitsKey);
    if (phasedUnits == null) {
        com.redhat.ceylon.compiler.typechecker.context.Context ceylonContext = getCeylonContextInstance(context);
        phasedUnits = new PhasedUnits(ceylonContext, new ModuleManagerFactory() {

            @Override
            public ModuleManager createModuleManager(com.redhat.ceylon.compiler.typechecker.context.Context ceylonContext) {
                CompilerDelegate phasedUnitsManager = getCompilerDelegate(context);
                return phasedUnitsManager.getModuleManager();
            }

            @Override
            public ModuleSourceMapper createModuleManagerUtil(com.redhat.ceylon.compiler.typechecker.context.Context ceylonContext, ModuleManager moduleManager) {
                CompilerDelegate phasedUnitsManager = getCompilerDelegate(context);
                return phasedUnitsManager.getModuleSourceMapper();
            }
        });
        context.put(phasedUnitsKey, phasedUnits);
    }
    return phasedUnits;
}
Also used : Context(com.sun.tools.javac.util.Context) AttrContext(com.sun.tools.javac.comp.AttrContext) PhasedUnits(com.redhat.ceylon.compiler.typechecker.context.PhasedUnits) ModuleManagerFactory(com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory) ModuleManager(com.redhat.ceylon.model.typechecker.util.ModuleManager)

Aggregations

PhasedUnits (com.redhat.ceylon.compiler.typechecker.context.PhasedUnits)6 PhasedUnit (com.redhat.ceylon.compiler.typechecker.context.PhasedUnit)2 Context (com.sun.tools.javac.util.Context)2 File (java.io.File)2 URLClassLoader (java.net.URLClassLoader)2 HashMap (java.util.HashMap)2 RepositoryManager (com.redhat.ceylon.cmr.api.RepositoryManager)1 RepositoryManagerBuilder (com.redhat.ceylon.cmr.api.RepositoryManagerBuilder)1 RuntimeModelLoader (com.redhat.ceylon.compiler.java.runtime.model.RuntimeModelLoader)1 RuntimeModuleManager (com.redhat.ceylon.compiler.java.runtime.model.RuntimeModuleManager)1 CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)1 TypeChecker (com.redhat.ceylon.compiler.typechecker.TypeChecker)1 TypeCheckerBuilder (com.redhat.ceylon.compiler.typechecker.TypeCheckerBuilder)1 Context (com.redhat.ceylon.compiler.typechecker.context.Context)1 VFS (com.redhat.ceylon.compiler.typechecker.io.VFS)1 ImportModule (com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportModule)1 ModuleManagerFactory (com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory)1 AbstractModelLoader (com.redhat.ceylon.model.loader.AbstractModelLoader)1 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)1 Module (com.redhat.ceylon.model.typechecker.model.Module)1