Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Associating data with EMF model
Associating data with EMF model [message #1787372] Thu, 24 May 2018 08:22 Go to next message
Alex Mising name is currently offline Alex Mising nameFriend
Messages: 148
Registered: March 2010
Senior Member
Hello all,

Another one in my series of basic questions:

I understand that xtext generates a model based on my grammar (see model/generatoed/{x}.ecore

I would like to be able to associate extra data with some elements. For instance, the generated type for Field is:

  <eClassifiers xsi:type="ecore:EClass" name="Field">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="presence" eType="ecore:EDataType"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="fieldEncodingType" eType="#//TypeDeclaration"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="id" eType="ecore:EDataType"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="semanticType" eType="#//SemanitTypeModifier"

Now, I want to add an integer called "offset"

    <eStructuralFeatures xsi:type="ecore:EAttribute" name="offset" eType="ecore:EDataType"/>

Is it possible to instruct xtext to do that during some post-processing of the model?

Please note that I understand the obvious: I could just change the grammar to include that attribute "(offset=INT)?", just wondering if there's a way to do this without cluttering the grammar: I really don't mean to give the option for a user of the grammar to type that extra integer as it makes no sense.
Re: Associating data with EMF model [message #1787373 is a reply to message #1787372] Thu, 24 May 2018 08:27 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Just do not generate the ecore model from your grammar, manually maintain it and import it in your grammar.

Additional state can be derived using the IDerivedStateComputer interface together with an DerivedStateAwareResource. Use the Guice modules to bind the customizations.
Previous Topic:Release of Xtext and Xtend 2.14.0
Next Topic:inconsistency of case sensitivity in xtext suffix
Goto Forum:

Current Time: Fri Jul 01 12:00:18 GMT 2022

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

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

Back to the top