0
votes

I am trying to create a small DSL language using XText.

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

StartState:
'startState'
     'evaluate' ref=JvmTypeReference "-" op=[jvmTypes::JvmOperation]
'end';

Following is the ScopeProvider Implementation:

public class MyScopeProvider extends AbstractDeclarativeScopeProvider {

IScope scope_StartState_op(StartState call, EReference reference) {
    JvmType type = call.getRef().getType();
    List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();

    if (type instanceof JvmGenericType) {
        JvmGenericType gt = (JvmGenericType) type;
        for (JvmMember member : gt.getMembers()) {
            if (member instanceof JvmOperation) {
                descriptions.add(EObjectDescription.create(member.getSimpleName(), member));
            }
        }
    }
    return new SimpleScope(descriptions);
}}

I type following into the resulting editor

startState evaluate controller.Controller - perform end

Here I am able to get the code completion working for method (perform which is in controller.Controller class) as expected. But I am in need of help to resolve the following error which happens after the code completion.

Couldn't resolve reference to JvmOperation 'perform'.

Also, I tried following Peter's Blog with no success

1
which xtext version do you use? how does the declaration line of the grammar look like? it works fine for me using 2.8.2 and inhering org.eclipse.xtext.xbase.Xtype - Christian Dietrich
@ChristianDietrich - I added the grammar at the top of the question. Please have a look. Also I am using Xtext 2.8.2 on Luna Service Release 2 (4.4.2) Build id: 20150219-0600 - Stack Overflow
@ChristianDietrich - Thank you very much for the tip. I was using org.eclipse.xtext.xbase.Xbase instead of org.eclipse.xtext.xbase.Xtype - Stack Overflow

1 Answers

0
votes

Posting answer to my own question. The grammer should look like the following.

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xtype import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

StartState: 'startState' 'evaluate' ref=JvmTypeReference "-" op=[jvmTypes::JvmOperation] 'end';

There is no change to the scope provider and the usage.