Search in sources :

Example 6 with JsCompiler

use of org.eclipse.ceylon.compiler.js.JsCompiler 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 7 with JsCompiler

use of org.eclipse.ceylon.compiler.js.JsCompiler in project ceylon by eclipse.

the class TestSiteVariance method testSiteVariance.

@Test
@SuppressWarnings("unchecked")
public void testSiteVariance() throws IOException {
    // Typecheck
    Options opts = options("src/test/resources/variance/phase1");
    TypeChecker tc = typeChecker(opts);
    // Compile
    JsCompiler jsc = new JsCompiler(tc, opts);
    jsc.generate();
    Map<String, Object> model = JavaScriptResolver.readJsonModel(new File("modules/phase1/0.1/phase1-0.1-model.js"));
    Assert.assertNotNull("Model not found", model);
    model = (Map<String, Object>) model.get("phase1");
    Assert.assertNotNull("Default package not found", model);
    model = (Map<String, Object>) model.get("m2");
    Assert.assertNotNull("Function m2 not found", model);
    Map<String, Object> type = (Map<String, Object>) model.get(MetamodelGenerator.KEY_TYPE);
    List<Map<String, Object>> targs = (List<Map<String, Object>>) type.get(MetamodelGenerator.KEY_TYPE_PARAMS);
    type = targs.get(0);
    List<List<Map<String, Object>>> paramLists = (List<List<Map<String, Object>>>) model.get(MetamodelGenerator.KEY_PARAMS);
    Map<String, Object> parm = paramLists.get(0).get(0);
    parm = (Map<String, Object>) parm.get(MetamodelGenerator.KEY_TYPE);
    targs = (List<Map<String, Object>>) parm.get(MetamodelGenerator.KEY_TYPE_PARAMS);
    parm = targs.get(0);
    Assert.assertEquals(SiteVariance.OUT.ordinal(), type.get(MetamodelGenerator.KEY_US_VARIANCE));
    Assert.assertEquals(SiteVariance.IN.ordinal(), parm.get(MetamodelGenerator.KEY_US_VARIANCE));
    // Typecheck phase2
    opts = options("src/test/resources/variance/phase2");
    tc = typeChecker(opts);
    Function m2 = (Function) tc.getPhasedUnits().getPhasedUnits().get(0).getPackage().getModule().getPackage("phase1").getDirectMember("m2", null, false);
    Assert.assertNotNull("phase1::m2 missing", m2);
    Assert.assertFalse("Missing variance overrides in return type", m2.getType().getVarianceOverrides().isEmpty());
    Assert.assertFalse("Missing variance overrides in parameter", m2.getFirstParameterList().getParameters().get(0).getType().getVarianceOverrides().isEmpty());
    jsc = new JsCompiler(tc, opts);
    jsc.generate();
    Assert.assertTrue("Should compile without errors", jsc.getErrors().isEmpty());
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) Function(org.eclipse.ceylon.model.typechecker.model.Function) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) List(java.util.List) File(java.io.File) Map(java.util.Map) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) Test(org.junit.Test)

Aggregations

JsCompiler (org.eclipse.ceylon.compiler.js.JsCompiler)7 Options (org.eclipse.ceylon.compiler.js.util.Options)7 TypeChecker (org.eclipse.ceylon.compiler.typechecker.TypeChecker)6 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)6 File (java.io.File)4 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3 JsModuleManagerFactory (org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 PrintWriter (java.io.PrintWriter)1 List (java.util.List)1 Map (java.util.Map)1 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)1 Function (org.eclipse.ceylon.model.typechecker.model.Function)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1