Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How can I get the corresponding GenClass of an EClass(I have an EClass an need its fqn for code generation.)
How can I get the corresponding GenClass of an EClass [message #1744752] Thu, 29 September 2016 22:38 Go to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
I have an EClass an need its fqn for code generation. The information I need is in the coresponding GenClass but there is no direkt link between the EClass and its GenClass. Are there utils to find the GenClass for an EClass ?
Re: How can I get the corresponding GenClass of an EClass [message #1744810 is a reply to message #1744752] Fri, 30 September 2016 11:24 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

(Ed M may give you a better answer.)

The key to the mapping is the registrations in EcorePlugin.ePackageNsURIToGenModelLocationMap. This populated automatically if you are running within Eclipse. You need to wind up the EcorePlugin.ExtensionProcessor if running standalone.

Regards

Ed Willink
Re: How can I get the corresponding GenClass of an EClass [message #1744860 is a reply to message #1744810] Fri, 30 September 2016 20:33 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
HI Ed,

thank you for this information, but I still don't know which methods I have to call to get from an EClass object to it's GenClass object.
Can you give me some more information on that ?

A small code example would be nice.
Re: How can I get the corresponding GenClass of an EClass [message #1744870 is a reply to message #1744860] Sat, 01 October 2016 06:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Sorry, I posted yesterday, but somehow it got lost. As the other Ed suggested, EcorePlugin.getEPackageNsURIToGenModelLocationMap(true) returns a map from nsURI to URI for the corresponding GenModel-containing resource. So given an EClass you can use eClass.getEPackage().getNsURI() to look up that EClass' GenModel's URI in that map. You can load that URI into your resource set (resourceSet.getResource(uri, true)), and use EcoreUtil.getObjectByType(resource.getContents(), GenModelPackage.Literals.GEN_MODEL) to fetch the GenModel from that loaded resource; I suggest this approach because the resource might actually be a *.xcore not just a *.genmodel, and in such a resource, the GenModel is not the first object in the contents. Then use GenModel.findEClassifier to find the corresponding GenClass in that GenModel for the eClass you started with.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How can I get the corresponding GenClass of an EClass [message #1744882 is a reply to message #1744870] Sat, 01 October 2016 09:56 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Thank you for the detailed description. Unfortunately I can not find the last function GenModel.findEClassifier. Can you give me more details on that function. In which class can I find this method ?
Re: How can I get the corresponding GenClass of an EClass [message #1744903 is a reply to message #1744882] Sun, 02 October 2016 07:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Sorry, typo, it's org.eclipse.emf.codegen.ecore.genmodel.GenModel.findGenClassifier(EClassifier)

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How can I get the corresponding GenClass of an EClass [message #1745071 is a reply to message #1744903] Tue, 04 October 2016 18:28 Go to previous message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Thank you, I made the following function from you information:
def getGenClassifier(EClassifier eClassifier) {
	val nsUri = eClassifier.EPackage?.nsURI
	val rs = eClassifier.eResource?.resourceSet
	if (nsUri != null && rs != null){
		val map = EcorePlugin.getEPackageNsURIToGenModelLocationMap(true)
		val gmUri = map.get(nsUri)
		val resource = rs.getResource(gmUri, true)
		val genModel = EcoreUtil.getObjectByType(resource.contents, GenModelPackage.Literals.GEN_MODEL) as GenModel
		genModel.findGenClassifier(eClassifier)
	}
}
Previous Topic:Parse part of file and ignore anything else
Next Topic:error EXPAND
Goto Forum:
  


Current Time: Wed Apr 24 19:02:47 GMT 2024

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

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

Back to the top