默认导入groovy [英] Default imports groovy

查看:100
本文介绍了默认导入groovy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否有可能在默认导入中拥有我们自己的包?有什么办法告诉groovy运行时使用我自己的包作为默认导入?

Is it possible to have our own package in default imports? Is there any way to tell the groovy runtime to use my own package as default import?

推荐答案

JIRA 涵盖了您的问题。

大部分内容在这里。

The bulk of it is here.

 class DefaultImportSourceUnitOperation extends SourceUnitOperation {
     public void call(SourceUnit source) throws CompilationFailedException {
         source.getAST().addImportPackage("pkg1.pgk2.pkg3.");
     } 
}

 class DefaultImportClassLoader extends GroovyClassLoader {
     protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource
 codeSource) {
         CompilationUnit cu = super.createCompilationUnit(config, codeSource)

         cu.addPhaseOperation(new DefaultImportSourceUnitOperation(), Phases.CONVERSION)

         return cu
     }
}

请务必不要忘记将添加到包装声明结束。

Be sure not to forget to add the . to the end of the package declaration.

Goodluck!

这篇关于默认导入groovy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆