我的问题看起来像这样:我用Groovy编写了DSL,现在我想在IntelliJ中完成代码。我想要实现的是这样的:
foo("aa").is {
bar("bb").is {
foobar("cc")
}
}
所以我写了一个.gdsl文件
def globalContext = context(scope: scriptScope())
contributor(globalContext) {
method name: "foo", type: "A", params: [name:"java.lang.String"]
}
def aContext = context(ctype:"A")
contributor(aContext) {
method name: "is", type: "A", params: [closure:"groovy.lang.Closure"]
}
def bContext = context(ctype:"B")
contributor(bContext) {
method name: "is", type: "B", params: [closure:"groovy.lang.Closure"]
}
def closureContext = context(scope: closureScope())
contributor(closureContext, {
def call = enclosingCall("is")
if (call) {
def callingMethod = call.bind()
if ("A".equals(callingMethod?.returnType?.name)) {
method name: "bar", type: "B", params:
[name:"java.lang.String"]
}
else if ("B".equals(callingMethod?.returnType?.name)) {
method name: "foobar", type: "C", params:
[name:"java.lang.String"]
}
}
})
一切似乎都有效,直到我完成bar.is
的右括号为止,这时Intellij突然停下来理解bar
关键字。你能请教吗?