Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [acceleo] Find the root element
[acceleo] Find the root element [message #1798686] Thu, 22 November 2018 16:59 Go to next message
Shimon Zadok is currently offline Shimon ZadokFriend
Messages: 24
Registered: May 2016
Junior Member
Hi Guys,

Does anyone knows how to to retrieve the root element in the current model or even find it by a certain criteria?
That find could be called any where in the 'mtl' files...

Thanks for any help :-)

This would allow me to calculate the 'include/import' path for library beginning with the root element down to the class.
Re: [acceleo] Find the root element [message #1798692 is a reply to message #1798686] Thu, 22 November 2018 21:14 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6457
Registered: July 2009
Senior Member
Hi

The root element is the element for which eContainer() is null. EcoreUtil.getRootContainer solves the problem in Java. You could invoke it from Acceleo or recode as a query. Have you checked the Acceleo documentation? it is the kind of thing that the developers added to the library.

Regards

Ed Willink
Re: [acceleo] Find the root element [message #1798724 is a reply to message #1798692] Fri, 23 November 2018 10:07 Go to previous messageGo to next message
Shimon Zadok is currently offline Shimon ZadokFriend
Messages: 24
Registered: May 2016
Junior Member
Thanks for the help and in need of new direction.

EcoreUtil.getRootContainer(Package) gives: "org.eclipse.uml2.uml.internal.impl.UMLPackageImpl@75cd8043 (name: uml) (nsURI: http://www.eclipse.org/uml2/5.0.0/UML, nsPrefix: uml)".

How could I use 'EcoreUtil.getRootContainer(Package)'?

I think I need to give structure example of my model as it seems I have multiple root elements and I need the "executed" model's root element.

My model structure is as follows:

common
framework
app1 app2 etc...

'common' contains some model and profiles (which are root elements to my objects)
In 'framework' I have a package 'Lib' with PackageMerge of those objects needed.
In 'app1' I have a new instance of 'Lib' with PackageMerge of those objects needed too...

Then my root element I search for is not in 'common' model, but in the 'app1' model.

[Updated on: Fri, 23 November 2018 10:27]

Report message to a moderator

Re: [acceleo] Find the root element [message #1798726 is a reply to message #1798724] Fri, 23 November 2018 10:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6457
Registered: July 2009
Senior Member
Hi

Read the documentation on invoke that may be used to call arbitrary Java operations. Beware getting the declarations right is tricky and there is limited helpful diagnosis, so start with a simple example.

Regards

Ed Willink
Re: [acceleo] Find the root element [message #1798731 is a reply to message #1798726] Fri, 23 November 2018 11:54 Go to previous messageGo to next message
Shimon Zadok is currently offline Shimon ZadokFriend
Messages: 24
Registered: May 2016
Junior Member
Oh, I appologize, I do know how to use Java operation from Acceleo :-)

I added the output of the new query (using invoke) with the suggested call as follows:

[query public getRootContainer(aType : OclType) : Sequence(OclType)
	= invoke('org.eclipse.emf.ecore.util.EcoreUtil', 'getRootContainer(org.eclipse.emf.ecore.EObject)', Sequence{aType})
/]


Please notice that it didn't give me an actual 'root element' but the:
getRootContainer: "org.eclipse.uml2.uml.internal.impl.UMLPackageImpl@75cd8043 (name: uml) (nsURI: http://www.eclipse.org/uml2/5.0.0/UML, nsPrefix: uml)"

which is not any of my root elements but seems like the namespace of the UML2 in use by the
[module generate('http://www.eclipse.org/uml2/5.0.0/UML')]

Re: [acceleo] Find the root element [message #1798733 is a reply to message #1798731] Fri, 23 November 2018 12:05 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6457
Registered: July 2009
Senior Member
Hi

Like I said. It's hard to get right. Us a debugger to seed why you have a bug.

Regards

Ed Willink
Previous Topic:programmatically check if the generation Was successfull
Next Topic:[Acceleo] Java service wrapper problem/reflection
Goto Forum:
  


Current Time: Tue Sep 17 17:17:00 GMT 2019

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

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

Back to the top