Skip to content

Commit 6e8303d

Browse files
committed
Add support for -XepOpt:NullAway:CustomGeneratedCodeAnnotations
1 parent ed3e39b commit 6e8303d

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ Each property (except for `severity`) maps to an `-XepOpt:NullAway:[propertyName
104104
| `customContractAnnotations` | A list of annotations that should be considered equivalent to `@Contract` annotations.
105105
| `customNullableAnnotations` | A list of annotations that should be considered equivalent to `@Nullable` annotations.
106106
| `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`).
107+
| `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`).

src/main/kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ open class NullAwayOptions internal constructor(
156156
@get:Input @get:Optional
157157
val customNonnullAnnotations = objectFactory.listProperty<String>()
158158

159+
/** 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`. */
160+
@get:Input @get:Optional
161+
val customGeneratedCodeAnnotations = objectFactory.listProperty<String>()
162+
159163
internal fun asArguments(): Iterable<String> = sequenceOf(
160164
"-Xep:NullAway${severity.getOrElse(CheckSeverity.DEFAULT).asArg}",
161165
listOption("AnnotatedPackages", annotatedPackages),
@@ -181,7 +185,8 @@ open class NullAwayOptions internal constructor(
181185
booleanOption("CheckContracts", checkContracts),
182186
listOption("CustomContractAnnotations", customContractAnnotations),
183187
listOption("CustomNullableAnnotations", customNullableAnnotations),
184-
listOption("CustomNonnullAnnotations", customNonnullAnnotations)
188+
listOption("CustomNonnullAnnotations", customNonnullAnnotations),
189+
listOption("CustomGeneratedCodeAnnotations", customGeneratedCodeAnnotations)
185190
)
186191
.filterNotNull()
187192
.asIterable()

src/test/kotlin/net/ltgt/gradle/nullaway/AbstractPluginIntegrationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ abstract class AbstractPluginIntegrationTest(
149149
customContractAnnotations.add("com.example.Contract")
150150
customNullableAnnotations.add("com.example.CouldBeNull")
151151
customNonnullAnnotations.add("com.example.MustNotBeNull")
152+
customGeneratedCodeAnnotations.add("com.example.Generated")
152153
}
153154
}
154155
""".trimIndent()

src/test/kotlin/net/ltgt/gradle/nullaway/GroovyDslIntegrationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class GroovyDslIntegrationTest {
112112
customContractAnnotations = ["com.example.Contract"]
113113
customNullableAnnotations = ["com.example.CouldBeNull"]
114114
customNonnullAnnotations = ["com.example.MustNotBeNull"]
115+
customGeneratedCodeAnnotations = ["com.example.Generated"]
115116
}
116117
}
117118
""".trimIndent()

src/test/kotlin/net/ltgt/gradle/nullaway/fixtures.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ val testGradleVersion = System.getProperty("test.gradle-version", GradleVersion.
99

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

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

0 commit comments

Comments
 (0)