Skip to content

Commit

Permalink
Add support for -XepOpt:NullAway:ExtraFuturesClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroyer committed Feb 16, 2024
1 parent d205e78 commit 863cebe
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Each property (except for `severity`) maps to an `-XepOpt:NullAway:[propertyName
| `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`).
| `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`).
| `jspecifyMode` | (`isJSpecifyMode` with Kotlin DSL) If set to true, enables new checks based on JSpecify (like checks for generic types).
| `extraFuturesClasses` | A list of classes to be treated equivalently to Guava `Futures` and `FluentFuture`; this special support will likely be removed once NullAway's JSpecify support is more complete.

### Methods

Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ open class NullAwayOptions internal constructor(
@get:Optional
val isJSpecifyMode = objectFactory.property<Boolean>()

/**
* A list of classes to be treated equivalently to Guava `Futures` and `FluentFuture`; maps to `-XepOpt:NullAway:ExtraFuturesClasses`.
*
* This special support will likely be removed once NullAway's JSpecify support is more complete.
*/
@get:Input @get:Optional
val extraFuturesClasses = objectFactory.listProperty<String>()

/**
* Enable NullAway.
*
Expand Down Expand Up @@ -229,6 +237,7 @@ open class NullAwayOptions internal constructor(
listOption("CustomNonnullAnnotations", customNonnullAnnotations),
listOption("CustomGeneratedCodeAnnotations", customGeneratedCodeAnnotations),
booleanOption("JSpecifyMode", isJSpecifyMode),
listOption("ExtraFuturesClasses", extraFuturesClasses),
)
.filterNotNull()
.asIterable()
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/net/ltgt/gradle/nullaway/Fixtures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ val testGradleVersion = System.getProperty("test.gradle-version", GradleVersion.

val errorproneVersion = System.getProperty("errorprone.version")!!

const val nullawayVersion = "0.10.10"
const val nullawayVersion = "0.10.23"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class GroovyDslIntegrationTest {
customNonnullAnnotations = ["com.example.MustNotBeNull"]
customGeneratedCodeAnnotations = ["com.example.Generated"]
jspecifyMode = true
extraFuturesClasses = ["com.example.Future"]
}
}
""".trimIndent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class NullAwayOptionsTest {
"NullAway:CustomNonnullAnnotations",
"NullAway:CustomGeneratedCodeAnnotations",
"NullAway:JSpecifyMode",
"NullAway:ExtraFuturesClasses",
)
}

Expand Down Expand Up @@ -95,6 +96,7 @@ class NullAwayOptionsTest {
doTestOptions { customNonnullAnnotations.add("com.example.MustNotBeNull") }
doTestOptions { customGeneratedCodeAnnotations.add("com.example.Generated") }
doTestOptions { isJSpecifyMode.set(true) }
doTestOptions { extraFuturesClasses.add("com.example.Future") }

doTestOptions {
enable()
Expand Down Expand Up @@ -124,6 +126,7 @@ class NullAwayOptionsTest {
customNonnullAnnotations.add("com.example.MustNotBeNull")
customGeneratedCodeAnnotations.add("com.example.Generated")
isJSpecifyMode.set(true)
extraFuturesClasses.add("com.example.Future")
}
}

Expand Down Expand Up @@ -182,6 +185,7 @@ class NullAwayOptionsTest {
assertListOptionEqual(parsedOptions, "NullAway:CustomNonnullAnnotations", options.customNonnullAnnotations)
assertListOptionEqual(parsedOptions, "NullAway:CustomGeneratedCodeAnnotations", options.customGeneratedCodeAnnotations)
assertBooleanOptionEqual(parsedOptions, "NullAway:JSpecifyMode", options.isJSpecifyMode)
assertListOptionEqual(parsedOptions, "NullAway:ExtraFuturesClasses", options.extraFuturesClasses)

assertThat(parsedOptions.flags.flagsMap.keys - ALL_NULLAWAY_OPTION_NAMES).isEmpty()
assertThat(parsedOptions.remainingArgs).isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class NullAwayPluginIntegrationTest {
customNullableAnnotations.add("com.example.CouldBeNull")
customNonnullAnnotations.add("com.example.MustNotBeNull")
isJSpecifyMode.set(true)
extraFuturesClasses.add("com.example.Future")
}
}
""".trimIndent(),
Expand Down

0 comments on commit 863cebe

Please sign in to comment.