Skip to content

Commit 9490974

Browse files
committed
Add support for -XepOpt:NullAway:CustomContractAnnotations
1 parent 6a900a1 commit 9490974

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,4 @@ Each property (except for `severity`) maps to an `-XepOpt:NullAway:[propertyName
101101
| `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.
102102
| `acknowledgeAndroidRecent` | If set to true, treats `@RecentlyNullable` as `@Nullable`, and `@RecentlyNonNull` as `@NonNull`; requires that `acknowledgeRestrictiveAnnotations` is also set to true.
103103
| `checkContracts` | If set to true, NullAway will check `@Contract` annotations.
104+
| `customContractAnnotations` | A list of annotations that should be considered equivalent to `@Contract` annotations.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ open class NullAwayOptions internal constructor(
144144
@get:Input @get:Optional
145145
val checkContracts = objectFactory.property<Boolean>()
146146

147+
/** A list of annotations that should be considered equivalent to `@Contract` annotations; maps to `-XepOpt:NullAway:CustomContractAnnotations`. */
148+
@get:Input @get:Optional
149+
val customContractAnnotations = objectFactory.listProperty<String>()
150+
147151
internal fun asArguments(): Iterable<String> = sequenceOf(
148152
"-Xep:NullAway${severity.getOrElse(CheckSeverity.DEFAULT).asArg}",
149153
listOption("AnnotatedPackages", annotatedPackages),
@@ -166,7 +170,8 @@ open class NullAwayOptions internal constructor(
166170
stringOption("AutoFixSuppressionComment", autoFixSuppressionComment),
167171
booleanOption("HandleTestAssertionLibraries", handleTestAssertionLibraries),
168172
booleanOption("AcknowledgeAndroidRecent", acknowledgeAndroidRecent),
169-
booleanOption("CheckContracts", checkContracts)
173+
booleanOption("CheckContracts", checkContracts),
174+
listOption("CustomContractAnnotations", customContractAnnotations)
170175
)
171176
.filterNotNull()
172177
.asIterable()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ abstract class AbstractPluginIntegrationTest(
146146
handleTestAssertionLibraries.set(true)
147147
acknowledgeAndroidRecent.set(true)
148148
checkContracts.set(true)
149+
customContractAnnotations.add("com.example.Contract")
149150
}
150151
}
151152
""".trimIndent()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class GroovyDslIntegrationTest {
109109
handleTestAssertionLibraries = true
110110
acknowledgeAndroidRecent = true
111111
checkContracts = true
112+
customContractAnnotations = ["com.example.Contract"]
112113
}
113114
}
114115
""".trimIndent()

0 commit comments

Comments
 (0)