Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Re: Acceleo and Xtext
Re: Acceleo and Xtext [message #902540] Sat, 18 August 2012 09:49 Go to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You have been asking this question for some time on the M2T mailing
list, which is where it belongs.

However you just provide us parts of your program without any indication
how you invoke them.

The more partial information you provide the less attractive it is to
try to help you.

As Christian demonstrated, the basic functionality work fine, so
somewhere you are doing something odd, and you have not told us about it.

If you want help, you need to help yourself, by helping us. Provide a
simple zipped project and launch configuration that demonstrates the
problem. Do not provide snippets that require us to spend time
mis-re-developing what you have failed to provide.

Regards

Ed Willink


On 18/08/2012 09:44, Andrea Sindico wrote:
> 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: mailto:mypackage.dsl.impl.DSLModelImpl@a1c7a
>
> input: ['statement1;statement2'.getDSLModel().statements/]
> (Syntactically VALID)
> output: invalid
>
> input: ['statement1;statement2'.getDSLModel().eAllContents()/]
> output: mailto:mypackage.dsl.impl.DSLStatement@e53202 (......
>
> Some hours later
>
> In the Java Class of the main ACCELEO module I have added the
> following lines
>
> @Override
> public void initialize(EObject element, File folder,
> java.util.List<? extends Object> arguments) throws IOException {
> preInitialize();
> super.initialize(element, folder, arguments);
> }
> @Override
> public void initialize(URI modelURI, File folder, java.util.List<?>
> arguments) throws IOException {
> preInitialize();
> super.initialize(modelURI, folder, arguments);
> }
> protected void preInitialize() {
> DSLStandaloneSetup.doSetup();
> }
>
> and
>
> @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);
> }
>
> but it still behaves the same.
> Is there anyone who managed to use Xtext with Acceleo this way?
>
>
Re: Acceleo and Xtext [message #902910 is a reply to message #902540] Tue, 21 August 2012 06:28 Go to previous messageGo to next message
Andrea Sindico is currently offline Andrea SindicoFriend
Messages: 266
Registered: November 2010
Senior Member

Hi Ed as it concerns both Acceleo and Xtext I thought it was a good idea to post it in both the forums. At this link https://docs.google.com/open?id=0B2_ovo8IiZaZaXdNdFdPMTI4Yjg you find a zipped workspace containing both the Acceleo and the Xtext project plus a launchMe.launch configuration you can use to run the ACceleo transformation.

If you run it as an acceleo application (The launchMe.launch) you get this output:

UML
test1: Class1

DSL
test1: org.xtext.example.mydsl.myDsl.impl.ModelImpl@1ae6ee8
test2: invalid


while if you run it as a Java application you get the right output:

UML
test1: Class1

DSL
test1: org.xtext.example.mydsl.myDsl.impl.ModelImpl@598fffdd
test2: org.xtext.example.mydsl.myDsl.impl.GreetingImpl@2f0dd706 (name: tester)
tester


Thank you for your help.


Follow me on Twitter @andreasindico

[Updated on: Tue, 21 August 2012 06:29]

Report message to a moderator

Re: Acceleo and Xtext [message #903007 is a reply to message #902910] Tue, 21 August 2012 15:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If it works one way and not the other, it is almost certainly an Acceleo
launcher issue rather than an OCL issue; but as I noted earlier, I find
the Acceleo application launch either useless or worse (it locks my
Eclipse up).

Now that the French holiday season is coming to an end, you may get a
response from one of the Acceleo guys.

Since you have a good repro, I suggest you file a bug against Acceleo.

Regards

Ed Willink




On 21/08/2012 07:28, Andrea Sindico wrote:
> Hi Ed as it concerns both Acceleo and Xtext I thought it was a good
> idea to post it in both the forums. At this link
> https://docs.google.com/open?id=0B2_ovo8IiZaZaXdNdFdPMTI4Yjg you find
> a zipped workspace containing both the Acceleo and the Xtext project
> plus a launchMe.launch configuration you can use to run the ACceleo
> transformation.
> If you run it as an acceleo application (The launchMe.launch) you get
> this output:
>
>
> UML
> test1: Class1
>
> DSL
> test1: org.xtext.example.mydsl.myDsl.impl.ModelImpl@1ae6ee8
> test2: invalid
>
>
> while if you run it as a Java application you get the right output:
>
>
> UML
> test1: Class1
>
> DSL
> test1: org.xtext.example.mydsl.myDsl.impl.ModelImpl@598fffdd
> test2: org.xtext.example.mydsl.myDsl.impl.GreetingImpl@2f0dd706 (name:
> tester)
> tester
>
>
> Thank you for your help.
Re: Acceleo and Xtext [message #903132 is a reply to message #903007] Wed, 22 August 2012 07:42 Go to previous messageGo to next message
Andrea Sindico is currently offline Andrea SindicoFriend
Messages: 266
Registered: November 2010
Senior Member

Hi Ed, I also noticed that when executed as a Java Application it behaves differently for what concerns PrimitiveTypes (see http://www.eclipse.org/forums/index.php/t/369811/). Have you ever experienced something like that? am I missing something in the related launch configuration? (... continue on the related post)

Follow me on Twitter @andreasindico

Re: Acceleo and Xtext [message #903167 is a reply to message #903132] Wed, 22 August 2012 11:12 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

My requirements are particularly challenging. I am using Acceleo as a
code generator for development OCL meta-models while Acceleo is using
production OCL meta-models as part of its functionality. I therefore
stress the namespace resolution very hard, and find the odd problem or two.

So yes, I have seen many strange things happening with PrimitiveTypes
(just look at the Acceleo Bugzillas I have raised.)

Regards

Ed Willink

On 22/08/2012 08:42, Andrea Sindico wrote:
> Hi Ed, I also noticed that when executed as a Java Application it
> behaves differently for what concerns PrimitiveTypes (see
> http://www.eclipse.org/forums/index.php/t/369811/). Have you ever
> experienced something like that? am I missing something in the related
> launch configuration? (... continue on the related post)
Previous Topic:[Acceleo] retrieving the ResourceSet from a Java service
Next Topic:[XPAND] Cast Exception when opening XPAND File
Goto Forum:
  


Current Time: Fri Apr 19 23:08:58 GMT 2024

Powered by FUDForum. Page generated in 0.02883 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top