Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Customizing Xtext Model
Customizing Xtext Model [message #1152938] Thu, 24 October 2013 05:08 Go to next message
Eclipse UserFriend
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 05:25 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

did you have a look at AbstractCleaningLinker.afterModelLinked
(I dont know if this is the best place)
~Christian
Re: Customizing Xtext Model [message #1152967 is a reply to message #1152956] Thu, 24 October 2013 05:33 Go to previous messageGo to next message
Eclipse UserFriend
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 05:48 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
give it a try. dont know if this will have side effects.
Re: Customizing Xtext Model [message #1173576 is a reply to message #1152984] Wed, 06 November 2013 11:11 Go to previous messageGo to next message
Eclipse UserFriend
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 13:37 Go to previous messageGo to next message
Eclipse UserFriend
Hi

i think the second one is better.
Re: Customizing Xtext Model [message #1174797 is a reply to message #1173748] Thu, 07 November 2013 05:14 Go to previous message
Eclipse UserFriend
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: Wed Jul 02 09:14:13 EDT 2025

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

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

Back to the top