Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtext parser node
xtext parser node [message #638592] Thu, 11 November 2010 17:33 Go to next message
sungam  is currently offline sungam Friend
Messages: 21
Registered: March 2010
Junior Member
I have an ASTNode that has been loaded from a resource using a standalone setup.

After that, I have code that modifies the ASTNode in memory. (adding some model elements etc.)
I am trying to get the NodeAdapter for the modified ASTNode to obtain some parser node information.
But using the NodeUtil.getNodeAdapter(..) on the modified ASTNode, returns a null.

Is there anyway, I can reconstitute the parser composite node or obtain the node adapter of the modified ASTNode.

I have also tried to use SerializerUtil to serialize the modified ASTNode, but it throws some NPE.

Any ideas?
Thanks!
Re: xtext parser node [message #638705 is a reply to message #638592] Fri, 12 November 2010 09:39 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi,

you should not modify the node model directly but the semantic model
(which can be obtained by means of resource.getContents()). Afterwards
just call resource.save() and the serializer will jump in and recreate a
concrete syntax representation for your model.

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

Am 11.11.10 18:33, schrieb sungam:
> I have an ASTNode that has been loaded from a resource using a
> standalone setup.
>
> After that, I have code that modifies the ASTNode in memory. (adding
> some model elements etc.)
> I am trying to get the NodeAdapter for the modified ASTNode to obtain
> some parser node information.
> But using the NodeUtil.getNodeAdapter(..) on the modified ASTNode,
> returns a null.
>
> Is there anyway, I can reconstitute the parser composite node or obtain
> the node adapter of the modified ASTNode.
>
> I have also tried to use SerializerUtil to serialize the modified
> ASTNode, but it throws some NPE.
>
> Any ideas?
> Thanks!
Re: xtext parser node [message #638782 is a reply to message #638705] Fri, 12 November 2010 15:06 Go to previous messageGo to next message
sungam  is currently offline sungam Friend
Messages: 21
Registered: March 2010
Junior Member
So what I do is

1. resource.load(...)
2. result=resource.getParseResult
3. result.getRootASTElement

This EObject is then modified and sometimes even a new EObject is created by merging couple of others using the appropriate factory and ECoreUtil methods.

So essentially its the semantic model getting updated.

(i have also tried to replace the above code, to update on the resource.getContents(), which still has the same error)

Because sometimes a new EObject is created merging from few others, the getResource on the EObject returns a null.

So the have the below code instead, to invoke the serializer:
XtextResource resource = injector.getInstance(XtextResource.class);
String finalDsl = resource.getSerializer().serialize(eObject);

which fails with an exception:

Caused by: java.lang.NullPointerException
at org.eclipse.xtext.scoping.impl.DefaultScopeProvider$2.apply( DefaultScopeProvider.java:69)
at org.eclipse.xtext.scoping.impl.DefaultScopeProvider$2.apply( DefaultScopeProvider.java:67)
at org.eclipse.xtext.util.SimpleCache.get(SimpleCache.java:35)
at org.eclipse.xtext.scoping.impl.DefaultScopeProvider.getScope (DefaultScopeProvider.java:98)
at org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvi der$2.handle(AbstractDeclarativeScopeProvider.java:81)
at org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvi der$2.handle(AbstractDeclarativeScopeProvider.java:71)


Re: xtext parser node [message #639176 is a reply to message #638782] Mon, 15 November 2010 14:31 Go to previous messageGo to next message
sungam  is currently offline sungam Friend
Messages: 21
Registered: March 2010
Junior Member
Is this usecase out of scope for current xtext support?
Re: xtext parser node [message #639207 is a reply to message #639176] Mon, 15 November 2010 15:41 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Sungam,

this usecase is on the scope of the Xtext project. However, you should
not try to use an XtextResource without a ResourceSet. Please have a
look at the FAQ to learn how to use Xtext in a standalone environment.

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

Am 15.11.10 15:31, schrieb sungam:
> Is this usecase out of scope for current xtext support?
Re: xtext parser node [message #639271 is a reply to message #639207] Mon, 15 November 2010 19:43 Go to previous messageGo to next message
sungam  is currently offline sungam Friend
Messages: 21
Registered: March 2010
Junior Member
My code for loading the resource is:

XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, true);
Resource resource = resourceSet.createResource(URI.createURI("foo:/dummy.mydsl"));
resource.load(inputStream, resourceSet.getLoadOptions());

which is inline with the Xtext FAQ.

But after that, I recreate a new EObject node from the generated factories merging content from the loaded resource model.

1. MyModel myModelElement = (MyModel)resourceSet.getContents().get(0);
2. MyModel newModelElement = factory.MyDslFactory.eINSTANCE.createMyModel();
3. //here i add content to the 'newModelElement', using values from 'myModelElement'

How can I serialize it back, from the 'newModelElement'?

Re: xtext parser node [message #639375 is a reply to message #639271] Tue, 16 November 2010 10:09 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Have a look at
http://koehnlein.blogspot.com/2010/06/semantic-model-access- in-xtext.html
Am 15.11.10 20:43, schrieb sungam:
> My code for loading the resource is:
>
> XtextResourceSet resourceSet =
> injector.getInstance(XtextResourceSet.class);
> resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, true);
> Resource resource =
> resourceSet.createResource(URI.createURI("foo:/dummy.mydsl"));
> resource.load(inputStream, resourceSet.getLoadOptions());
>
> which is inline with the Xtext FAQ.
>
> But after that, I recreate a new EObject node from the generated
> factories merging content from the loaded resource model.
>
> 1. MyModel myModelElement = (MyModel)resourceSet.getContents().get(0);
> 2. MyModel newModelElement =
> factory.MyDslFactory.eINSTANCE.createMyModel();
> 3. //here i add content to the 'newModelElement', using values from
> 'myModelElement'
>
> How can I serialize it back, from the 'newModelElement'?
>
>


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


---
Get professional support from the Xtext committers at www.typefox.io
Re: xtext parser node [message #639462 is a reply to message #639375] Tue, 16 November 2010 16:28 Go to previous messageGo to next message
sungam  is currently offline sungam Friend
Messages: 21
Registered: March 2010
Junior Member
Thanks for the pointer.

I do not update the model from the editor/ui module, but rather to do some code generation.

What I really need is, if sometimes there are missing links, for elements modeled as cross-references,I need a way to determine what the ID of the missing cross reference is.
Well theres the NodeUtil to get the node adapter that leads me to the composite node.
But having recreated a new EObject, that is no longer accessible.
Re: xtext parser node [message #639872 is a reply to message #639462] Thu, 18 November 2010 08:42 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
The node model is created by the (partial) parser only, So you have to
serialize and reparse after the the model change. For your convenience,
this functionality is bundled in the IDocumentEditor.

Am 16.11.10 17:28, schrieb sungam:
> Thanks for the pointer.
>
> I do not update the model from the editor/ui module, but rather to do
> some code generation.
>
> What I really need is, if sometimes there are missing links, for
> elements modeled as cross-references,I need a way to determine what the
> ID of the missing cross reference is.
> Well theres the NodeUtil to get the node adapter that leads me to the
> composite node. But having recreated a new EObject, that is no longer
> accessible.


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


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Cross References & Strings
Next Topic:"Decision can match input such as "')'" using multiple alternatives: 1, 2"
Goto Forum:
  


Current Time: Thu Apr 25 05:00:48 GMT 2024

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

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

Back to the top