Complete proposal method does not provide expected model [message #881890] |
Tue, 05 June 2012 12:39 |
Catalin Apostu Messages: 2 Registered: June 2012 |
Junior Member |
|
|
Hello everyone,
we are trying to implement complete proposal (content assist) for our DSL. We know how the complete proposal mechanism in Xtext works
and which methods (form class "AbstractDSLProposalProvider") have to be overwritten in order to customize the completion proposal for a given DSL concept.
The problem we are facing consists in unprecise and unexpected context model
being provided to the method computing the completion proposal.
Here an example of our DSL:
package src.test;
class ClassA {
private var integer a;
public void methodA(){
}
public void methodB(integer a){
}
private void methodT(){
}
}
class ClassB {
private integer i;
private real n;
public void methodP(){
}
public void methodZ(ClassA clazz){
}
public void methodO(integer l, real b){
}
private void methodY(){
}
}
class ClassC {
private ClassA h;
private integer q;
private ClassB r;
public void methodC(){
real a;
r.<Ctrl>+<Space>
When I hit "<Ctrl>+<Space>" all public methods of "ClassB" should be listed in the content assit, but the content assist is empty.
We are overwriting the following method in our DSLProposalProvider:
public void completeMethodCallStatement_MethodCalled(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor)
The problem is that the provided model (as the first argument of the method) is of type "StatementBlock" and it contains only "real a;" statement,
but not the next statement where the methods have to be proposed. As a consequence the object on which the content assist is invoked is not known.
The gramamr rules are:
Package:
packageDecl = PackageDecl
;
PackageDecl:
'package' name = QualifiedName ';'
;
QualifiedName:
ID ('.' ID)*
;
Definition:
ClassDefinition
| EnumDefinition
;
ClassDefinition:
'class' name = ID ('extends' superClass = [ClassDefinition2 | QualifiedName])? '{'
(defs += Definition)*
(elements += ElementDecl)*
(methods += MethodDecl)*
(statemachine = StateMachineDecl)?
'}'
;
MethodDecl:
modifier = Modifier type = SystemOrModelType name=ID
('(' (args+=MethodParameter (',' args+=MethodParameter)*)? ')') (isDataset ?= 'as dataset')?
(block = StatementBlock | 'realizedBy' stateMachineRef = [StateMachineDecl])
;
StatementBlock:
'{'
(statements += BlockStatement)*
'}'
;
BlockStatement returns Statement:
LocalElementDecl
| Statement
;
Statement:
AssignmentStatement ';'
| ForEachStatement
| IfStatement
| StatementBlock
| ReturnStatement
| MethodCallStatement
;
MethodCallStatement:
func=[ElementRef]'.'methodCalled=[MethodDecl] ('(' (args+=Expression (',' args+=Expression)*)? ')' ';' )
;
Could it have something to do with the way the grammar rules are defined?
Thank you for any hint!
|
|
|
|
Re: Complete proposal method does not provide expected model [message #882448 is a reply to message #882040] |
Wed, 06 June 2012 13:32 |
Catalin Apostu Messages: 2 Registered: June 2012 |
Junior Member |
|
|
Hi Christian,
Thank you for your reply. We are still investigating the usage of the complete and scope providers in Xtext and their interdependencies.
Besides this, we are facing the problem described in my first post (unexpected model provided in overwritten complete and scope methods). Here the same issue exemplified at the scope provider:
The following method has been added to the DSLProposalProvider in order to find out which are the methods called for content assist:
@Override
public void completeAssignment(Assignment assignment, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
ParserRule parserRule = GrammarUtil.containingParserRule(assignment);
String methodName = "complete" + Strings.toFirstUpper(parserRule.getName()) + "_" + Strings.toFirstUpper(assignment.getFeature()); //$NON-NLS-1$//$NON-NLS-2$
System.out.println(methodName);
invokeMethod(methodName, acceptor, contentAssistContext.getCurrentModel(), assignment, contentAssistContext);
}
The following method has been added to the DSLScopeProvider in order to find out which are the methods called for scoping:
@Override
public IScope getScope(EObject context, EReference reference) {
System.out.println("scope_" + reference.getEContainingClass().getName() + "_" + reference.getName() + "(" + context.eClass().getName() + ", ..)");
return super.getScope(context, reference);
}
When content assist is invoked on
class ClassC {
private ClassA h;
private integer q;
private ClassB r;
public void methodC(){
real a;
r.<Ctrl>+<Space>
the scoping method does not contain the expected expected (EObject) model. Instead of the expected method call context model ("r."), an element declaration context model ("real a;") is provided.
What do you think it could be the reason for the unexpected model provided to the overwritten complete and scope methods? Could it have something to do with the rules of our grammar?
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04025 seconds