Skip to content

Commit

Permalink
Add support for -XepOpt:NullAway:Custom{Nullable,Nonnull}Annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroyer committed Jan 21, 2022
1 parent b6401ef commit db76a8b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ Each property (except for `severity`) maps to an `-XepOpt:NullAway:[propertyName
| `acknowledgeAndroidRecent` | If set to true, treats `@RecentlyNullable` as `@Nullable`, and `@RecentlyNonNull` as `@NonNull`; requires that `acknowledgeRestrictiveAnnotations` is also set to true.
| `checkContracts` | If set to true, NullAway will check `@Contract` annotations.
| `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`).
12 changes: 11 additions & 1 deletion src/main/kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ open class NullAwayOptions internal constructor(
@get:Input @get:Optional
val customContractAnnotations = objectFactory.listProperty<String>()

/** A list of annotations that should be considered equivalent to `@Nullable` annotations. */
@get:Input @get:Optional
val customNullableAnnotations = objectFactory.listProperty<String>()

/** 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`). */
@get:Input @get:Optional
val customNonnullAnnotations = objectFactory.listProperty<String>()

internal fun asArguments(): Iterable<String> = sequenceOf(
"-Xep:NullAway${severity.getOrElse(CheckSeverity.DEFAULT).asArg}",
listOption("AnnotatedPackages", annotatedPackages),
Expand All @@ -171,7 +179,9 @@ open class NullAwayOptions internal constructor(
booleanOption("HandleTestAssertionLibraries", handleTestAssertionLibraries),
booleanOption("AcknowledgeAndroidRecent", acknowledgeAndroidRecent),
booleanOption("CheckContracts", checkContracts),
listOption("CustomContractAnnotations", customContractAnnotations)
listOption("CustomContractAnnotations", customContractAnnotations),
listOption("CustomNullableAnnotations", customNullableAnnotations),
listOption("CustomNonnullAnnotations", customNonnullAnnotations)
)
.filterNotNull()
.asIterable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ abstract class AbstractPluginIntegrationTest(
acknowledgeAndroidRecent.set(true)
checkContracts.set(true)
customContractAnnotations.add("com.example.Contract")
customNullableAnnotations.add("com.example.CouldBeNull")
customNonnullAnnotations.add("com.example.MustNotBeNull")
}
}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class GroovyDslIntegrationTest {
acknowledgeAndroidRecent = true
checkContracts = true
customContractAnnotations = ["com.example.Contract"]
customNullableAnnotations = ["com.example.CouldBeNull"]
customNonnullAnnotations = ["com.example.MustNotBeNull"]
}
}
""".trimIndent()
Expand Down

0 comments on commit db76a8b

Please sign in to comment.