Search in sources :

Example 6 with PhasedUnits

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

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(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) LinkedList(java.util.LinkedList) URL(java.net.URL)

Example 7 with PhasedUnits

use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits 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 8 with PhasedUnits

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

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) {
        org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext = getCeylonContextInstance(context);
        phasedUnits = new PhasedUnits(ceylonContext, new ModuleManagerFactory() {

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

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

Example 9 with PhasedUnits

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

the class CeylonDocTool method initialize.

@Override
public void initialize(CeylonTool mainTool) throws Exception {
    super.initialize(mainTool);
    TypeCheckerBuilder builder = new TypeCheckerBuilder();
    for (File src : sourceFolders) {
        builder.addSrcDirectory(src);
    }
    // set up the artifact repository
    RepositoryManager repository = getRepositoryManager();
    builder.setRepositoryManager(repository);
    // make a destination repo
    outputRepositoryManager = getOutputRepositoryManager();
    // create the actual list of modules to process
    List<File> srcs = FileUtil.applyCwd(cwd, sourceFolders);
    Collection<String> expandedModules = ModuleWildcardsHelper.expandWildcards(srcs, moduleSpecs, null);
    final List<ModuleSpec> modules = ModuleSpec.parseEachList(expandedModules);
    final Callable<PhasedUnits> getPhasedUnits = new Callable<PhasedUnits>() {

        @Override
        public PhasedUnits call() throws Exception {
            return typeChecker.getPhasedUnits();
        }
    };
    // we need to plug in the module manager which can load from .cars
    builder.moduleManagerFactory(new ModuleManagerFactory() {

        @Override
        public ModuleManager createModuleManager(Context context) {
            return new PhasedUnitsModuleManager(getPhasedUnits, context, modules, outputRepositoryManager, bootstrapCeylon, getLogger());
        }

        @Override
        public ModuleSourceMapper createModuleManagerUtil(Context context, ModuleManager moduleManager) {
            return new LazyModuleSourceMapper(context, (PhasedUnitsModuleManager) moduleManager, null, false, null, getEncoding());
        }
    });
    // only parse what we asked for
    List<String> moduleFilters = new LinkedList<String>();
    for (ModuleSpec spec : modules) {
        moduleFilters.add(spec.getName());
        if (spec.getName().equals(Module.LANGUAGE_MODULE_NAME) && !bootstrapCeylon) {
            throw new CeylondException("error.languageModuleBootstrapOptionMissing");
        }
    }
    builder.setModuleFilters(moduleFilters);
    String fileEncoding = getEncoding();
    if (fileEncoding == null) {
        fileEncoding = CeylonConfig.get(DefaultToolOptions.DEFAULTS_ENCODING);
    }
    if (fileEncoding != null) {
        builder.encoding(fileEncoding);
    }
    // We do this ourselves, so we can report on the resolution errors before
    // running typeChecker.process();
    builder.skipDependenciesVerification();
    typeChecker = builder.getTypeChecker();
    {
        PhasedUnits phasedUnits = typeChecker.getPhasedUnits();
        phasedUnits.getModuleManager().prepareForTypeChecking();
        phasedUnits.visitModules();
        phasedUnits.getModuleManager().modulesVisited();
    }
    ModuleValidator moduleValidator = new ModuleValidator(typeChecker.getContext(), typeChecker.getPhasedUnits());
    moduleValidator.verifyModuleDependencyTree();
    AssertionVisitor av = new AssertionVisitor();
    for (PhasedUnit pu : typeChecker.getPhasedUnits().getPhasedUnits()) {
        pu.getCompilationUnit().visit(av);
    }
    if (haltOnError && av.getErrors() > 0) {
        throw new CeylondException("error.failedParsing", new Object[] { av.getErrors() }, null);
    }
    typeChecker.process();
    if (haltOnError && typeChecker.getErrors() > 0) {
        throw new CeylondException("error.failedTypechecking", new Object[] { typeChecker.getErrors() }, null);
    }
    initModules(modules);
    initPhasedUnits();
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) Context(org.eclipse.ceylon.compiler.typechecker.context.Context) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) PhasedUnitsModuleManager(org.eclipse.ceylon.compiler.PhasedUnitsModuleManager) ModuleManager(org.eclipse.ceylon.model.typechecker.util.ModuleManager) AssertionVisitor(org.eclipse.ceylon.compiler.typechecker.util.AssertionVisitor) Callable(java.util.concurrent.Callable) LinkedList(java.util.LinkedList) ModuleValidator(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleValidator) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) PhasedUnitsModuleManager(org.eclipse.ceylon.compiler.PhasedUnitsModuleManager) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) LazyModuleSourceMapper(org.eclipse.ceylon.compiler.java.loader.model.LazyModuleSourceMapper) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) LazyModuleSourceMapper(org.eclipse.ceylon.compiler.java.loader.model.LazyModuleSourceMapper) ModuleSourceMapper(org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper) ModuleManagerFactory(org.eclipse.ceylon.compiler.typechecker.util.ModuleManagerFactory) File(java.io.File)

Aggregations

PhasedUnits (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits)9 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)4 File (java.io.File)3 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3 ModuleManager (org.eclipse.ceylon.model.typechecker.util.ModuleManager)3 IOException (java.io.IOException)2 URLClassLoader (java.net.URLClassLoader)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)2 ModuleSourceMapper (org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper)2 Context (org.eclipse.ceylon.compiler.typechecker.context.Context)2 ModuleManagerFactory (org.eclipse.ceylon.compiler.typechecker.util.ModuleManagerFactory)2 Context (org.eclipse.ceylon.langtools.tools.javac.util.Context)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 RepositoryManagerBuilder (org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder)1