From 9490974deaeecf4dfa1e4a972db52d5463fdc880 Mon Sep 17 00:00:00 2001 From: Thomas Broyer Date: Thu, 1 Jul 2021 10:24:29 +0200 Subject: [PATCH] Add support for -XepOpt:NullAway:CustomContractAnnotations --- README.md | 1 + .../kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt | 7 ++++++- .../ltgt/gradle/nullaway/AbstractPluginIntegrationTest.kt | 1 + .../net/ltgt/gradle/nullaway/GroovyDslIntegrationTest.kt | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c1b181f..d7907ff 100644 --- a/README.md +++ b/README.md @@ -101,3 +101,4 @@ Each property (except for `severity`) maps to an `-XepOpt:NullAway:[propertyName | `exhaustiveOverride` | (`isExhaustiveOverride` with Kotlin DSL) If set to true, NullAway will check every method to see whether or not it overrides a method of a super-type, rather than relying only on the `@Override` annotation. | `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. diff --git a/src/main/kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt b/src/main/kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt index ce04b4b..78c2162 100644 --- a/src/main/kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt +++ b/src/main/kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt @@ -144,6 +144,10 @@ open class NullAwayOptions internal constructor( @get:Input @get:Optional val checkContracts = objectFactory.property() + /** A list of annotations that should be considered equivalent to `@Contract` annotations; maps to `-XepOpt:NullAway:CustomContractAnnotations`. */ + @get:Input @get:Optional + val customContractAnnotations = objectFactory.listProperty() + internal fun asArguments(): Iterable = sequenceOf( "-Xep:NullAway${severity.getOrElse(CheckSeverity.DEFAULT).asArg}", listOption("AnnotatedPackages", annotatedPackages), @@ -166,7 +170,8 @@ open class NullAwayOptions internal constructor( stringOption("AutoFixSuppressionComment", autoFixSuppressionComment), booleanOption("HandleTestAssertionLibraries", handleTestAssertionLibraries), booleanOption("AcknowledgeAndroidRecent", acknowledgeAndroidRecent), - booleanOption("CheckContracts", checkContracts) + booleanOption("CheckContracts", checkContracts), + listOption("CustomContractAnnotations", customContractAnnotations) ) .filterNotNull() .asIterable() diff --git a/src/test/kotlin/net/ltgt/gradle/nullaway/AbstractPluginIntegrationTest.kt b/src/test/kotlin/net/ltgt/gradle/nullaway/AbstractPluginIntegrationTest.kt index 8150278..36f3b8d 100644 --- a/src/test/kotlin/net/ltgt/gradle/nullaway/AbstractPluginIntegrationTest.kt +++ b/src/test/kotlin/net/ltgt/gradle/nullaway/AbstractPluginIntegrationTest.kt @@ -146,6 +146,7 @@ abstract class AbstractPluginIntegrationTest( handleTestAssertionLibraries.set(true) acknowledgeAndroidRecent.set(true) checkContracts.set(true) + customContractAnnotations.add("com.example.Contract") } } """.trimIndent() diff --git a/src/test/kotlin/net/ltgt/gradle/nullaway/GroovyDslIntegrationTest.kt b/src/test/kotlin/net/ltgt/gradle/nullaway/GroovyDslIntegrationTest.kt index 3e95d48..9b35e23 100644 --- a/src/test/kotlin/net/ltgt/gradle/nullaway/GroovyDslIntegrationTest.kt +++ b/src/test/kotlin/net/ltgt/gradle/nullaway/GroovyDslIntegrationTest.kt @@ -109,6 +109,7 @@ class GroovyDslIntegrationTest { handleTestAssertionLibraries = true acknowledgeAndroidRecent = true checkContracts = true + customContractAnnotations = ["com.example.Contract"] } } """.trimIndent()