如何在Groovy中将@CompileStatic批注添加到包作用域 [英] How add the @CompileStatic annotation to package scope in groovy

查看:525
本文介绍了如何在Groovy中将@CompileStatic批注添加到包作用域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在groovy中为整个包强制执行静态链接.静态链接需要使用CompileStatic .我想避免在每堂课上都重申这一点.如何将其作为包级注释应用.我在groovy中找不到对包级注释的引用.

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.

能否请您提供一段代码,说明如何将注释应用于包a.b.c?

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

推荐答案

这未经测试,但是我认为应该可以将

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.

类似:

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

这篇关于如何在Groovy中将@CompileStatic批注添加到包作用域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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