complete{TypeName}_{FeatureName} called with unexpected parameters [message #1085792] |
Tue, 13 August 2013 11:31 |
Till F. 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.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05579 seconds