我正在寻找一个如何在用户定义的对象成员上实现代码完成的示例(在XText中).据我所知,我需要使用IScope,但所有这些连接在一起的方式还不清楚.
鉴于这trait是用户定义的类型,我如何构建语法来编码完成/验证String我输入时包含的方法name.?
trait String {
def toLowerCase(): String
def toUpperCase(): String
}
val name = new String()
name.toLowerCase()
Run Code Online (Sandbox Code Playgroud)
谢谢
Chr*_*ich 17
这在很大程度上取决于你的语法,你需要做什么来采用范围.我们假设你有一个语法
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] "()"
;
Run Code Online (Sandbox Code Playgroud)
然后你的scopeprovider会是这样的
public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
IScope scope_Call_op(Call call, EReference ref) {
return Scopes.scopeFor(call.getVar().getType().getOps());
}
}
Run Code Online (Sandbox Code Playgroud)
你可以在这里找到关于这个主题的博客系列:
https://web.archive.org/web/20130129085620/http://blogs.itemis.de/stundzig/archives/773