xtext custom scoping: parameters of function

2019-07-10 00:22发布

I am trying to custom scoping, such that if I have something like function in my language that get parameters, I want that those parameters will be visible only until there is semicolon, and out of this scope, I want it to not be visible.

I tried redefine the method getScope() in the file MyDslScopeProvider.xtend

In getScope I did something like this:

 if (EclassName=="TypedParam" && EFeatureName=="type" && contextType == "TypedParam"){
        return Scopes.scopeFor(Collections.singleton(context),IScope.NULLSCOPE)
    }

This is abviosly doesn't working (It doesn't recognize the parameters). How can I do it?

Moreover, I have another question: I tried implements methods like:

def IScope scope_<EClass name>_<EFeature name>(<context type> context, EReference)

Although I printed the names and I made sure I am writing the name correct, those method simply never called. (I copied what was printed from the following code)

class DomainmodelScopeProvider extends AbstractDomainmodelScopeProvider {
    override def IScope getScope(EObject context, EReference reference)
    {

        System.out.println("scope_" + reference.getEContainingClass().getName()
             + "_" + reference.getName()
             + "(" + context.eClass().getName() + ", ..)"
        );

        return super.getScope(context,reference);                   
    }

What am I doing wrong?

Thanks!!!

1条回答
迷人小祖宗
2楼-- · 2019-07-10 00:53

The Problem is that with Xtext 2.9+ AbstractDeclarativeScopeProvider is no longer the default superclass of YourdslScopeProvider. You are expected to override getScope(EObject context, EReference ref)and do if elsing there. Or you change the superclass manually. Btw you can use the Constants in YourdslPackage.Literalsinstead of using manual string constants.

查看更多
登录 后发表回答