Skip to content

Commit

Permalink
Add support for -XepOpt:NullAway:CustomGeneratedCodeAnnotations
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroyer committed Oct 10, 2022
1 parent ed3e39b commit 6e8303d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ Each property (except for `severity`) maps to an `-XepOpt:NullAway:[propertyName
| `customContractAnnotations` | A list of annotations that should be considered equivalent to `@Contract` annotations.
| `customNullableAnnotations` | A list of annotations that should be considered equivalent to `@Nullable` annotations.
| `customNonnullAnnotations` | A list of annotations that should be considered equivalent to `@NonNull` annotations, for the cases where NullAway cares about such annotations (see e.g. `acknowledgeRestrictiveAnnotations`).
| `customGeneratedCodeAnnotations` | A list of annotations that should be considered equivalent to `@Generated` annotations, for the cases where NullAway cares about such annotations (see e.g. `treatGeneratedAsUnannotated`).
7 changes: 6 additions & 1 deletion src/main/kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ open class NullAwayOptions internal constructor(
@get:Input @get:Optional
val customNonnullAnnotations = objectFactory.listProperty<String>()

/** A list of annotations that should be considered equivalent to `@Generated` annotations, for the cases where NullAway cares about such annotations (see e.g. [treatGeneratedAsUnannotated]); maps to `-XepOpt:NullAway:CustomGeneratedCodeAnnotations`. */
@get:Input @get:Optional
val customGeneratedCodeAnnotations = objectFactory.listProperty<String>()

internal fun asArguments(): Iterable<String> = sequenceOf(
"-Xep:NullAway${severity.getOrElse(CheckSeverity.DEFAULT).asArg}",
listOption("AnnotatedPackages", annotatedPackages),
Expand All @@ -181,7 +185,8 @@ open class NullAwayOptions internal constructor(
booleanOption("CheckContracts", checkContracts),
listOption("CustomContractAnnotations", customContractAnnotations),
listOption("CustomNullableAnnotations", customNullableAnnotations),
listOption("CustomNonnullAnnotations", customNonnullAnnotations)
listOption("CustomNonnullAnnotations", customNonnullAnnotations),
listOption("CustomGeneratedCodeAnnotations", customGeneratedCodeAnnotations)
)
.filterNotNull()
.asIterable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ abstract class AbstractPluginIntegrationTest(
customContractAnnotations.add("com.example.Contract")
customNullableAnnotations.add("com.example.CouldBeNull")
customNonnullAnnotations.add("com.example.MustNotBeNull")
customGeneratedCodeAnnotations.add("com.example.Generated")
}
}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class GroovyDslIntegrationTest {
customContractAnnotations = ["com.example.Contract"]
customNullableAnnotations = ["com.example.CouldBeNull"]
customNonnullAnnotations = ["com.example.MustNotBeNull"]
customGeneratedCodeAnnotations = ["com.example.Generated"]
}
}
""".trimIndent()
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/net/ltgt/gradle/nullaway/fixtures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ val testGradleVersion = System.getProperty("test.gradle-version", GradleVersion.

const val errorproneVersion = "2.10.0"
const val errorproneJavacVersion = "9+181-r4173-1"
const val nullawayVersion = "0.9.5"
const val nullawayVersion = "0.10.2"

const val FAILURE_SOURCE_COMPILATION_ERROR = "Failure.java:8: warning: [NullAway]"

Expand Down

0 comments on commit 6e8303d

Please sign in to comment.