Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Replace object after linking
Replace object after linking [message #1142083] Thu, 17 October 2013 11:37 Go to next message
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
Hi!

I have a DSL which accepts textual specifications like

param1 a = n
param2 b = X
a + b


There are two types T1 and T2 where T1 represents ("param1 a = n") and T2 represents ("param2 b = X").
Both types have a common super type S, but different attribute / references feature names.
An expression like "a + b" has atoms which are of types "RefToT1" resp. "RefToT2"
representing references to the types T1 resp. T2.

Note that "a" and "b" in the expression "a + b" are both IDs and thus can not be distinguished while parsing. For both "a" and "b" the types "RefToT2" are created! This cannot be changed in the Xtext DSL specification (due to grammar extensions).

What I want to do is to change objects with type "RefToT2" to an objecet "RefToT1" dependent on some context of the object.
For this reason, I think that the right place to hook is the LazyLinker.
There are three methods "beforeModelLinked", "doLinkModel" and "afterModelLinked".
"beforeModelLinked" is too early, since the reference features of "RefToT1" and "RefToT2" are not yet set (in order to get the information for creating a right "RefToT1" object).
I tried to modify "doLinkModel" and "afterLinkModel", by creating for a "RefToT2" object a new "RefToT1" object (feeding its attributes) and finally call EcoreUtil.replace(...) in order to replace the "RefToT2" object with the newly created "RefToT1" object.

Doing this I get the following exception while editing:

First I get a windows showing:
'Xtext validation' has encountered a problem.
An internal error occurred during: "Xtext validation".
java.lang.IllegalStateException: Couldn't resolve lazy link, because no node model is attached.

And the exception trace is:
2 [Worker-2] ERROR org.eclipse.xtext.linking.lazy.LazyLinkingResource - resolution of uriFragment 'xtextLink_::0.1.0.4.9.0.1.1::2::/2' failed.
java.lang.IllegalStateException: Couldn't resolve lazy link, because no node model is attached.
at org.eclipse.xtext.linking.lazy.LazyURIEncoder.decode(LazyURIEncoder.java:93)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:204)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doResolveLazyCrossReference(LazyLinkingResource.java:172)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReference(LazyLinkingResource.java:131)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReferences(LazyLinkingResource.java:117)
at org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences(EcoreUtil2.java:511)
at org.eclipse.xtext.validation.ResourceValidatorImpl.resolveProxies(ResourceValidatorImpl.java:155)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:68)
at org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:79)
at org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:1)
at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.readOnly(AbstractReadWriteAcces.java:62)
at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.readOnly(XtextDocument.java:246)
at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:84)
at org.eclipse.xtext.ui.editor.validation.ValidationJob.createIssues(ValidationJob.java:75)
at org.eclipse.xtext.ui.editor.validation.ValidationJob.run(ValidationJob.java:64)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)



Do you know any solution for my problem? Or shall I hook somewhere else?

Best regards,
Alex.
Re: Replace object after linking [message #1143438 is a reply to message #1142083] Fri, 18 October 2013 07:24 Go to previous messageGo to next message
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
I think I can simplify my concern a little bit:

When my textual model is parsed (i.e. a node model is created) and linked (the semantic model is created), I want to perform a small in-place transformation on some objects from the semantic model.
I'm hooking in the LazyLinker.afterModelLinked() and define the transformation as follows:
Define a new object and call Ecore.replace in order to replace the old object with the new object.
This produces the exception: "Couldn't resolve lazy link, because no node model is attached", which makes of course sense, since the new created object has no corresponding node model object.
Therefore a possible solution is to also transform the node model (is it a good idea and how can I do it?) or to hook somewhere else.

Does anyone know a solution to that?

Best regards,
Alex.
Re: Replace object after linking [message #1174766 is a reply to message #1143438] Thu, 07 November 2013 09:52 Go to previous message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hey Alex,

I have a similar problem, I am searching for a good place to hook in the linking phase. I figured out a place for an inplace-transfo where I do not create a new modelelement, but change some references.
Follow the steps which are explained here:

http://www.eclipse.org/forums/index.php/m/29585/?srch=stereotype+in+model#msg_29585

I just extended Linker and override the ensureLinked method.
Maybe it might help you a little

~Alex
Previous Topic:How to display contents of Xtext index (builder.state)?
Next Topic:absolute windows path of an URI
Goto Forum:
  


Current Time: Sun Nov 29 23:40:36 GMT 2020

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

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

Back to the top