这在很大程度上取决于您的语法,您必须做什么才能采用范围界定。假设你有这样的语法
Model:
statements+=Statement+
;
Statement:
Trait | VarDef | Call
;
Trait:
"trait" name=ID "{"
ops+=Operation*
"}"
;
Operation:
"def" name=ID "()" ":" type=[Trait]
;
VarDef:
"val" name=ID "=" "new" type=[Trait] "()"
;
Call:
var=[VarDef] "." op=[Operation] "()"
;
那么你的 scopeprovider 看起来像
public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
IScope scope_Call_op(Call call, EReference ref) {
return Scopes.scopeFor(call.getVar().getType().getOps());
}
}
您可以在此处找到有关该主题的博客系列:
https://web.archive.org/web/20130129085620/http://blogs.itemis.de/stundzig/archives/773