Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Referencing nameless Cross-references
Referencing nameless Cross-references [message #1752356] Sun, 22 January 2017 23:15 Go to next message
Niklas Jugl is currently offline Niklas JuglFriend
Messages: 2
Registered: January 2017
Junior Member
generate mydsl "myfirm/mydsl"
Constants : 
   'KONSTANTE' ( (name=ID ',' foo=INT)
    | ( const=[typ::Konstante] )) // nameless reference
;

Otherrule:
name=ID ref=[Constants] // can only reference the locally declared constants
;


generate typ "myfirm/typ"
Konstante:
	'KONSTANTE' name = ID ':' foo=INT
;


Hi, I am having trouble getting the references to work. I want to reference the rule 'constants' but I can only get the references to match for the locally declared 'constants'. But I want to get the references to the nameless 'constants' as well.

I figuered out that I have implement my own QualifiedNameProvider but the name of the Konstante is not loaded (null) when I try to access it.


class MyDSLQualifiedNameProvider extends IQualifiedNameProvider.AbstractImpl {
    @Inject  private IQualifiedNameConverter qualifiedNameConverter;

    override getFullyQualifiedName(EObject obj) {
        var name = SimpleAttributeResolver.NAME_RESOLVER.apply(obj);

        if (name == null || name.length() == 0) {
            if (obj.class == ConstantsImpl) {
                var constants = obj as Constants;
                // constants.const.name is always null
                if (constants.const.name == null) {
                    return null;
                }

                return qualifiedNameConverter.toQualifiedName(constants.const.name)
            } else {
                return null;
            }
        }
        return qualifiedNameConverter.toQualifiedName(name);
    }
}



How can I get access to the name of the externally referenced object?
Or is there a other solution to the problem or an example where someone else has solved this issue?
Re: Referencing nameless Cross-references [message #1752417 is a reply to message #1752356] Mon, 23 January 2017 15:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi

you can use NodeModelUtils to obtain the text in the model for the const feature.
then you can implement iQualifiedNameProvider to use that text to give the nameless constant a name


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon7.gif  Re: Referencing nameless Cross-references [message #1752437 is a reply to message #1752417] Mon, 23 January 2017 18:04 Go to previous message
Niklas Jugl is currently offline Niklas JuglFriend
Messages: 2
Registered: January 2017
Junior Member
Thanks so much, I've been struggling with this problem for literally two whole days now..

I am accually using this in my scopeProvider:
            if (reference == M2Package.Literals.OTHERRULE__REF ) {
                val rootElement = EcoreUtil2.getRootContainer(context)
                val candidates = EcoreUtil2.getAllContentsOfType(rootElement, ConstantsImpl)
                for(ConstantsImpl c : candidates){
                    if(c.const!=null){
                        c.name = (((NodeModelUtils.getNode(c).semanticElement) as ConstantsImpl).const as Konstante).name;
                    }
                }
                val existingScope = Scopes.scopeFor(candidates)
                return new FilteringScope(existingScope, [getEObjectOrProxy != context])
            }

I guess it's not the most beautifull solution but it works... Smile
Previous Topic:Formatter2 Junit test passes in Eclipse but fails in maven (Xtext 2.10.0)
Next Topic:Doing a Clean Build on Xtext 2.9.1
Goto Forum:
  


Current Time: Thu Apr 25 13:52:21 GMT 2024

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

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

Back to the top