Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Customizing Xtext Model
Customizing Xtext Model [message #1152938] Thu, 24 October 2013 09:08 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hello everynone,
I want to set some default values for some modelelements of my Xtext-Model. But it is not possible within the xtext-grammer file. I read something about a IXtext2EcorePostProcessor here and wanted to know, if it is still the best way to do it.

Here the link to the introduced method:
http://christiandietrich.wordpress.com/2011/07/22/customizing-xtext-metamodel-inference-using-xtend2/

My special case is the following:
- I'm importing the UML2-Metamodel and create a Xtext-Grammer for a subset of this metamodel (Classdiagrams)
- Now I want to set some properties by default, so the created Xtext-Model (instance of the UML2-Metamodel) is valid

Does someone has any experiences with this topic?

Regards,
Alex
Re: Customizing Xtext Model [message #1152956 is a reply to message #1152938] Thu, 24 October 2013 09:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13667
Registered: July 2009
Senior Member
Hi,

did you have a look at AbstractCleaningLinker.afterModelLinked
(I dont know if this is the best place)
~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customizing Xtext Model [message #1152967 is a reply to message #1152956] Thu, 24 October 2013 09:33 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,
No I didn't look at AbstractCleaningLinker.afterModelLinked yet, but I will do it.
Is it a bad idea to set some default values programmatically by accesing the xtext-model via a XtextResoure?

Like this way:
//set name of the model (root element)
((Model) xtextResource.getContents().get(0)).setName("defaultModelName");


I could just do this in the .ui-plugin before serializing the model.

Alex
Re: Customizing Xtext Model [message #1152984 is a reply to message #1152967] Thu, 24 October 2013 09:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13667
Registered: July 2009
Senior Member
Hi,
give it a try. dont know if this will have side effects.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customizing Xtext Model [message #1173576 is a reply to message #1152984] Wed, 06 November 2013 16:11 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,

what do you think is the better procedure for setting some default values and references to modelelements.
1.Extend a Linker (like explained here: http://www.eclipse.org/forums/index.php/m/29585/?srch=stereotype+in+model#msg_29585)
public class MyLinker extends Linker {

	@Inject
	private CdalfGrammarAccess grammarAccess;
        @Override
	public void ensureLinked(EObject obj, IDiagnosticProducer producer) {
		super.ensureLinked(obj, producer); 
		if (obj instanceof SomeElements) {
			SomeElementsasso = (SomeElements) obj;
			// set default attributes
			
			
		}
	}

2. To extend AbstractCleaningLinker
And overriding the afterModelLinked -method?

~Alex
Re: Customizing Xtext Model [message #1173748 is a reply to message #1173576] Wed, 06 November 2013 18:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13667
Registered: July 2009
Senior Member
Hi

i think the second one is better.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Customizing Xtext Model [message #1174797 is a reply to message #1173748] Thu, 07 November 2013 10:14 Go to previous message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,

but when I override the afterModelLinked(model, diagnosticsConsumer); I have to iterate the whole model to find the necessary element I'm looking for. So
this might be quick complicated if a model is complex.

Or am I wrong?
~Alex
Previous Topic:[Xtext/Xtend] Issue when calling xtext generator from a context menu
Next Topic:Generic DSL based on POJO
Goto Forum:
  


Current Time: Fri Dec 04 08:56:14 GMT 2020

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

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

Back to the top