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");
}
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;
}
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");
}
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");
}
Aggregations