Class NoReflectionExtension

java.lang.Object
io.micronaut.errorprone.noreflection.gradle.NoReflectionExtension

public abstract class NoReflectionExtension extends Object
How a project forbids reflection.
noReflection {
    // every category is reported by default, and a single call may be suppressed on the variable holding its result

    allow 'ENUM_CONSTANTS'                          // a category, throughout the project
    allowCalls 'java.lang.Class#getSimpleName'      // a method, throughout the project
    allowIn 'com.example.ReflectionAccess'          // any reflection, in a class
    allowIn 'com.example.handles.*', 'HANDLES'      // a category, in a package and the packages below it
    forbid 'com.example.LegacyReflector#*'          // the project's own reflective helpers, reported as CUSTOM

    suppressible = false                            // no suppression in the source is honoured
    forbidAll()                                     // nothing allowed but in allowIn, and nothing suppressible
    severity 'WARN'                                 // reported without failing the compilation
    errorProneVersion = '2.50.0'                    // the ErrorProne the plugin adds
    checkedSourceSets = ['main', 'integration']     // the source sets checked, main by default
    checkedTasks = ['compileGenerated']             // compile tasks of no source set checked, none by default
    checkTests = true                               // every compilation checked
}

The categories are the names of ReflectionCategory, calls are written as CallPatterns and classes and packages as AllowedScopes.

Since:
1.0.0
Author:
Denis Stepanov
  • Constructor Details

    • NoReflectionExtension

      public NoReflectionExtension()
  • Method Details

    • getAllowed

      public abstract org.gradle.api.provider.SetProperty<ReflectionCategory> getAllowed()
      Returns:
      The categories allowed throughout the project, none by default
    • getAllowedCalls

      public abstract org.gradle.api.provider.SetProperty<String> getAllowedCalls()
      Returns:
      The calls allowed throughout the project, as CallPatterns, none by default
    • getAllowedIn

      public abstract org.gradle.api.provider.MapProperty<String, Set<ReflectionCategory>> getAllowedIn()
      Returns:
      The classes and packages reflection is allowed in, by the class or the package followed by .*, with the categories allowed there, all of them when the set is empty; none by default
    • getForbiddenCalls

      public abstract org.gradle.api.provider.SetProperty<String> getForbiddenCalls()
      Returns:
      The calls reported besides the categories, as CallPatterns, none by default
    • getSuppressible

      public abstract org.gradle.api.provider.Property<Boolean> getSuppressible()
      Returns:
      Whether a @SuppressWarnings("NoReflection") in the source is honoured, true by default
    • getForbidAll

      public abstract org.gradle.api.provider.Property<Boolean> getForbidAll()
      Returns:
      Whether all reflection is forbidden but in the classes and packages of getAllowedIn(), with no suppression honoured, false by default
    • getSeverity

      public abstract org.gradle.api.provider.Property<net.ltgt.gradle.errorprone.CheckSeverity> getSeverity()
      Returns:
      The severity reflection is reported with, ERROR by default
    • getCheckedSourceSets

      public abstract org.gradle.api.provider.SetProperty<String> getCheckedSourceSets()
      Returns:
      The names of the source sets whose compilation is checked, main by default
    • getErrorProneVersion

      public abstract org.gradle.api.provider.Property<String> getErrorProneVersion()
      Returns:
      The version of ErrorProne added to the project, the one the plugin was built with by default; a version the project declares itself is resolved against it as any other dependency is
    • getCheckedTasks

      public abstract org.gradle.api.provider.SetProperty<String> getCheckedTasks()
      Returns:
      The names of the compile tasks that belong to no source set and are checked, none by default. The ErrorProne plugin turns ErrorProne on only for the compile tasks of source sets, so such a task also needs options.errorprone.enabled = true and ErrorProne on its annotation processor path
    • getCheckTests

      public abstract org.gradle.api.provider.Property<Boolean> getCheckTests()
      Returns:
      Whether every compilation is checked, the tests and the compile tasks of no source set included, false by default: a test that proves something was reached without reflection has to reach it somehow
    • allow

      public void allow(ReflectionCategory... categories)
      Allows the given categories throughout the project.
      Parameters:
      categories - The categories
    • allow

      public void allow(String... categories)
      Allows the named categories throughout the project.
      Parameters:
      categories - The names of the categories, as ReflectionCategory spells them
    • allowCalls

      public void allowCalls(String... patterns)
      Allows the given calls throughout the project.
      Parameters:
      patterns - The calls, as CallPatterns
    • allowIn

      public void allowIn(String scope, String... categories)
      Allows reflection in a class, or in a package and the packages below it. Naming the same scope again adds to the categories allowed there, and a scope allowed every category keeps them all.
      Parameters:
      scope - The class, or the package followed by .*
      categories - The categories allowed there, all of them when none is given
    • forbid

      public void forbid(String... patterns)
      Reports the given calls, as the category ReflectionCategory.CUSTOM, besides the categories.
      Parameters:
      patterns - The calls, as CallPatterns
    • forbidAll

      public void forbidAll()
      Forbids all reflection but in the classes and packages of allowIn(String, String...), with no suppression honoured.
    • severity

      public void severity(String severity)
      Sets the severity reflection is reported with.
      Parameters:
      severity - ERROR or WARN