use of org.eclipse.xtext.xbase.compiler.JvmModelGenerator in project xtext-xtend by eclipse.
the class TestCaseCompiler method compile.
public void compile(String qualifiedName) throws IOException {
ResourceSet set = injector.getInstance(ResourceSet.class);
final String from = "src/" + qualifiedName.replace('.', '/') + ".xtend";
final String to = "src-gen/" + qualifiedName.replace('.', '/') + ".java";
Resource res = set.getResource(org.eclipse.emf.common.util.URI.createFileURI(from), true);
EcoreUtil.resolveAll(res);
if (!res.getErrors().isEmpty())
throw new RuntimeException(res.getErrors().toString());
final File file = new File(to);
createFolders(file);
FileWriter writer = new FileWriter(file);
IXtendJvmAssociations associations = injector.getInstance(IXtendJvmAssociations.class);
JvmModelGenerator generator = injector.getInstance(JvmModelGenerator.class);
XtendFile xtendFile = (XtendFile) res.getContents().get(0);
JvmGenericType inferredType = associations.getInferredType((XtendClass) xtendFile.getXtendTypes().get(0));
GeneratorConfig config = injector.getInstance(IGeneratorConfigProvider.class).get(inferredType);
CharSequence javaCode = generator.generateType(inferredType, config);
writer.append(javaCode);
writer.close();
System.out.println("compiled " + from + " to " + to);
}
Aggregations