Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » complete{TypeName}_{FeatureName} called with unexpected parameters
complete{TypeName}_{FeatureName} called with unexpected parameters [message #1085792] Tue, 13 August 2013 11:31 Go to next message
Till F. is currently offline Till F.Friend
Messages: 58
Registered: August 2012
Member
Hi,

I've got a question regarding the interface "complete{TypeName}_{FeatureName}" of the {LanguageName}ProposalProvider.

I've got the following grammer:

InvariantDef:
    "invariant" (realInvariant=VariableInvariant) ";"
;

VariableInvariant:
    variable=[custommodel::Variable|FULLQUALIFIEDNAME] relation=RELATION value=INT
;


Among others this generates the following method in Abstract{LanguageName}ProposalProvider:

public void completeVariableInvariant_Variable(EObject model, Assignment assignment,
    ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
    lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
}


I expected the parameter "EObject model" to be of the more specific type "VariableInvariant". In reality it is "InvariantDef" (thus the parent). The documentation of "getCurrentModel()" and "getPreviousModel()" of "ContentAssistContext" suggests that this is intended / forced by the architecture. Is this really inevitable or can I do something to prevent it?

The problem is that it may cause trouble: The proposals added to content assist using the default implementation above will not correspond to the actual scope, at least if a custom scope provider is used.

For example, in my case I defined a local scope for "VariableInvariant_variable" by adding the following method to {LanguageName}ScopeProvider:

public IScope scope_VariableInvariant_variable(VariableInvariant vi, EReference ref)
{
    // ...
}


But this Scope will not be considered for proposals if the default implementation above is used. Proposals differ from what is actually accepted. To solve this, I have to obtain the scope and maintain proposals manually:

@Override
public void completeVariableInvariant_Variable(EObject model, Assignment assignment,
    ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
    if (model instanceof InvariantDef)
    {
        VariableInvariant vi = ((InvariantDef) model).getRealInvariant();
        CrossReference crossReference = (CrossReference)assignment.getTerminal();
        EReference ref = GrammarUtil.getReference(crossReference);
        IScope scope = getScopeProvider().getScope(vi, ref);
        Iterable<IEObjectDescription> scopedElements = scope.getAllElements();
        
        for (IEObjectDescription eod : scopedElements)
        {
            String proposal = eod.getName().toString();
            acceptor.accept(createCompletionProposal(proposal, context));
        }
    }
    else
    {
        super.completeVariableInvariant_Variable(model, assignment, context, acceptor);
    }
}


This isn't much code, but it has a bad smell. Can I do something better? Or is this a known flaw in the xtext architecture?


Another remark (off-topic): is there a good reason to have totally different concepts for customizing content assist and scoping? The first one is achieved by overriding ("Generation Gap Pattern" / "Double Derived Classes"), which is good, the other one by using reflection, which should be avoided.


Re: complete{TypeName}_{FeatureName} called with unexpected parameters [message #1085803 is a reply to message #1085792] Tue, 13 August 2013 11:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
HI,

simply define the scoping as follows

scope_Child_ref(Parent context, EReference ref) {

}

And it will work in both scopig and content assist without any further problems


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: complete{TypeName}_{FeatureName} called with unexpected parameters [message #1085826 is a reply to message #1085803] Tue, 13 August 2013 12:33 Go to previous messageGo to next message
Till F. is currently offline Till F.Friend
Messages: 58
Registered: August 2012
Member
Christian Dietrich wrote on Tue, 13 August 2013 07:46
HI,

simply define the scoping as follows

scope_Child_ref(Parent context, EReference ref) {

}

And it will work in both scopig and content assist without any further problems


Pretty nice solution, it works like a charme.

Thanks, Christian.

Anyway, I still find it a bit awkward to define the scope for the Child (method name) but dealing with the Parent (method parameter)... Confused
Re: complete{TypeName}_{FeatureName} called with unexpected parameters [message #1085828 is a reply to message #1085826] Tue, 13 August 2013 12:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hey it is part of the intended api, xtext walks up the containment tree when scoping.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 13 August 2013 12:34]

Report message to a moderator

Re: complete{TypeName}_{FeatureName} called with unexpected parameters [message #1085856 is a reply to message #1085828] Tue, 13 August 2013 13:16 Go to previous messageGo to next message
Till F. is currently offline Till F.Friend
Messages: 58
Registered: August 2012
Member
I see that Xtext walks up the containment tree. But it seems that the starting point for scoping and content assist is not always the same (child vs. parent).

Nevertheless I have to admit that it is difficult or even impossible to find a reasonable example for having the scope "provided" by the child itself. One could even think of forbidding a construct like "scope_Child_ref(Child context, EReference ref)"...
Re: complete{TypeName}_{FeatureName} called with unexpected parameters [message #1085858 is a reply to message #1085856] Tue, 13 August 2013 13:18 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

the problem for that that Xtext create Objects lazy so if the first assignment is a reference there is not yet a object created when using content assist.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Importing Files and Global/Local Scoping
Next Topic:Outline View in Xtext
Goto Forum:
  


Current Time: Fri Mar 29 06:18:51 GMT 2024

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

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

Back to the top