Search in sources :

Example 16 with TypeCheckerBuilder

use of org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder in project ceylon by eclipse.

the class TestMultipackages method setup.

@Before
public void setup() throws IOException {
    // Compile module with 2 packages
    System.out.println("Compiling multi");
    TypeCheckerBuilder tcb = new TypeCheckerBuilder().usageWarnings(false);
    tcb.addSrcDirectory(new java.io.File("src/test/resources/multi/pass1"));
    tcb.setRepositoryManager(repoman);
    TypeChecker tc = tcb.getTypeChecker();
    tc.process();
    Options options = new Options().addRepo("build/test/test_modules").outRepo("build/test/test_modules").addSrcDir("src/test/resources/multi/pass1");
    JsCompiler compiler = new JsCompiler(tc, options);
    compiler.stopOnErrors(false);
    compiler.generate();
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) Before(org.junit.Before)

Example 17 with TypeCheckerBuilder

use of org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder in project ceylon by eclipse.

the class TestMultipackages method test.

@Test
public void test() throws IOException {
    // Compile module with 2 packages
    System.out.println("Compiling usemulti");
    TypeCheckerBuilder tcb = new TypeCheckerBuilder().usageWarnings(false);
    tcb.moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
    tcb.addSrcDirectory(new java.io.File("src/test/resources/multi/pass2"));
    tcb.setRepositoryManager(repoman);
    TypeChecker tc = tcb.getTypeChecker();
    tc.process();
    Options options = new Options().addRepo("build/test/test_modules").outRepo("build/test/test_modules").addSrcDir("src/test/resources/multi/pass2").verbose("");
    JsCompiler compiler = new JsCompiler(tc, options);
    compiler.stopOnErrors(false);
    compiler.generate();
}
Also used : JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) Options(org.eclipse.ceylon.compiler.js.util.Options) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) Test(org.junit.Test)

Example 18 with TypeCheckerBuilder

use of org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder in project ceylon by eclipse.

the class TestSiteVariance method typeChecker.

private TypeChecker typeChecker(Options opts) {
    final RepositoryManager repoman = CeylonUtils.repoManager().userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
    final TypeCheckerBuilder builder = new TypeCheckerBuilder().moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
    for (File sd : opts.getSrcDirs()) {
        builder.addSrcDirectory(sd);
    }
    builder.setRepositoryManager(repoman);
    final TypeChecker tc = builder.getTypeChecker();
    JsModuleManagerFactory.setVerbose(true);
    tc.process();
    return tc;
}
Also used : JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File)

Example 19 with TypeCheckerBuilder

use of org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder 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)

Example 20 with TypeCheckerBuilder

use of org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder in project ceylon by eclipse.

the class CeylonCompileJsTool method run.

@Override
public void run() throws Exception {
    AppendableWriter writer = new AppendableWriter(getOutAppendable());
    final Options opts = new Options().cwd(cwd).repos(getRepositoryAsStrings()).sourceDirs(roots).resourceDirs(resources).resourceRootName(resourceRootName).systemRepo(systemRepo).outRepo(getOut()).user(user).pass(pass).optimize(optimize).modulify(modulify).comment(comments).verbose(getVerbose()).profile(profile).stdin(false).generateSourceArchive(!skipSrc).encoding(encoding).includeDependencies(includeDependencies).diagnosticListener(diagnosticListener).outWriter(writer).suppressWarnings(suppwarns);
    final TypeChecker typeChecker;
    if (opts.hasVerboseFlag("cmr")) {
        append("Using repositories: " + getRepositoryAsStrings());
        newline();
    }
    final RepositoryManager repoman = getRepositoryManager();
    long t0, t1, t2, t3, t4;
    final TypeCheckerBuilder tcb;
    List<File> onlySources = null;
    List<File> onlyResources = null;
    if (opts.isStdin()) {
        VirtualFile src = new VirtualFile() {

            @Override
            public boolean exists() {
                return true;
            }

            @Override
            public boolean isFolder() {
                return false;
            }

            @Override
            public String getName() {
                return "SCRIPT.ceylon";
            }

            @Override
            public String getPath() {
                return getName();
            }

            @Override
            public String getRelativePath(VirtualFile file) {
                return "";
            }

            @Override
            public InputStream getInputStream() {
                return System.in;
            }

            @Override
            public List<VirtualFile> getChildren() {
                return Collections.emptyList();
            }

            @Override
            public int hashCode() {
                return getPath().hashCode();
            }

            @Override
            public boolean equals(Object obj) {
                if (obj instanceof VirtualFile) {
                    return ((VirtualFile) obj).getPath().equals(getPath());
                } else {
                    return super.equals(obj);
                }
            }

            @Override
            public int compareTo(VirtualFile o) {
                return getPath().compareTo(o.getPath());
            }
        };
        t0 = System.nanoTime();
        tcb = new TypeCheckerBuilder().addSrcDirectory(src);
    } else {
        t0 = System.nanoTime();
        tcb = new TypeCheckerBuilder();
        SourceArgumentsResolver resolver = new SourceArgumentsResolver(roots, resources, Constants.CEYLON_SUFFIX, Constants.JS_SUFFIX);
        resolver.cwd(cwd).expandAndParse(files, Backend.JavaScript);
        if (includeDependencies != null && !COMPILE_NEVER.equals(includeDependencies)) {
            // Determine any dependencies that might need compiling as well
            SourceDependencyResolver sdr = new SourceDependencyResolver(getModuleVersionReader(), roots, Backends.JS);
            if (sdr.traverseDependencies(resolver.getSourceFiles())) {
                for (ModuleVersionDetails mvd : sdr.getAdditionalModules()) {
                    if (COMPILE_FORCE.equals(includeDependencies) || (COMPILE_CHECK.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JS, true)) || (COMPILE_ONCE.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JS, false))) {
                        files.add(mvd.getModule());
                        resolver.expandAndParse(files, Backend.JavaScript);
                    }
                }
            }
        }
        onlySources = resolver.getSourceFiles();
        onlyResources = resolver.getResourceFiles();
        if (onlySources.isEmpty()) {
            String msg = CeylonCompileJsMessages.msg("error.no.sources");
            if (ModuleWildcardsHelper.onlyGlobArgs(files)) {
                throw new NonFatalToolMessage(msg);
            } else {
                throw new ToolUsageError(msg);
            }
        }
        if (opts.isVerbose()) {
            append("Adding source directories to typechecker:" + roots).newline();
        }
        for (File root : roots) {
            File cwdRoot = applyCwd(root);
            if (cwdRoot.exists() && cwdRoot.isDirectory()) {
                tcb.addSrcDirectory(cwdRoot);
            }
        }
        tcb.setSourceFiles(onlySources);
        if (!resolver.getSourceModules().isEmpty()) {
            tcb.setModuleFilters(resolver.getSourceModules());
        }
        tcb.statistics(opts.isProfile());
        JsModuleManagerFactory.setVerbose(opts.hasVerboseFlag("loader"));
        tcb.moduleManagerFactory(new JsModuleManagerFactory(encoding));
    }
    // getting the type checker does process all types in the source directory
    tcb.verbose(opts.hasVerboseFlag("ast")).setRepositoryManager(repoman);
    tcb.usageWarnings(false).encoding(encoding);
    typeChecker = tcb.getTypeChecker();
    t1 = System.nanoTime();
    TypeCache.doWithoutCaching(new Runnable() {

        @Override
        public void run() {
            typeChecker.process(true);
        }
    });
    t2 = System.nanoTime();
    JsCompiler jsc = new JsCompiler(typeChecker, opts);
    if (onlySources != null) {
        if (opts.isVerbose()) {
            append("Only these files will be compiled: " + onlySources).newline();
        }
        jsc.setSourceFiles(onlySources);
    }
    if (onlyResources != null) {
        jsc.setResourceFiles(onlyResources);
    }
    t3 = System.nanoTime();
    if (!jsc.generate()) {
        if (jsc.getExitCode() != 0) {
            if (throwOnError)
                throw new RuntimeException("Compiler exited with non-zero exit code: " + jsc.getExitCode());
            else {
                jsc.printErrorsAndCount(writer);
                System.exit(jsc.getExitCode());
            }
        }
        int count = jsc.printErrorsAndCount(writer);
        String msg = (count > 1) ? "There were %d errors." : "There was %d error.";
        flush();
        throw new CompilerErrorException(String.format(msg, count));
    } else {
        // We still call this here for any warning there might be
        jsc.printErrorsAndCount(writer);
    }
    t4 = System.nanoTime();
    if (opts.isProfile() || opts.hasVerboseFlag("benchmark")) {
        System.err.println("PROFILING INFORMATION");
        System.err.printf("TypeChecker creation:   %6d nanos%n", t1 - t0);
        System.err.printf("TypeChecker processing: %6d nanos%n", t2 - t1);
        System.err.printf("JS compiler creation:   %6d nanos%n", t3 - t2);
        System.err.printf("JS compilation:         %6d nanos%n", t4 - t3);
        System.out.println("Compilation finished.");
    }
}
Also used : VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) Options(org.eclipse.ceylon.compiler.js.util.Options) DefaultToolOptions(org.eclipse.ceylon.common.config.DefaultToolOptions) JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) SourceArgumentsResolver(org.eclipse.ceylon.common.tools.SourceArgumentsResolver) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) SourceDependencyResolver(org.eclipse.ceylon.common.tools.SourceDependencyResolver) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) NonFatalToolMessage(org.eclipse.ceylon.common.tool.NonFatalToolMessage) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Aggregations

TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)20 File (java.io.File)14 TypeChecker (org.eclipse.ceylon.compiler.typechecker.TypeChecker)14 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)11 Options (org.eclipse.ceylon.compiler.js.util.Options)8 JsCompiler (org.eclipse.ceylon.compiler.js.JsCompiler)6 JsModuleManagerFactory (org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory)6 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)5 ArrayList (java.util.ArrayList)4 ClosableVirtualFile (org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile)3 LeakingLogger (org.eclipse.ceylon.compiler.typechecker.io.cmr.impl.LeakingLogger)3 Module (org.eclipse.ceylon.model.typechecker.model.Module)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 PhasedUnits (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits)2 BeforeClass (org.junit.BeforeClass)2 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1