Search in sources :

Example 1 with ModuleManagerFactory

use of com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory in project ceylon-compiler by ceylon.

the class CeylonDocTool method initialize.

@Override
public void initialize(CeylonTool 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);
    List<String> expandedModules = ModuleWildcardsHelper.expandWildcards(srcs, moduleSpecs, null);
    final List<ModuleSpec> modules = ModuleSpec.parseEachList(expandedModules);
    // 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 CeylonDocModuleManager(CeylonDocTool.this, context, modules, outputRepositoryManager, bootstrapCeylon, log);
        }

        @Override
        public ModuleSourceMapper createModuleManagerUtil(Context context, ModuleManager moduleManager) {
            return new CeylonDocModuleSourceMapper(context, (CeylonDocModuleManager) moduleManager, CeylonDocTool.this);
        }
    });
    // 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);
    }
    typeChecker = builder.getTypeChecker();
    // collect all units we are typechecking
    initTypeCheckedUnits(typeChecker);
    typeChecker.process();
    if (haltOnError && typeChecker.getErrors() > 0) {
        throw new CeylondException("error.failedParsing", new Object[] { typeChecker.getErrors() }, null);
    }
    initModules(modules);
    initPhasedUnits();
}
Also used : Context(com.redhat.ceylon.compiler.typechecker.context.Context) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) TypeCheckerBuilder(com.redhat.ceylon.compiler.typechecker.TypeCheckerBuilder) ModuleManager(com.redhat.ceylon.model.typechecker.util.ModuleManager) LinkedList(java.util.LinkedList) ModuleSpec(com.redhat.ceylon.common.tools.ModuleSpec) RepositoryManager(com.redhat.ceylon.cmr.api.RepositoryManager) ModuleSourceMapper(com.redhat.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper) ModuleManagerFactory(com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory) File(java.io.File)

Example 2 with ModuleManagerFactory

use of com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory 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

ModuleManagerFactory (com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory)2 ModuleManager (com.redhat.ceylon.model.typechecker.util.ModuleManager)2 ArtifactContext (com.redhat.ceylon.cmr.api.ArtifactContext)1 RepositoryManager (com.redhat.ceylon.cmr.api.RepositoryManager)1 ModuleSpec (com.redhat.ceylon.common.tools.ModuleSpec)1 TypeCheckerBuilder (com.redhat.ceylon.compiler.typechecker.TypeCheckerBuilder)1 ModuleSourceMapper (com.redhat.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper)1 Context (com.redhat.ceylon.compiler.typechecker.context.Context)1 PhasedUnits (com.redhat.ceylon.compiler.typechecker.context.PhasedUnits)1 AttrContext (com.sun.tools.javac.comp.AttrContext)1 Context (com.sun.tools.javac.util.Context)1 File (java.io.File)1 LinkedList (java.util.LinkedList)1