Search in sources :

Example 1 with LazyModuleSourceMapper

use of org.eclipse.ceylon.compiler.java.loader.model.LazyModuleSourceMapper in project ceylon by eclipse.

the class CeyloncCompilerDelegate method getModuleSourceMapper.

@Override
public ModuleSourceMapper getModuleSourceMapper() {
    if (moduleSourceMapper == null) {
        org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext = LanguageCompiler.getCeylonContextInstance(context);
        Options options = Options.instance(context);
        boolean verbose = options.isSet(Option.VERBOSE);
        CeylonLog log = (CeylonLog) CeylonLog.instance(context);
        moduleSourceMapper = new LazyModuleSourceMapper(ceylonContext, getModuleManager(), getStatusPrinter(), verbose, log);
    }
    return moduleSourceMapper;
}
Also used : Options(org.eclipse.ceylon.langtools.tools.javac.util.Options) LazyModuleSourceMapper(org.eclipse.ceylon.compiler.java.loader.model.LazyModuleSourceMapper)

Example 2 with LazyModuleSourceMapper

use of org.eclipse.ceylon.compiler.java.loader.model.LazyModuleSourceMapper 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

LazyModuleSourceMapper (org.eclipse.ceylon.compiler.java.loader.model.LazyModuleSourceMapper)2 File (java.io.File)1 LinkedList (java.util.LinkedList)1 Callable (java.util.concurrent.Callable)1 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)1 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)1 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)1 PhasedUnitsModuleManager (org.eclipse.ceylon.compiler.PhasedUnitsModuleManager)1 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)1 ModuleSourceMapper (org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper)1 ModuleValidator (org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleValidator)1 Context (org.eclipse.ceylon.compiler.typechecker.context.Context)1 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)1 PhasedUnits (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits)1 AssertionVisitor (org.eclipse.ceylon.compiler.typechecker.util.AssertionVisitor)1 ModuleManagerFactory (org.eclipse.ceylon.compiler.typechecker.util.ModuleManagerFactory)1 Options (org.eclipse.ceylon.langtools.tools.javac.util.Options)1 ModuleManager (org.eclipse.ceylon.model.typechecker.util.ModuleManager)1