Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Accessing Code behind Model
Accessing Code behind Model [message #1777693] Fri, 01 December 2017 15:59 Go to next message
Oliver Blasius is currently offline Oliver BlasiusFriend
Messages: 2
Registered: December 2017
Junior Member
Hello there,

I am using the xText embedded Editor and want to access the "source code" behind the model.

I access the generated model with this code:

Testfile res = editor.getDocument().readOnly(new IUnitOfWork<Testfile, XtextResource>() {
			@Override
			public Testfile exec(XtextResource resource) throws Exception {
				return EcoreUtil.copy((Testfile) resource.getContents().get(0));
			}
		});


My attempt to get the text behind a model element failed, because the returned node is always null:
ICompositeNode node = NodeModelUtils.getNode(step);
String code = NodeModelUtils.getTokenText(node);

How can I get the text behind the model element?
Re: Accessing Code behind Model [message #1777784 is a reply to message #1777693] Mon, 04 December 2017 15:54 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11617
Registered: July 2009
Senior Member
you can directly can call INode.getText()

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Accessing Code behind Model [message #1777786 is a reply to message #1777784] Mon, 04 December 2017 15:56 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11617
Registered: July 2009
Senior Member
besides this the question would be why is node null?
of course you should not return eobjects from the readOnly methods.
but i have no clear view of what you are doing


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Accessing Code behind Model [message #1777835 is a reply to message #1777786] Tue, 05 December 2017 08:22 Go to previous messageGo to next message
Oliver Blasius is currently offline Oliver BlasiusFriend
Messages: 2
Registered: December 2017
Junior Member
your answer already helped me.
The error was that I was returning a copy of the model with EcoreUtil.copy
Now I am returning the model directly.
Testfile res = editor.getDocument().readOnly(new IUnitOfWork<Testfile, XtextResource>() {
			@Override
			public Testfile exec(XtextResource resource) throws Exception {
				return ((Testfile) resource.getContents().get(0));
			}
		});


But what do you mean with Quote:
of course you should not return eobjects from the readOnly methods.
?
I only need to read the model. I dont want to modify anything.
Re: Accessing Code behind Model [message #1777838 is a reply to message #1777835] Tue, 05 December 2017 08:51 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11617
Registered: July 2009
Senior Member
no you need to do all calculation inside the readonly.

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Previous Topic:Trying to generate DSL files using Java
Next Topic:Formatting list of strings?
Goto Forum:
  


Current Time: Mon Jan 22 10:40:33 GMT 2018

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

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