0

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.

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
rvazquezglez
  • 2,284
  • 28
  • 40
  • After a bit of research, there's this compiler configuration that can add `@CompileStatic` at compile time https://stackoverflow.com/a/46241654/1195507 – rvazquezglez Jun 03 '18 at 03:18

2 Answers2

1

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

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
1

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.

Leonard Brünings
  • 12,408
  • 1
  • 46
  • 66