简体   繁体   English

如何检查类是否有@CompileStatic 注释?

[英]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.

相关问题 如何在IntelliJ中搜索以给定注释注释的类? - How to search for classes annotated with a given annotation in IntelliJ? 使用正则表达式进行搜索-是否可以找到在其任何方法中都没有特定注释的类? - Search with regex - is there a way to find classes that do not have a certain annotation in any of its methods? 如何确保所有的包信息文件都具有相同的包级别注释? - How can I make sure that all the package-info files have same package level annotation? 通过IDEA结构化查找多次使用注释查找类 - Find classes using an annotation multiple times via IDEA structured find 如果我未能为公共字段和方法提供JavaDoc描述/注释,如何让IntelliJ给我一个警告? - How do I get IntelliJ to give me a warning if I have failed to provide JavaDoc description/annotation for public fields and methods? 当其他一些类有编译问题时,如何在IntelliJ中运行测试? - How to run tests in IntelliJ idea when some other classes have compilation problems? 如何在smartJ中的lib /目录中添加一个jar,并为我的web.xml提供类? - how to add a jar to my lib/ directory in intelliJ and have the classes available for my web.xml? 如何删除intellij @range 注释? - How to remove the intellij @range annotation? 为什么javax.annotation pacakge在jdk 8中没有类型注释? - Why javax.annotation pacakge dose not have type annotations in jdk 8? IntelliJ:有些类改变了消息 - IntelliJ: Some classes have changed message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM