Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Model Access in Xtext
Model Access in Xtext [message #735769] Wed, 12 October 2011 17:04 Go to next message
vishal Mising name is currently offline vishal Mising nameFriend
Messages: 4
Registered: October 2011
Junior Member
Hi I am trying to insert a element in the semantic model of xtext.
My xtext grammar looks like this.
Model:
(element += Tag)+;

Tag returns Tag:
'tag' name=ID '{'
(tags += Tag)*
'}'
;

Now programmatically i am trying to add model element in this fashion.
IXtextDocument xtextDocument = .....;
xtextDocument.modify(new IUnitOfWork.Void<XtextResource>() {

@Override
public void process(XtextResource resource) throws Exception {
Model obj = (Model) resource.getContents().get(0);
EList<Tag> tags = obj.getElement();
Tag tagObj = TestFactory.eINSTANCE.createTag();
tags.add(tagObj);
}
});


When the model instance element is added in this fashion. New model element appears in the xtext editor, in the same line. i.e
before adding the model element :
Tag tag1 {

}
after adding the model element :
Tag tag1 {

}Tag tag2{}

I want the line feed to appear after the parenthesis.
Additionally the adapters are missing for the model. how can i add them.
Am i doing it in the wrong way ?
Re: Model Access in Xtext [message #735771 is a reply to message #735769] Wed, 12 October 2011 17:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

the first problem could be related to your formatter (you may have to customize it)
for the second: which adapters are missing?
~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 12 October 2011 17:15]

Report message to a moderator

Re: Model Access in Xtext [message #735805 is a reply to message #735771] Wed, 12 October 2011 18:58 Go to previous messageGo to next message
vishal Mising name is currently offline vishal Mising nameFriend
Messages: 4
Registered: October 2011
Junior Member
Hi,

If i see in debug mode the existing model element will have CompositeNodeWithSemanticElement as an Adapter for the model element. Which is not getting created when i create a model element programmitically. Do i have to call the parser once again after i add the model element.
Re: Model Access in Xtext [message #735952 is a reply to message #735805] Thu, 13 October 2011 07:55 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Which version of Xtext are you using?

In 1.x you have to use the DocumentEditor API to make sure your semantic
changes are properly transferred to the model and node model.

In 2.x, it should be enough to usie IXtextDocument.modify

In neither case you should call the parser yourself!


Am 12.10.11 20:58, schrieb vishal:
> Hi,
>
> If i see in debug mode the existing model element will have
> CompositeNodeWithSemanticElement as an Adapter for the model element.
> Which is not getting created when i create a model element
> programmitically. Do i have to call the parser once again after i add
> the model element.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Model Access in Xtext [message #739677 is a reply to message #735952] Mon, 17 October 2011 18:32 Go to previous messageGo to next message
vishal Mising name is currently offline vishal Mising nameFriend
Messages: 4
Registered: October 2011
Junior Member
Hi ,

I am using 2.x version of xtext
Re: Model Access in Xtext [message #832888 is a reply to message #739677] Fri, 30 March 2012 18:17 Go to previous messageGo to next message
Heinrich Müller is currently offline Heinrich MüllerFriend
Messages: 10
Registered: March 2012
Junior Member
Does anyone know in which release of xtext this functionality here was
applied ? : eclipse.org/forums/index.php/mv/tree/152822/
Re: Model Access in Xtext [message #832916 is a reply to message #832888] Fri, 30 March 2012 18:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

from the age of the posting it should be 0.7.x

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Model Access in Xtext [message #837537 is a reply to message #832916] Thu, 05 April 2012 20:06 Go to previous message
Heinrich Müller is currently offline Heinrich MüllerFriend
Messages: 10
Registered: March 2012
Junior Member
Thanks.
Previous Topic:Comment pretty-printing
Next Topic:Making an editor with xtext for an existing DSL (Robot Framework)
Goto Forum:
  


Current Time: Thu Sep 26 08:10:34 GMT 2024

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

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

Back to the top