Skip to content

Commit

Permalink
Add support for -XepOpt:NullAway:JSpecifyMode
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroyer committed May 12, 2023
1 parent ff646ea commit 2b27487
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Each property (except for `severity`) maps to an `-XepOpt:NullAway:[propertyName
| `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`).
| `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).

### Methods

Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/net/ltgt/gradle/nullaway/NullAwayOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ open class NullAwayOptions internal constructor(
@get:Input @get:Optional
val customGeneratedCodeAnnotations = objectFactory.listProperty<String>()

/** If set to true, enables new checks based on JSpecify (like checks for generic types); maps to `-XepOpt:NullAway:JSpecifyMode`. */
// Note the differing case, for Groovy DSL, so it can be read as `jspecifyMode` and set as `jspecifyMode = true`
@get:JvmName("getJspecifyMode")
@get:Input
@get:Optional
val isJSpecifyMode = objectFactory.property<Boolean>()

/**
* Enable NullAway.
*
Expand Down Expand Up @@ -220,7 +227,8 @@ open class NullAwayOptions internal constructor(
listOption("CustomContractAnnotations", customContractAnnotations),
listOption("CustomNullableAnnotations", customNullableAnnotations),
listOption("CustomNonnullAnnotations", customNonnullAnnotations),
listOption("CustomGeneratedCodeAnnotations", customGeneratedCodeAnnotations)
listOption("CustomGeneratedCodeAnnotations", customGeneratedCodeAnnotations),
booleanOption("JSpecifyMode", isJSpecifyMode)
)
.filterNotNull()
.asIterable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class GroovyDslIntegrationTest {
customNullableAnnotations = ["com.example.CouldBeNull"]
customNonnullAnnotations = ["com.example.MustNotBeNull"]
customGeneratedCodeAnnotations = ["com.example.Generated"]
jspecifyMode = true
}
}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class NullAwayOptionsTest {
"NullAway:CustomContractAnnotations",
"NullAway:CustomNullableAnnotations",
"NullAway:CustomNonnullAnnotations",
"NullAway:CustomGeneratedCodeAnnotations"
"NullAway:CustomGeneratedCodeAnnotations",
"NullAway:JSpecifyMode"
)
}

Expand Down Expand Up @@ -98,6 +99,7 @@ class NullAwayOptionsTest {
doTestOptions { customNullableAnnotations.add("com.example.CouldBeNull") }
doTestOptions { customNonnullAnnotations.add("com.example.MustNotBeNull") }
doTestOptions { customGeneratedCodeAnnotations.add("com.example.Generated") }
doTestOptions { isJSpecifyMode.set(true) }

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

Expand Down Expand Up @@ -183,6 +186,7 @@ class NullAwayOptionsTest {
assertListOptionEqual(parsedOptions, "NullAway:CustomNullableAnnotations", options.customNullableAnnotations)
assertListOptionEqual(parsedOptions, "NullAway:CustomNonnullAnnotations", options.customNonnullAnnotations)
assertListOptionEqual(parsedOptions, "NullAway:CustomGeneratedCodeAnnotations", options.customGeneratedCodeAnnotations)
assertBooleanOptionEqual(parsedOptions, "NullAway:JSpecifyMode", options.isJSpecifyMode)

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 @@ -154,6 +154,7 @@ class NullAwayPluginIntegrationTest {
customContractAnnotations.add("com.example.Contract")
customNullableAnnotations.add("com.example.CouldBeNull")
customNonnullAnnotations.add("com.example.MustNotBeNull")
isJSpecifyMode.set(true)
}
}
""".trimIndent()
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 @@ -10,7 +10,7 @@ val testGradleVersion = System.getProperty("test.gradle-version", GradleVersion.
val errorproneVersion = System.getProperty("errorprone.version")!!

const val errorproneJavacVersion = "9+181-r4173-1"
const val nullawayVersion = "0.10.2"
const val nullawayVersion = "0.10.9"

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

Expand Down

0 comments on commit 2b27487

Please sign in to comment.