Search in sources :

Example 11 with TypeCheckerBuilder

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

the class CompileSomething method main.

public static void main(String[] x) throws IOException {
    final Options opts = new Options().outRepo("/tmp/modules").addRepo("compiler-js/build/runtime").addRepo("../ceylon.ast/modules").addRepo("../ceylon-sdk/modules").addRepo("compiler-js/build/test/proto").addRepo("npm:").optimize(true).verbose("all").generateSourceArchive(false).suppressWarnings(EnumUtil.enumsFromStrings(Warning.class, Arrays.asList("unusedImport"))).addSrcDir("/tmp/source");
    final TypeCheckerBuilder tcb = new TypeCheckerBuilder().statistics(false).encoding("UTF-8");
    for (File sd : opts.getSrcDirs()) {
        tcb.addSrcDirectory(sd);
    }
    final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo(opts.getSystemRepo()).userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
    tcb.setRepositoryManager(repoman);
    JsModuleManagerFactory.setVerbose(true);
    tcb.moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
    final TypeChecker tc = tcb.getTypeChecker();
    TypeCache.setEnabled(false);
    tc.process(true);
    TypeCache.setEnabled(true);
    final JsCompiler jsc = new JsCompiler(tc, opts);
    ArrayList<File> individualSources = new ArrayList<>();
    for (File srcdir : opts.getSrcDirs()) {
        for (File sd : srcdir.listFiles()) {
            if (sd.isFile() && sd.getName().endsWith(".js") || !individualSources.isEmpty()) {
                System.out.println("Especificando archivos para incluir fuentes js");
                individualSources.addAll(Arrays.asList(srcdir.listFiles()));
                break;
            }
        }
    }
    if (!individualSources.isEmpty()) {
        jsc.setSourceFiles(individualSources);
    }
    jsc.stopOnErrors(true);
    boolean ok = jsc.generate();
    jsc.printErrors(new java.io.PrintWriter(System.out));
    if (ok) {
        System.out.println("OK");
    } else {
        System.out.println("EXIT CODE: " + jsc.getExitCode());
    }
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) ArrayList(java.util.ArrayList) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler)

Example 12 with TypeCheckerBuilder

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

the class TestJavaDeps method testJavaDependencies.

@Test
public void testJavaDependencies() throws IOException {
    final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test-modules").buildManager();
    final TypeCheckerBuilder builder = new TypeCheckerBuilder().setRepositoryManager(repoman).addSrcDirectory(new File("src/test/resources/javadeps"));
    final TypeChecker tc = builder.getTypeChecker();
    tc.process();
    final Options opts = new Options().addSrcDir("src/test/resources/javadeps").outRepo("./build").comment(false).generateSourceArchive(false).encoding("UTF-8");
    final JsCompiler comp = new JsCompiler(tc, opts);
    comp.generate();
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) 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) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) Test(org.junit.Test)

Example 13 with TypeCheckerBuilder

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

the class TestModelMethodsAndAttributes method initTypechecker.

public static void initTypechecker() {
    if (model == null) {
        final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test-modules").buildManager();
        tc = new TypeCheckerBuilder().addSrcDirectory(new File("src/test/resources/modeltests")).setRepositoryManager(repoman).getTypeChecker();
        tc.process();
    }
}
Also used : RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File)

Example 14 with TypeCheckerBuilder

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

the class TestStaticTypeComparator method setup.

@BeforeClass
public static void setup() {
    final TypeCheckerBuilder tcb = new TypeCheckerBuilder().statistics(true).encoding("UTF-8");
    tcb.addSrcDirectory(new File("../language/src"));
    tc = tcb.getTypeChecker();
    tc.process();
}
Also used : TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 15 with TypeCheckerBuilder

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

the class TestModuleManager method setup.

@BeforeClass
public static void setup() throws IOException {
    // Copy language module to destination
    java.io.File srclangmod = new java.io.File(String.format("build/runtime/ceylon/language/%s/ceylon.language-%<s.js", Versions.CEYLON_VERSION_NUMBER));
    java.io.File dstlangmod = new java.io.File("build/test/test_modules/ceylon/language/" + Versions.CEYLON_VERSION_NUMBER);
    System.out.printf("Copying %s to %s%n", srclangmod, dstlangmod);
    dstlangmod.mkdirs();
    java.io.BufferedReader lmreader = new java.io.BufferedReader(new java.io.FileReader(srclangmod));
    java.io.Writer lmwriter = new java.io.FileWriter(new java.io.File(dstlangmod, srclangmod.getName()));
    String line;
    while ((line = lmreader.readLine()) != null) {
        lmwriter.write(line);
        lmwriter.write('\n');
    }
    lmreader.close();
    lmwriter.close();
    options = new Options().addRepo("build/test/test_modules").outRepo("build/test/test_modules").addSrcDir("src/test/resources/loader/pass1/m1/test.ceylon").addSrcDir("src/test/resources/loader/pass1");
    repoman = CeylonUtils.repoManager().cwd(options.getCwd()).systemRepo(options.getSystemRepo()).userRepos(options.getRepos()).outRepo(options.getOutRepo()).buildManager();
    // Create a typechecker to compile the test module
    System.out.println("Compiling pass 1");
    TypeCheckerBuilder tcb = new TypeCheckerBuilder().usageWarnings(false);
    tcb.addSrcDirectory(new java.io.File("src/test/resources/loader/pass1"));
    tcb.setRepositoryManager(repoman);
    tc = tcb.getTypeChecker();
    tc.process();
    JsCompiler compiler = new JsCompiler(tc, options);
    compiler.stopOnErrors(false);
    compiler.generate();
    loadJsModel();
    srcmod = tc.getPhasedUnits().getPhasedUnits().get(0).getPackage().getModule().getLanguageModule();
    jsmod = jstc.getPhasedUnits().getPhasedUnits().get(0).getPackage().getModule().getLanguageModule();
    srclang = srcmod.getDirectPackage(Module.LANGUAGE_MODULE_NAME);
    jslang = jsmod.getDirectPackage(Module.LANGUAGE_MODULE_NAME);
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) BeforeClass(org.junit.BeforeClass)

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