Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Complete proposal method does not provide expected model
Complete proposal method does not provide expected model [message #881890] Tue, 05 June 2012 12:39 Go to next message
Catalin Apostu is currently offline Catalin ApostuFriend
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! Smile
Re: Complete proposal method does not provide expected model [message #882040 is a reply to message #881890] Tue, 05 June 2012 17:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this is usually done by scoping and not by customizing content assist.
for some basic reading have a look at http://blogs.itemis.de/stundzig/archives/773

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Complete proposal method does not provide expected model [message #882448 is a reply to message #882040] Wed, 06 June 2012 13:32 Go to previous messageGo to next message
Catalin Apostu is currently offline Catalin ApostuFriend
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?
Re: Complete proposal method does not provide expected model [message #882497 is a reply to message #882448] Wed, 06 June 2012 15:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi I recommend to start with a simplyfied grammar you can share
completely with us. Please not: Xtext creates object lazy thus there
may be a parent object in the context.

p.S: the content assist may have problems if your grammar has amigous prefixes containing the references.


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

[Updated on: Wed, 06 June 2012 21:03]

Report message to a moderator

Re: Complete proposal method does not provide expected model [message #886509 is a reply to message #882497] Fri, 15 June 2012 04:43 Go to previous messageGo to next message
Latha Shankara is currently offline Latha ShankaraFriend
Messages: 33
Registered: June 2012
Member
Hi Christian,

I face a similar problem. Could you please give an example grammar having ambiguous prefixes containing references? And how we could go about in tackling them?

Thanks,
Latha

[Updated on: Fri, 15 June 2012 05:07]

Report message to a moderator

Re: Complete proposal method does not provide expected model [message #886512 is a reply to message #886509] Fri, 15 June 2012 04:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
On 2012-06-15 04:43:05 +0000, Latha Shankara said:

> Hi Christian,
>
> Could you please give an example grammar having ambiguous prefixes
> containing references?
>
> Thanks,
> Latha

Reference:
ref=[A] | ref=[B];

vs

Reference:
('a' ref=[A]) | ('b' ref=[B]);

vs

Reference:
ref=[AorB];

AorB: A |B;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Complete proposal method does not provide expected model [message #886597 is a reply to message #886512] Fri, 15 June 2012 08:51 Go to previous messageGo to next message
Latha Shankara is currently offline Latha ShankaraFriend
Messages: 33
Registered: June 2012
Member
Hi Christian,

So if we have a rule like:

Abstract: T1|T2|T3|T4|T5

and another rule which uses the above rule as below

Usage: use=[Abstract]'=' with=[T3];

How could we go about resolving the references in Usage rule?

Thanks,
Latha
Re: Complete proposal method does not provide expected model [message #886614 is a reply to message #886597] Fri, 15 June 2012 09:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
This will work out of the box

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Complete proposal method does not provide expected model [message #886618 is a reply to message #886614] Fri, 15 June 2012 09:48 Go to previous messageGo to next message
Latha Shankara is currently offline Latha ShankaraFriend
Messages: 33
Registered: June 2012
Member

Abstract: T1|T2|T3|T4|T5
Usage: use=[Abstract]'=' with=[T3];

With this grammar, I face the same problem as described by Catalin, the one who posted this question. I get a parent object but not "Usage" as my model.
Re: Complete proposal method does not provide expected model [message #886624 is a reply to message #886618] Fri, 15 June 2012 09:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Please provide something complete (useable)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Complete proposal method does not provide expected model [message #889865 is a reply to message #886624] Wed, 20 June 2012 04:04 Go to previous messageGo to next message
Latha Shankara is currently offline Latha ShankaraFriend
Messages: 33
Registered: June 2012
Member
Hi Christian,

Please find the attached grammar. With this grammr I face the problem which I described in earlier posts.

Thanks for your help,
Latha
Re: Complete proposal method does not provide expected model [message #889868 is a reply to message #889865] Wed, 20 June 2012 04:42 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
This grammar is not complete and maybe too complex to explain the
problem. And maybe has ambiguous prefixes. But as I cannot paste and
run hard to say especially since interesting parts are missing


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:testing the language
Next Topic:Quickfixes appear multiple times
Goto Forum:
  


Current Time: Fri Apr 26 11:33:06 GMT 2024

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

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

Back to the top