Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom IResourceDescriptionStrategy not working as expected
Custom IResourceDescriptionStrategy not working as expected [message #1872644] Tue, 12 November 2024 12:10 Go to next message
Tommaso Fonda is currently offline Tommaso FondaFriend
Messages: 9
Registered: May 2024
Junior Member
Hi,

In my project I've implemented my own IResourceDescriptionStrategy, based on DefaultResourceDescriptionStrategy, overriding createEObjectDescriptions() to add an AliasedEObjectDescription for some of the EObjectDescriptions created by the default implementation. The unexpected behaviour is that I can use an AliasedEObjectDescription's QualifiedName to refer to the associated EObject only in a different file than the one that contains the text that, when parsed, creates that EObject.

For example, I have used my IResourceDescriptionStrategy implementation to add an unquoted alias for every EObject that has got a name wrapped in single quotation marks. In my DSL's editor the following does not work:
package a {
	item 'z';
}

package b {
	reference a::z;
}

and I get the "Couldn't resolve reference to Item a::z" error. If I copy paste the whole "package b {...}" into a different file, the model suddenly becomes valid.
Within the same file, I am forced to write a::'z'.

What am I missing? Is this intended behaviour, and if so, how can I get the aliases to work even within the same file?

Thanks!
Re: Custom IResourceDescriptionStrategy not working as expected [message #1872647 is a reply to message #1872644] Tue, 12 November 2024 15:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
this is intentional. local scope is not coming from index but by impl
of ImportNamespaceAwareLocalScopeProvider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Custom IResourceDescriptionStrategy not working as expected [message #1872650 is a reply to message #1872647] Tue, 12 November 2024 15:22 Go to previous messageGo to next message
Tommaso Fonda is currently offline Tommaso FondaFriend
Messages: 9
Registered: May 2024
Junior Member
Thanks. I guess that to customise this to my needs I shall override internalGetAllDescriptions() in my custom ImportedNamespaceAwareLocalScopeProvider to somehow add my AliasedEObjectDescriptions to the allDescriptions iterable before it is used to initialise the MultimapBasedSelectable, correct?
Re: Custom IResourceDescriptionStrategy not working as expected [message #1872653 is a reply to message #1872650] Tue, 12 November 2024 15:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
depends on what you actually want to achive. (this does not come clear from your initial post)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Tue, 12 November 2024 15:26]

Report message to a moderator

Re: Custom IResourceDescriptionStrategy not working as expected [message #1872662 is a reply to message #1872653] Wed, 13 November 2024 07:06 Go to previous messageGo to next message
Tommaso Fonda is currently offline Tommaso FondaFriend
Messages: 9
Registered: May 2024
Junior Member
Christian Dietrich wrote on Tue, 12 November 2024 15:25
depends on what you actually want to achive. (this does not come clear from your initial post)

In my DSL, items can optionally have their name wrapped in quote marks. I want to be able to refer to all items whose name is wrapped in quote marks, using not only their original wrapped name, but also their name without quote marks. And of course I want to be able to do so both from within the same file, and from other files.
What I described in my first post is the first reasonable approach I managed to implement and (mostly) get to work, but I'm of course open to advice on how to improve it and/or make it more sound.
Thank you very much, as usual!
Re: Custom IResourceDescriptionStrategy not working as expected [message #1872671 is a reply to message #1872662] Wed, 13 November 2024 21:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
Imwould have expected to do this on pure grammar or value converter level

So myself=[Thing|DatatypeOrTerminalRuleToUse]

With DatatypeOrTerminalRuleToUse: STRING|ID; + a value converter that strips the quotes


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Custom IResourceDescriptionStrategy not working as expected [message #1872677 is a reply to message #1872671] Thu, 14 November 2024 13:06 Go to previous messageGo to next message
Tommaso Fonda is currently offline Tommaso FondaFriend
Messages: 9
Registered: May 2024
Junior Member
Christian Dietrich wrote on Wed, 13 November 2024 21:08
Imwould have expected to do this on pure grammar or value converter level

So myself=[Thing|DatatypeOrTerminalRuleToUse]

With DatatypeOrTerminalRuleToUse: STRING|ID; + a value converter that strips the quotes

Thanks for the advice, I had already looked into ValueConverters in the past but haven't ever actually used them. However, my understanding is that with a ValueConverter that strips the quote marks, I would be able to refer to my elements only with their unquoted names, which is not what I want (I want both options, i.e. quoted and unquoted, to be valid and usable). Am I wrong?
Re: Custom IResourceDescriptionStrategy not working as expected [message #1872692 is a reply to message #1872677] Thu, 14 November 2024 20:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
Well

If you have "x" or x in the file the value converter will make x out of it.
This is what the scope provider be asked


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Custom IResourceDescriptionStrategy not working as expected [message #1872707 is a reply to message #1872692] Fri, 15 November 2024 12:45 Go to previous message
Tommaso Fonda is currently offline Tommaso FondaFriend
Messages: 9
Registered: May 2024
Junior Member
Christian Dietrich wrote on Thu, 14 November 2024 20:14
Well

If you have "x" or x in the file the value converter will make x out of it.
This is what the scope provider be asked

Oh, I think I've only now understood your point!
The value converter will map both 'x' and x to x when it processes the name of an entity (which is parsed using a custom rule and assigned as "name=Name" in my entities' rules), but it will also do the same whenever a cross-reference making use of the Name rule is parsed, so both variants of the name are effectively mapped to the unquoted variant in both contexts and thus it will be possible to resolve the cross-references both with and without quotes.
(sorry if I've worded this post slightly imprecisely, I've written it in a hurry)

Next week I'll try to implement this approach.
Previous Topic:Xtext 2.37.0.M2 for Eclipse 2024-12 M3
Next Topic:Xtext 2.37.0 is released
Goto Forum:
  


Current Time: Thu Dec 12 07:48:49 GMT 2024

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

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

Back to the top