我的Groovy脚本中有一个隐式变量" services ",它的作用是在注册表中查找服务。
我可以用以下语法调用它:
def myService = services.lookup 'com.test.MyService'查找方法的实现并不返回MyService的实例,而是一个特殊的GroovyObject,它将丢失的方法委托给服务。
我想告诉Eclipse,对MyService的调用应该委托给MyService,以便将来自myService的所有方法添加到自动完成列表中。但是,我没有成功地用DSLD定义实现它。
有可能实现这样的行为吗?
发布于 2018-06-19 17:43:47
我使用了两项贡献:
简化版本:
contribute(isMyDSL() & currentType('ServiceProxy') & bind(exprs: assignedVariable(currentType()))) {
def name = exprs[0].leftExpression.name
def classType - exprs[0].arguments.getExpression(0).text /* Introspecting MethodCall */
def services = wormhole.services
if (!services) {
services = [:]
wormhole.services = services
}
services[name] = classType
}
contribute(isMyDSL() & isThisType()) {
wormhole.properties?.each { name, type ->
property name:name, type:type, doc:"OSGI Service: ${type}"
}
}https://stackoverflow.com/questions/50879689
复制相似问题