Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Accessing attributes in different resources(How to traverse an inheritance hierarchy)
Accessing attributes in different resources [message #1553045] Thu, 08 January 2015 13:16 Go to next message
Andreas  Flügge is currently offline Andreas FlüggeFriend
Messages: 26
Registered: July 2009
Junior Member
The following grammar allows to declare an inheritance hierarchy of entities:

grammar myDSL with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations
	
...

Entity:
	'entity' (name = ID) ('extends' superType = JvmTypeReference)? '{'
		...
		(attribs += Attribute)*;
		...
	'}';
	
...

While code generation for an Entity there is the need to examine if a special attribute exist in one of the superclasses (entities).

So how can I traverse these structure (superclass is a different resource, JvmTypeReference isnt't an 'Entity')?
Is this a matter of scope, model inferrer or something else? Is there a best practice / some examples?

Thanks for any help,
Andreas
Re: Accessing attributes in different resources [message #1553076 is a reply to message #1553045] Thu, 08 January 2015 13:37 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

In the case that you have to traverse to the Entity referenced by the superType relationship, you can inject IJvmModelAssociations and use getPrimarySourceElement. But as super type, any Java type would be allowed here, and the method will return null for this case.

The IJvmModelAssociations can be used as long as it is expected that the referenced element originates from the one language. In the case that multiple DSLs are used, the language specific model associations have to be retrieved like this:
		val type = ref.type
		val modelAssociations = (type.eResource as XtextResource).resourceServiceProvider.get(IJvmModelAssociations)
		
		val sourceElem = modelAssociations.getPrimarySourceElement(ref.type)

(this won't be you case)

HTH,
~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Accessing attributes in different resources [message #1553180 is a reply to message #1553076] Thu, 08 January 2015 14:51 Go to previous messageGo to next message
Andreas  Flügge is currently offline Andreas FlüggeFriend
Messages: 26
Registered: July 2009
Junior Member
Thank you very much, that's exactly what I've been looking for!

Great support!

Best regards,
Andreas
Re: Accessing attributes in different resources [message #1712710 is a reply to message #1553180] Tue, 27 October 2015 15:19 Go to previous message
Andreas  Flügge is currently offline Andreas FlüggeFriend
Messages: 26
Registered: July 2009
Junior Member
This seems to work only for super classes (entities)!? Is it possible to access arbitrary entities in a different resource/file?

Thanks,
Andreas
Previous Topic:Xtext performance Issue on serialization
Next Topic:disable implicit return in Xbase
Goto Forum:
  


Current Time: Fri Apr 26 23:22:15 GMT 2024

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

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

Back to the top