How add the @CompileStatic annotation to package scope in groovy

不打扰是莪最后的温柔 提交于 2019-12-24 18:23:27

问题


I would like to enforce static linking for a whole package in groovy. Static linking requires use of CompileStatic. I would like to avoid restating this on every class. How can I apply this as a package-level annotation. I have found no reference to package-level annotations in groovy.

Can you please provide a piece of code that shows how to apply the annotation to a package a.b.c?


回答1:


This is untested, but I think it should be possible to create a nice combination of a configurationScript, a Source aware customizer and a AST transformation customizer explained in dsl docs.

something like:

withConfig(configuration) {
    source(unitValidator: { unit -> unit.AST.classes.any { it.packageName== 'a.b.c' } }) {
        ast(CompileStatic) 
    }
}


来源:https://stackoverflow.com/questions/46229495/how-add-the-compilestatic-annotation-to-package-scope-in-groovy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!