xtext自定义作用域:函数参数 [英] xtext custom scoping: parameters of function
问题描述
我正在尝试自定义作用域,以便如果我的语言中有类似函数可以获取参数,我希望这些参数仅在出现分号之前才可见,并且超出此范围,我希望它不会可见.
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.
我尝试在MyDslScopeProvider.xtend文件中重新定义方法getScope()
I tried redefine the method getScope() in the file MyDslScopeProvider.xtend
在getScope中,我做了这样的事情:
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);
}
我在做什么错了?
谢谢!
推荐答案
问题是使用Xtext 2.9+ AbstractDeclarativeScopeProvider
不再是YourdslScopeProvider
的默认超类.您应该覆盖getScope(EObject context, EReference ref)
并在该目录中进行操作.或者您手动更改超类.顺便说一句,您可以在YourdslPackage.Literals
中使用常量,而不是使用手动字符串常量.
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.Literals
instead of using manual string constants.
这篇关于xtext自定义作用域:函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!