Note that there are some explanatory texts on larger screens.

plurals
  1. POMeshing Acceleo with Xtext
    primarykey
    data
    text
    <p>I am in the middle of an Acceleo Transformation aimed at producing code (i.e. Java) from an input UML model. </p> <p>Some elements of this UML model (i.e. Activities Opaque actions) contain some text which is conform to an Xtext grammar and I'd like to get the equivalent AST Ecore representation in the Acceleo transformation. </p> <p>To this end I have developed a Java class with a method which takes as input a string, containing the DSL excerpt, and produces an Ecore model conform to it (see <a href="http://www.eclipse.org/forums/index.php/m/901947/#msg_901947" rel="nofollow">http://www.eclipse.org/forums/index.php/m/901947/#msg_901947</a> for further details). I have tested it in a separate Java application and it seems it works properly.</p> <p>I have therefore written a simple Acceleo module (i.e. getDSLModel) wrapping that java class and enabling me to get the Ecore model from the DSL textual representation.</p> <p>Suppose my DSL (and the equivalent Ecore) consist of a root element named <code>DSLModel</code> containing a (0..*) number of <code>DSLStatement</code>s (this is a simplification). When in Acceleo I invoke the wrapper from a string, containing a correct DSL script, I have noticed it correctly returns a <code>ModelImpl</code>.</p> <pre class="lang-java prettyprint-override"><code> ['statement1;statement2'.getDSLModel()/] </code></pre> <p>so the Java service and the Xtext parse is working. </p> <p>However if I try to get the model statements, i.e.:</p> <pre class="lang-java prettyprint-override"><code> ['statement1;statement2'.getDSLModel().statements/] </code></pre> <p>it returns an <strong>"invalid"</strong> string. So I can't use it in a for loop</p> <p>I have therefore tried to call the eAllContents() OCL service from the model instance i.e.:</p> <pre class="lang-java prettyprint-override"><code> ['statement1;statement2'.getDSLModel().eAllContents()/] </code></pre> <p>and it actually returns the list of statements. I do not understand why the features of the Ecore entities returned from the Xtext parser are not working properly. </p> <hr> <p>Here is the Java service which turns a string into a instance of my DSL model (Ecore AST). I have tested it with an independent Java application and it works fine!</p> <pre class="lang-java prettyprint-override"><code> public class GetDSLModel { public DSLModel getDSLModel(String expression){ DSLStandaloneSetupGenerated dslsas = new DSLStandaloneSetupGenerated(); Injector injector = dslsas.createInjectorAndDoEMFRegistration(); XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); Resource resource = resourceSet.createResource(URI.createURI("dummy:/example.dsl")); InputStream in = new ByteArrayInputStream(expression.getBytes()); try { resource.load(in, resourceSet.getLoadOptions()); DSLModel model = (DSLModel) resource.getContents().get(0); return model; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } } </code></pre> <p>Now I need the AST in the main Acceleo (UML2Text) transformation thus here is the Acceleo wrapper</p> <pre class="lang-java prettyprint-override"><code> [query public getDSLModel(str:String): DSLModel = (invoke('sfg.baleno.src.mloaders.GetDSLModel','getDSLModel(java.lang.String)',Sequence{str})).oclAsType(DSLModel)/] </code></pre> <p>here is what I get if run it </p> <pre class="lang-java prettyprint-override"><code> input: ['statement1;statement2'.getDSLModel()/] output: mypackage.dsl.impl.DSLModelImpl@a1c7a input: ['statement1;statement2'.getDSLModel().statements/] (Syntactically VALID) output: invalid input: ['statement1;statement2'.getDSLModel().eAllContents()/] output: mypackage.dsl.impl.DSLStatement@e53202 (...... </code></pre> <p><strong>UPDATE</strong></p> <p>To the Java Class of the main Acceleo module I have added the following lines</p> <pre class="lang-java prettyprint-override"><code> @Override public void initialize(EObject element, File folder, java.util.List&lt;? extends Object&gt; arguments) throws IOException { preInitialize(); super.initialize(element, folder, arguments); } @Override public void initialize(URI modelURI, File folder, java.util.List&lt;?&gt; arguments) throws IOException { preInitialize(); super.initialize(modelURI, folder, arguments); } protected void preInitialize() { DSLStandaloneSetup.doSetup(); } </code></pre> <p>and</p> <pre class="lang-java prettyprint-override"><code> @Override public void registerPackages(ResourceSet resourceSet) { super.registerPackages(resourceSet); if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) { resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE); } if (!isInWorkspace(mypackages.DSLPackage.class)) { resourceSet.getPackageRegistry().put(mypackages.DSLPackage.eINSTANCE.getNsURI(), mypackages.DSLPackage.eINSTANCE); } EcoreUtil.resolveAll(resourceSet); } </code></pre> <p>but it still behaves the same.</p> <p><strong>UPDATE</strong></p> <p>At this link you <strong>temporary</strong> find a zipped file of an example EMF workspace containing an Acceleo and a XText project reproducing the issue. The weird thing is that if you run it as a Java application it works but if you run it as an Acceleo application it does not...</p> <p><a href="https://docs.google.com/open?id=0B2_ovo8IiZaZaXdNdFdPMTI4Yjg" rel="nofollow">https://docs.google.com/open?id=0B2_ovo8IiZaZaXdNdFdPMTI4Yjg</a> </p> <p>In the top left corner you should find a File menu from which you can download the zip file.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload