Class NoReflectionExtension
java.lang.Object
io.micronaut.errorprone.noreflection.gradle.NoReflectionExtension
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidallow(ReflectionCategory... categories) Allows the given categories throughout the project.voidAllows the named categories throughout the project.voidallowCalls(String... patterns) Allows the given calls throughout the project.voidAllows reflection in a class, or in a package and the packages below it.voidReports the given calls, as the categoryReflectionCategory.CUSTOM, besides the categories.voidForbids all reflection but in the classes and packages ofallowIn(String, String...), with no suppression honoured.abstract org.gradle.api.provider.SetProperty<ReflectionCategory> abstract org.gradle.api.provider.SetProperty<String> abstract org.gradle.api.provider.MapProperty<String, Set<ReflectionCategory>> abstract org.gradle.api.provider.SetProperty<String> abstract org.gradle.api.provider.SetProperty<String> abstract org.gradle.api.provider.Property<Boolean> abstract org.gradle.api.provider.Property<String> abstract org.gradle.api.provider.Property<Boolean> abstract org.gradle.api.provider.SetProperty<String> abstract org.gradle.api.provider.Property<net.ltgt.gradle.errorprone.CheckSeverity> abstract org.gradle.api.provider.Property<Boolean> voidSets the severity reflection is reported with.
-
Constructor Details
-
NoReflectionExtension
public NoReflectionExtension()
-
-
Method Details
-
getAllowed
- Returns:
- The categories allowed throughout the project, none by default
-
getAllowedCalls
- Returns:
- The calls allowed throughout the project, as
CallPatterns, none by default
-
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
- Returns:
- The calls reported besides the categories, as
CallPatterns, none by default
-
getSuppressible
- Returns:
- Whether a
@SuppressWarnings("NoReflection")in the source is honoured,trueby default
-
getForbidAll
- Returns:
- Whether all reflection is forbidden but in the classes and packages of
getAllowedIn(), with no suppression honoured,falseby default
-
getSeverity
public abstract org.gradle.api.provider.Property<net.ltgt.gradle.errorprone.CheckSeverity> getSeverity()- Returns:
- The severity reflection is reported with,
ERRORby default
-
getCheckedSourceSets
- Returns:
- The names of the source sets whose compilation is checked,
mainby default
-
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
- 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 = trueand ErrorProne on its annotation processor path
-
getCheckTests
- Returns:
- Whether every compilation is checked, the tests and the compile tasks of no source set included,
falseby default: a test that proves something was reached without reflection has to reach it somehow
-
allow
Allows the given categories throughout the project.- Parameters:
categories- The categories
-
allow
Allows the named categories throughout the project.- Parameters:
categories- The names of the categories, asReflectionCategoryspells them
-
allowCalls
Allows the given calls throughout the project.- Parameters:
patterns- The calls, asCallPatterns
-
allowIn
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
Reports the given calls, as the categoryReflectionCategory.CUSTOM, besides the categories.- Parameters:
patterns- The calls, asCallPatterns
-
forbidAll
public void forbidAll()Forbids all reflection but in the classes and packages ofallowIn(String, String...), with no suppression honoured. -
severity
Sets the severity reflection is reported with.- Parameters:
severity-ERRORorWARN
-