[英]How to check classes have @CompileStatic annotation?
I want to perform an automated static check analysis on my Groovy code to identify which clases doesn't have the @CompileStatic
annotation.我想对我的 Groovy 代码执行自动静态检查分析,以确定哪些类没有
@CompileStatic
注释。
I'd like to know how that can be done either with IntelliJ or CodeNarc custom rule.我想知道如何使用 IntelliJ 或 CodeNarc 自定义规则来完成。
It's possible to use IntelliJ IDEA's Structural Search (Edit | Find | Search Structurally...) and its Structural Search Inspection for this purpose.为此,可以使用 IntelliJ IDEA 的结构搜索(编辑 | 查找 | 结构搜索...)及其结构搜索检查。 Use a simple pattern like this:
使用这样的简单模式:
class $X$ {}
File type Groovy
, Context File
.文件类型
Groovy
,上下文File
。 And add a Script Constraint like the following (click on Edit Variables...
to add constraints):并添加如下所示的脚本约束(单击“
Edit Variables...
以添加约束):
com.intellij.codeInsight.AnnotationUtil.findAnnotation(X.parent, "groovy.transform.CompileStatic") == null
This should find all classes that do not have a @CompileStatic
annotation这应该找到所有没有
@CompileStatic
注释的类
For completeness sake, Codenarc has a CompileStatic Rule since 1.4为了完整起见,Codenarc 从 1.4 开始就有一个CompileStatic 规则
CompileStatic Rule
编译静态规则
Since CodeNarc 1.4
自 CodeNarc 1.4
Enforces classes are annotated either with one of the @CompileStatic, >@GrailsCompileStatic or @CompileDynamic annotations.
Enforces 类使用 @CompileStatic、>@GrailsCompileStatic 或 @CompileDynamic 注释之一进行注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.