Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Meshing ACCELEO and Xtext
Meshing ACCELEO and Xtext [message #901948] Wed, 15 August 2012 05:08 Go to previous message
Andrea Sindico is currently offline Andrea Sindico
Messages: 250
Registered: November 2010
Senior Member

I am in the middle of an ACCELEO Transformation aimed at producing code (i.e. Java) from an input UML model.

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.

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 http://www.eclipse.org/forums/index.php/m/901947/#msg_901947 for further details). I have tested it in a separate Java application and it seems it works properly.

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.

Suppose my DSL (and the equivalent ECORE) consist of a root element named DSLModel containing a (0..*) number of DSLStatements (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 ModelImpl

['statement1;statement2'.getDSLModel()/]

so the Java service and the XText parse is working.

However if I try to get the model statements, i.e.:

['statement1;statement2'.getDSLModel().statements/]

it returns an **"invalid"** string. So I can't use it in a for loop

I have therefore tried to call the eAllContents() ocl service from the model instance i.e.:

['statement1;statement2'.getDSLModel().eAllContents()/]

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.

Any help would be very appreciated! Thank you



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!

     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;
		
	}
	
    }


Now I need the AST in the main ACCELEO (UML2Text) transformation thus here is the Acceleo wrapper


     [query public getDSLModel(str:String): DSLModel =  (invoke('sfg.baleno.src.mloaders.GetDSLModel','getDSLModel(java.lang.String)',Sequence{str})).oclAsType(DSLModel)/]



here is what I get if run it
      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 (......


Follow me on Twitter @andreasindico

[Updated on: Wed, 15 August 2012 12:15]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic:Acceleo meta-model as namespace
Next Topic:[Acceleo] retrieving the ResourceSet from a Java service
Goto Forum:
  


Current Time: Sat May 18 23:43:35 EDT 2013

Powered by FUDForum. Page generated in 0.01831 seconds