Search in sources :

Example 1 with MetamodelVisitor

use of org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor in project ceylon by eclipse.

the class TestModelAliases method initTests.

@SuppressWarnings("unchecked")
@BeforeClass
public static void initTests() {
    TestModelMethodsAndAttributes.initTypechecker();
    MetamodelVisitor mmg = null;
    for (PhasedUnit pu : TestModelMethodsAndAttributes.tc.getPhasedUnits().getPhasedUnits()) {
        if (pu.getPackage().getModule().getNameAsString().equals("t3")) {
            if (mmg == null) {
                mmg = new MetamodelVisitor(pu.getPackage().getModule());
            }
            pu.getCompilationUnit().visit(mmg);
        }
    }
    topLevelModel = mmg.getModel();
    model = (Map<String, Object>) topLevelModel.get("t3");
}
Also used : MetamodelVisitor(org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) BeforeClass(org.junit.BeforeClass)

Example 2 with MetamodelVisitor

use of org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor in project ceylon by eclipse.

the class Stitcher method encodeModel.

private static int encodeModel(final File moduleFile) throws IOException {
    final String name = moduleFile.getName();
    final File file = new File(moduleFile.getParentFile(), name.substring(0, name.length() - 3) + ArtifactContext.JS_MODEL);
    System.out.println("Generating language module compile-time model in JSON...");
    TypeCheckerBuilder tcb = new TypeCheckerBuilder().usageWarnings(false);
    tcb.addSrcDirectory(clSrcDir);
    TypeChecker tc = tcb.getTypeChecker();
    tc.process(true);
    MetamodelVisitor mmg = null;
    final ErrorCollectingVisitor errVisitor = new ErrorCollectingVisitor(tc);
    for (PhasedUnit pu : tc.getPhasedUnits().getPhasedUnits()) {
        pu.getCompilationUnit().visit(errVisitor);
        if (errVisitor.getErrorCount() > 0) {
            errVisitor.printErrors(false, false);
            System.out.println("errors in the language module " + pu.getCompilationUnit().getLocation());
            return 1;
        }
        if (mmg == null) {
            mmg = new MetamodelVisitor(pu.getPackage().getModule());
        }
        pu.getCompilationUnit().visit(mmg);
    }
    mod = tc.getPhasedUnits().getPhasedUnits().get(0).getPackage().getModule();
    try (FileWriter writer = new FileWriter(file)) {
        JsCompiler.beginWrapper(writer);
        writer.write("ex$.$CCMM$=");
        ModelEncoder.encodeModel(mmg.getModel(), writer);
        writer.write(";\n");
        final JsOutput jsout = new JsOutput(mod, true) {

            @Override
            public Writer getWriter() throws IOException {
                return writer;
            }
        };
        jsout.outputFile(new File(LANGMOD_JS_SRC, "MODEL.js"));
        JsCompiler.endWrapper(writer);
    } finally {
        ShaSigner.sign(file, new JsJULLogger(), true);
    }
    final File npmFile = new File(moduleFile.getParentFile(), ArtifactContext.NPM_DESCRIPTOR);
    try (FileWriter writer = new FileWriter(npmFile)) {
        String npmdesc = new NpmDescriptorGenerator(mod, true, false).generateDescriptor();
        writer.write(npmdesc);
    }
    return 0;
}
Also used : JsOutput(org.eclipse.ceylon.compiler.js.util.JsOutput) JsJULLogger(org.eclipse.ceylon.compiler.js.util.JsJULLogger) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) MetamodelVisitor(org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor) FileWriter(java.io.FileWriter) NpmDescriptorGenerator(org.eclipse.ceylon.compiler.js.util.NpmDescriptorGenerator) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)

Example 3 with MetamodelVisitor

use of org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor in project ceylon by eclipse.

the class TestModelClasses method initTests.

@SuppressWarnings("unchecked")
@BeforeClass
public static void initTests() {
    TestModelMethodsAndAttributes.initTypechecker();
    MetamodelVisitor mmg = null;
    for (PhasedUnit pu : TestModelMethodsAndAttributes.tc.getPhasedUnits().getPhasedUnits()) {
        if (pu.getPackage().getModule().getNameAsString().equals("t2")) {
            if (mmg == null) {
                mmg = new MetamodelVisitor(pu.getPackage().getModule());
            }
            pu.getCompilationUnit().visit(mmg);
        }
    }
    topLevelModel = mmg.getModel();
    model = (Map<String, Object>) topLevelModel.get("t2");
}
Also used : MetamodelVisitor(org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) BeforeClass(org.junit.BeforeClass)

Example 4 with MetamodelVisitor

use of org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor in project ceylon by eclipse.

the class TestModelMethodsAndAttributes method initModel.

@SuppressWarnings("unchecked")
@BeforeClass
public static void initModel() {
    initTypechecker();
    MetamodelVisitor mmg = null;
    for (PhasedUnit pu : tc.getPhasedUnits().getPhasedUnits()) {
        if (pu.getPackage().getModule().getNameAsString().equals("t1")) {
            if (mmg == null) {
                mmg = new MetamodelVisitor(pu.getPackage().getModule());
            }
            pu.getCompilationUnit().visit(mmg);
        }
    }
    topLevelModel = mmg.getModel();
    model = (Map<String, Object>) topLevelModel.get("t1");
}
Also used : MetamodelVisitor(org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) BeforeClass(org.junit.BeforeClass)

Aggregations

MetamodelVisitor (org.eclipse.ceylon.compiler.js.loader.MetamodelVisitor)4 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)4 BeforeClass (org.junit.BeforeClass)3 File (java.io.File)1 FileWriter (java.io.FileWriter)1 JsJULLogger (org.eclipse.ceylon.compiler.js.util.JsJULLogger)1 JsOutput (org.eclipse.ceylon.compiler.js.util.JsOutput)1 NpmDescriptorGenerator (org.eclipse.ceylon.compiler.js.util.NpmDescriptorGenerator)1 TypeChecker (org.eclipse.ceylon.compiler.typechecker.TypeChecker)1 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)1