我想对我的 Groovy 代码执行自动静态检查分析,以确定哪些类没有@CompileStatic
注释。
我想知道如何使用 IntelliJ 或 CodeNarc 自定义规则来完成。
我想对我的 Groovy 代码执行自动静态检查分析,以确定哪些类没有@CompileStatic
注释。
我想知道如何使用 IntelliJ 或 CodeNarc 自定义规则来完成。
为此,可以使用 IntelliJ IDEA 的结构搜索(编辑 | 查找 | 结构搜索...)及其结构搜索检查。使用这样的简单模式:
class $X$ {}
文件类型Groovy
,上下文File
。并添加如下脚本约束(单击Edit Variables...
以添加约束):
com.intellij.codeInsight.AnnotationUtil.findAnnotation(X.parent, "groovy.transform.CompileStatic") == null
这应该找到所有没有@CompileStatic
注释的类
为了完整起见,Codenarc从 1.4开始就有一个CompileStatic 规则
编译静态规则
自 CodeNarc 1.4 起
强制类使用@CompileStatic、>@GrailsCompileStatic 或@CompileDynamic 注释之一进行注释。