[ATL] Preferred way of using the ATL2006 compiler in Java program [message #546649] |
Tue, 13 July 2010 12:20  |
Eclipse User |
|
|
|
Hello,
Since I still have problems with using the ATL compiler from a standalone java program my questions are the following:
1) Where can I get a proper version of the compiler.
2) Can I get a stand-alone (ie. outside eclipse) version?
3) Are there some examples on how to call this from Java?
Answering one of these questions can already tremendously help me.
|
|
|
Re: [ATL] Preferred way of using the ATL2006 compiler in Java program [message #546656 is a reply to message #546649] |
Tue, 13 July 2010 12:40   |
Eclipse User |
|
|
|
This is the code I use though it's not outside Eclipse so I don't know about the standalone mode.
We first inject the ATL file as an ATL Model using AtlParser and then AtlCompiler to get the ASM Model that we have to write to a file.
ByteArrayInputStream inputStream = new ByteArrayInputStream(yourATLString.getBytes());
EMFTCSInjector injector = new EMFTCSInjector();
Map params = new HashMap();
params.put("name","ATL");
params.put("indentString", " ");
params.put("identEsc", "\"");
params.put("stringDelim", "'");
params.put("serializeComments", "true");
EMFModel atlModel = null;
try {
atlModel = factory.newModel((EMFReferenceModel) factory.getBuiltInResource("ATL.ecore"), "atlModel");
} catch (ATLCoreException e1) {
e1.printStackTrace();
}
try {
EMFReferenceModel problemMetaModel = (EMFReferenceModel) factory.getBuiltInResource("Problem.ecore");
EMFModel problems = factory.newModel(problemMetaModel, "problemsModel");
params.put("problems", problems);
injector.inject(atlModel, inputStream, params);
OutputStream source = new ByteArrayOutputStream();
OutputStream result = new ByteArrayOutputStream();
AtlParser parser = new AtlParser();
parser.extract(atlModel, source, params);
AtlCompiler.compile(new ByteArrayInputStream(source.toString().getBytes()), result);
PrintWriter asmPrintWriter = new PrintWriter(location.substring(16, location.length())+"/transformation/"+model.getName()+"Copy.asm");
ASM asm = new ASMXMLReader().read(new ByteArrayInputStream(result.toString().getBytes()));
ASMXMLWriter txtWriter = new ASMXMLWriter(asmPrintWriter,false);
txtWriter.print(asm);
asmPrintWriter.flush();
asmPrintWriter.close();
} catch(Exception e){
e.printStackTrace();
}
Hope it helps
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04537 seconds