gpt4 book ai didi

eclipse - xtext 自定义作用域 : parameters of function

转载 作者:行者123 更新时间:2023-12-04 16:47:14 24 4
gpt4 key购买 nike

我正在尝试自定义范围,这样如果我在我的语言中有类似函数的东西来获取参数,我希望这些参数只在出现分号之前可见,并且在这个范围之外,我希望它不可见可见。

我尝试在文件 MyDslScopeProvider.xtend 中重新定义方法 getScope()

在 getScope 中我做了这样的事情:

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

这显然不起作用(它无法识别参数)。我该怎么做?

另外,我还有一个问题:我尝试实现如下方法:

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

虽然我打印了名字并且我确保我写的名字是正确的,但这些方法根本就没有被调用过。 (我复制了以下代码打印的内容)

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 的默认父类(super class)。您应该重写 getScope(EObject context, EReference ref) 并在 elsing 那里执行。或者您手动更改父类(super class)。顺便说一句,您可以使用 YourdslPackage.Literals 中的常量,而不是使用手动字符串常量。

关于eclipse - xtext 自定义作用域 : parameters of function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38636968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com