Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Multiple usages for the current input string
Multiple usages for the current input string [message #49161] Mon, 08 June 2009 13:34 Go to next message
Juergen Denner is currently offline Juergen DennerFriend
Messages: 3
Registered: July 2009
Junior Member
Hello,



Is there a way to assign the currently parsed input string to a member AND
to use it at the same time for linking?



Example:

========

ReferringHost:

(refs += ReferringType)*



ReferringType:

'ref' referencedObject=[Entity|(ID|STRING)];

....



I want to modify the grammar it in a way to store the (ID|STRING)
additionally in a name attribute. Like:



ReferringType:

'ref' referencedObject=[Entity|(ID|STRING)] name=$current;



Storing the value in the name attribute is necessary in this scenario
because the EMF "EKeys"-feature is used by ReferringHost-refs to address the
objects by name and not their collection index.



I tried to set the name field during the linking phase. This failed because
Xtext internally creates proxy references to ReferringType instances before
linking starts.



Kind regards,

J
Re: Multiple usages for the current input string [message #49190 is a reply to message #49161] Mon, 08 June 2009 14:09 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Jürgen,

I'ld suggest to mark the name attribute as 'derived'. Derived features
don't have modifiers and the implementation of the getter would compute
the value from other state (i.e. the cross reference in your case).
The getter needs to be implemented in Java in the generated code.

Cheers,
Sven

Jürgen Denner schrieb:
> Hello,
>
>
>
> Is there a way to assign the currently parsed input string to a member AND
> to use it at the same time for linking?
>
>
>
> Example:
>
> ========
>
> ReferringHost:
>
> (refs += ReferringType)*
>
>
>
> ReferringType:
>
> 'ref' referencedObject=[Entity|(ID|STRING)];
>
> ...
>
>
>
> I want to modify the grammar it in a way to store the (ID|STRING)
> additionally in a name attribute. Like:
>
>
>
> ReferringType:
>
> 'ref' referencedObject=[Entity|(ID|STRING)] name=$current;
>
>
>
> Storing the value in the name attribute is necessary in this scenario
> because the EMF "EKeys"-feature is used by ReferringHost-refs to address the
> objects by name and not their collection index.
>
>
>
> I tried to set the name field during the linking phase. This failed because
> Xtext internally creates proxy references to ReferringType instances before
> linking starts.
>
>
>
> Kind regards,
>
> Jürgen
>
>
>
> PS: I'm using Xtext 0.7 from Eclipse-Modeling-Tools RC2
>
>
>
Re: Multiple usages for the current input string [message #49212 is a reply to message #49190] Mon, 08 June 2009 14:48 Go to previous messageGo to next message
Juergen Denner is currently offline Juergen DennerFriend
Messages: 3
Registered: July 2009
Junior Member
Hi Sven,

Unluckily this does not work for the same reason as the manipulation during
the linking phase. I tried this out and the parsing sequence seems to be
like this:

1. A new ReferringType instance is created.
2. The instance is added to the refs collection of ReferringHost.
3. A proxy reference to the new instance is created and used internally by
Xtex (referencedObject is still null. I.e. the name is not known).

4. During the linking phase, the referencedObject gets filled. But now the
instance URI changes and the proxy reference get invalid.

Therefore I need to set the name attribute earlier.

Cheers,
J
Re: Multiple usages for the current input string [message #49304 is a reply to message #49212] Mon, 08 June 2009 18:17 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Jürgen Denner schrieb:
> 1. A new ReferringType instance is created.
> 2. The instance is added to the refs collection of ReferringHost.
> 3. A proxy reference to the new instance is created and used internally by
> Xtex (referencedObject is still null. I.e. the name is not known).

Why is referencedObject still null? It should contain the lazy linking
proxy which automatically is replaced with the real object when accessed
the first time.

>
> 4. During the linking phase, the referencedObject gets filled. But now the
> instance URI changes and the proxy reference get invalid.

Sorry, I don't get it.

Usually one shouldn't need to care about the lazy linking proxies.

Assuming that your grammar just declares the linking and your meta model
contains an addition derived "name"-attribute. Why can't you just
compute the name like this? :

String getName() {
return getReferencedObject().getName();
}

Sven
Re: Multiple usages for the current input string [message #49395 is a reply to message #49304] Mon, 08 June 2009 21:47 Go to previous messageGo to next message
Juergen Denner is currently offline Juergen DennerFriend
Messages: 3
Registered: July 2009
Junior Member
Hi Sven,

> Why can't you just compute the name like this? :
>
> String getName() {
> return getReferencedObject().getName();
> }

If I do it like this, I end up with a NPE.

Thread [main] (Suspended (exception NullPointerException))
ReferringTypeImpl.getName() line: 178
ReferringTypeImpl.eGet(int, boolean, boolean) line: 214
ReferringTypeImpl(BasicEObjectImpl).eGet(EStructuralFeature, boolean,
boolean) line: 1013
ReferringTypeImpl(BasicEObjectImpl).eGet(EStructuralFeature, boolean)
line: 1005
ReferringTypeImpl(BasicEObjectImpl).eGet(EStructuralFeature) line: 1000
ReferringHostImpl(BasicEObjectImpl).eURIFragmentSegment(EStr ucturalFeature,
EObject) line: 359
LazyLinkingResource(ResourceImpl).getURIFragment(EObject) line: 678
LazyLinkingResource(XtextResource).getURIFragment(EObject) line: 179
LazyURIEncoder.encode(EObject, EReference, AbstractNode) line: 42
LazyLinker.createProxy(EObject, AbstractNode, EReference) line: 124
LazyLinker.createAndSetProxy(EObject, AbstractNode, EReference) line:
113
LazyLinker.installProxies(EObject, IDiagnosticProducer,
Multimap<Setting,AbstractNode>) line: 84
LazyLinker.doLinkModel(EObject, IDiagnosticConsumer) line: 59
LazyLinker(AbstractCleaningLinker).linkModel(EObject,
IDiagnosticConsumer) line: 24
LazyLinkingResource(XtextResource).doLinking() line: 141
LazyLinkingResource(XtextResource).doLoad(InputStream, Map<?,?>) line:
161
LazyLinkingResource.doLoad(InputStream, Map<?,?>) line: 43
LazyLinkingResource(XtextResource).reparse(String) line: 85
XtextReconciler$1.process(XtextResource) line: 147
XtextReconciler$1.process(Object) line: 1
XtextReconciler$1(IUnitOfWork$Void<T>).exec(T) line: 36
XtextDocument$XtextDocumentLocker(IStateAccess$AbstractImpl<P >).modify(IUnitOfWork<T,P>)
line: 57
XtextDocument.modify(IUnitOfWork<T,XtextResource>) line: 135
XtextReconciler.handleInputDocumentChanged(IDocument, IDocument) line:
141
XtextReconciler.access$3(XtextReconciler, IDocument, IDocument) line:
133
XtextReconciler$TextInputListener.inputDocumentChanged(IDocu ment,
IDocument) line: 88
ProjectionViewer(TextViewer).fireInputDocumentChanged(IDocum ent,
IDocument) line: 2870
ProjectionViewer(TextViewer).setDocument(IDocument) line: 2919
ProjectionViewer(SourceViewer).setDocument(IDocument, IAnnotationModel,
int, int) line: 545
ProjectionViewer.setDocument(IDocument, IAnnotationModel, int, int)
line: 375
ProjectionViewer(SourceViewer).setDocument(IDocument, IAnnotationModel)
line: 500
XtextEditor(AbstractTextEditor).initializeSourceViewer(IEdit orInput)
line: 3951
XtextEditor(AbstractTextEditor).createPartControl(Composite) line: 3466
XtextEditor(StatusTextEditor).createPartControl(Composite) line: 53
XtextEditor(AbstractDecoratedTextEditor).createPartControl(C omposite)
line: 427
XtextEditor.createPartControl(Composite) line: 210
....

The problem 'starts' here:
...
ReferringHostImpl(BasicEObjectImpl).eURIFragmentSegment(EStr ucturalFeature,
EObject) line: 359
LazyLinkingResource(ResourceImpl).getURIFragment(EObject) line: 678
LazyLinkingResource(XtextResource).getURIFragment(EObject) line: 179
...

The eURIFragmentSegment(...) function is invoked before the Xtext linking
has happened. Due to that, referencedObject of ReferringTypeImpl is still
null.
To compute eURIFragmentSegment, EMF must invoke getName() and getName()
relies on a referencedObject.

Everything works perfectly, as long as I do not use EMF's EKeys feature. But
in my scenario I have additional EMF resources with objects pointing to
ReferringType instances and they need to be identified by name.

I hope that I could shed some light on the situation.

Cheers,
J
Re: Multiple usages for the current input string [message #49577 is a reply to message #49395] Tue, 09 June 2009 08:23 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Jürgen,

could you please try to come up with a small example which reproduces
your problem?
You can send it to me, or attach it to a bugzilla.

Cheers,
Sven


Jürgen Denner schrieb:
> Hi Sven,
>
>> Why can't you just compute the name like this? :
>>
>> String getName() {
>> return getReferencedObject().getName();
>> }
>
> If I do it like this, I end up with a NPE.
>
> Thread [main] (Suspended (exception NullPointerException))
> ReferringTypeImpl.getName() line: 178
> ReferringTypeImpl.eGet(int, boolean, boolean) line: 214
> ReferringTypeImpl(BasicEObjectImpl).eGet(EStructuralFeature, boolean,
> boolean) line: 1013
> ReferringTypeImpl(BasicEObjectImpl).eGet(EStructuralFeature, boolean)
> line: 1005
> ReferringTypeImpl(BasicEObjectImpl).eGet(EStructuralFeature) line: 1000
> ReferringHostImpl(BasicEObjectImpl).eURIFragmentSegment(EStr ucturalFeature,
> EObject) line: 359
> LazyLinkingResource(ResourceImpl).getURIFragment(EObject) line: 678
> LazyLinkingResource(XtextResource).getURIFragment(EObject) line: 179
> LazyURIEncoder.encode(EObject, EReference, AbstractNode) line: 42
> LazyLinker.createProxy(EObject, AbstractNode, EReference) line: 124
> LazyLinker.createAndSetProxy(EObject, AbstractNode, EReference) line:
> 113
> LazyLinker.installProxies(EObject, IDiagnosticProducer,
> Multimap<Setting,AbstractNode>) line: 84
> LazyLinker.doLinkModel(EObject, IDiagnosticConsumer) line: 59
> LazyLinker(AbstractCleaningLinker).linkModel(EObject,
> IDiagnosticConsumer) line: 24
> LazyLinkingResource(XtextResource).doLinking() line: 141
> LazyLinkingResource(XtextResource).doLoad(InputStream, Map<?,?>) line:
> 161
> LazyLinkingResource.doLoad(InputStream, Map<?,?>) line: 43
> LazyLinkingResource(XtextResource).reparse(String) line: 85
> XtextReconciler$1.process(XtextResource) line: 147
> XtextReconciler$1.process(Object) line: 1
> XtextReconciler$1(IUnitOfWork$Void<T>).exec(T) line: 36
> XtextDocument$XtextDocumentLocker(IStateAccess$AbstractImpl<P >).modify(IUnitOfWork<T,P>)
> line: 57
> XtextDocument.modify(IUnitOfWork<T,XtextResource>) line: 135
> XtextReconciler.handleInputDocumentChanged(IDocument, IDocument) line:
> 141
> XtextReconciler.access$3(XtextReconciler, IDocument, IDocument) line:
> 133
> XtextReconciler$TextInputListener.inputDocumentChanged(IDocu ment,
> IDocument) line: 88
> ProjectionViewer(TextViewer).fireInputDocumentChanged(IDocum ent,
> IDocument) line: 2870
> ProjectionViewer(TextViewer).setDocument(IDocument) line: 2919
> ProjectionViewer(SourceViewer).setDocument(IDocument, IAnnotationModel,
> int, int) line: 545
> ProjectionViewer.setDocument(IDocument, IAnnotationModel, int, int)
> line: 375
> ProjectionViewer(SourceViewer).setDocument(IDocument, IAnnotationModel)
> line: 500
> XtextEditor(AbstractTextEditor).initializeSourceViewer(IEdit orInput)
> line: 3951
> XtextEditor(AbstractTextEditor).createPartControl(Composite) line: 3466
> XtextEditor(StatusTextEditor).createPartControl(Composite) line: 53
> XtextEditor(AbstractDecoratedTextEditor).createPartControl(C omposite)
> line: 427
> XtextEditor.createPartControl(Composite) line: 210
> ....
>
> The problem 'starts' here:
> ...
> ReferringHostImpl(BasicEObjectImpl).eURIFragmentSegment(EStr ucturalFeature,
> EObject) line: 359
> LazyLinkingResource(ResourceImpl).getURIFragment(EObject) line: 678
> LazyLinkingResource(XtextResource).getURIFragment(EObject) line: 179
> ...
>
> The eURIFragmentSegment(...) function is invoked before the Xtext linking
> has happened. Due to that, referencedObject of ReferringTypeImpl is still
> null.
> To compute eURIFragmentSegment, EMF must invoke getName() and getName()
> relies on a referencedObject.
>
> Everything works perfectly, as long as I do not use EMF's EKeys feature. But
> in my scenario I have additional EMF resources with objects pointing to
> ReferringType instances and they need to be identified by name.
>
> I hope that I could shed some light on the situation.
>
> Cheers,
> Jürgen
>
>
> "Sven Efftinge" <sven.efftinge@itemis.de> wrote in message
> news:h0jkjn$nco$1@build.eclipse.org...
>> Jürgen Denner schrieb:
>>> 1. A new ReferringType instance is created.
>>> 2. The instance is added to the refs collection of ReferringHost.
>>> 3. A proxy reference to the new instance is created and used internally
>>> by Xtex (referencedObject is still null. I.e. the name is not known).
>> Why is referencedObject still null? It should contain the lazy linking
>> proxy which automatically is replaced with the real object when accessed
>> the first time.
>>
>>> 4. During the linking phase, the referencedObject gets filled. But now
>>> the instance URI changes and the proxy reference get invalid.
>> Sorry, I don't get it.
>>
>> Usually one shouldn't need to care about the lazy linking proxies.
>>
>> Assuming that your grammar just declares the linking and your meta model
>> contains an addition derived "name"-attribute. Why can't you just compute
>> the name like this? :
>>
>> String getName() {
>> return getReferencedObject().getName();
>> }
>>
>> Sven
>
>
Previous Topic:[XText] Questions about XText parsing and reconciling design decisions
Next Topic:Running Xtext generator from maven
Goto Forum:
  


Current Time: Thu Dec 26 15:52:13 GMT 2024

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

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

Back to the top