简体   繁体   中英

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.

I'd like to know how that can be done either with IntelliJ or CodeNarc custom rule.

It's possible to use IntelliJ IDEA's Structural Search (Edit | Find | Search Structurally...) and its Structural Search Inspection for this purpose. Use a simple pattern like this:

class $X$ {}

File type Groovy , Context File . And add a Script Constraint like the following (click on Edit Variables... to add constraints):

com.intellij.codeInsight.AnnotationUtil.findAnnotation(X.parent, "groovy.transform.CompileStatic") == null

This should find all classes that do not have a @CompileStatic annotation

For completeness sake, Codenarc has a CompileStatic Rule since 1.4

CompileStatic Rule

Since CodeNarc 1.4

Enforces classes are annotated either with one of the @CompileStatic, >@GrailsCompileStatic or @CompileDynamic annotations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM