Skip to content

Commit

Permalink
Add support for -XepOpt:NullAway:CustomContractAnnotations
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroyer committed Oct 20, 2021
1 parent 6a900a1 commit 9490974
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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 @@ -144,6 +144,10 @@ open class NullAwayOptions internal constructor(
@get:Input @get:Optional
val checkContracts = objectFactory.property<Boolean>()

/** 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<String>()

internal fun asArguments(): Iterable<String> = sequenceOf(
"-Xep:NullAway${severity.getOrElse(CheckSeverity.DEFAULT).asArg}",
listOption("AnnotatedPackages", annotatedPackages),
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ abstract class AbstractPluginIntegrationTest(
handleTestAssertionLibraries.set(true)
acknowledgeAndroidRecent.set(true)
checkContracts.set(true)
customContractAnnotations.add("com.example.Contract")
}
}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class GroovyDslIntegrationTest {
handleTestAssertionLibraries = true
acknowledgeAndroidRecent = true
checkContracts = true
customContractAnnotations = ["com.example.Contract"]
}
}
""".trimIndent()
Expand Down

0 comments on commit 9490974

Please sign in to comment.