Skip to content

Commit 941c654

Browse files
bwijsmullerBraam Wijsmullertimtebeek
authored
Jspecify nullmarked (#600)
* Test for the jspecify NullMarked migration * Migration for NullMarked instead of ParametersAreNonnullByDefault --------- Co-authored-by: Braam Wijsmuller <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
1 parent 1cba1dc commit 941c654

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/main/resources/META-INF/rewrite/jspecify.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ recipeList:
4747
oldFullyQualifiedTypeName: javax.annotation.Nonnull
4848
newFullyQualifiedTypeName: org.jspecify.annotations.NonNull
4949
ignoreDefinition: true
50+
- org.openrewrite.java.ChangeType:
51+
oldFullyQualifiedTypeName: javax.annotation.ParametersAreNonnullByDefault
52+
newFullyQualifiedTypeName: org.jspecify.annotation.NullMarked
53+
ignoreDefinition: true
5054
- org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType:
5155
annotationType: org.jspecify.annotations.*
5256
---

src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ class Bar {
8282
}
8383
}
8484
"""
85+
),
86+
// package-info.java
87+
java(
88+
"""
89+
@ParametersAreNonnullByDefault
90+
package org.openrewrite.example;
91+
92+
import javax.annotation.ParametersAreNonnullByDefault;
93+
""",
94+
"""
95+
@NullMarked
96+
package org.openrewrite.example;
97+
98+
import org.jspecify.annotation.NullMarked;
99+
"""
85100
)
86101
),
87102
//language=xml
@@ -136,7 +151,7 @@ void migrateFromJakartaAnnotationApiToJspecify() {
136151
"""
137152
import jakarta.annotation.Nonnull;
138153
import jakarta.annotation.Nullable;
139-
154+
140155
public class Test {
141156
@Nonnull
142157
public String field1;
@@ -145,7 +160,7 @@ public class Test {
145160
@Nullable
146161
public Foo.Bar foobar;
147162
}
148-
163+
149164
interface Foo {
150165
class Bar {
151166
@Nonnull
@@ -156,16 +171,16 @@ class Bar {
156171
"""
157172
import org.jspecify.annotations.NonNull;
158173
import org.jspecify.annotations.Nullable;
159-
174+
160175
public class Test {
161176
@NonNull
162177
public String field1;
163178
@Nullable
164179
public String field2;
165-
180+
166181
public Foo.@Nullable Bar foobar;
167182
}
168-
183+
169184
interface Foo {
170185
class Bar {
171186
@NonNull
@@ -228,7 +243,7 @@ void migrateFromJetbrainsAnnotationsToJspecify() {
228243
"""
229244
import org.jetbrains.annotations.NotNull;
230245
import org.jetbrains.annotations.Nullable;
231-
246+
232247
public class Test {
233248
@NotNull
234249
public String field1;
@@ -237,7 +252,7 @@ public class Test {
237252
@Nullable
238253
public Foo.Bar foobar;
239254
}
240-
255+
241256
interface Foo {
242257
class Bar {
243258
@NotNull
@@ -248,16 +263,16 @@ class Bar {
248263
"""
249264
import org.jspecify.annotations.NonNull;
250265
import org.jspecify.annotations.Nullable;
251-
266+
252267
public class Test {
253268
@NonNull
254269
public String field1;
255270
@Nullable
256271
public String field2;
257-
272+
258273
public Foo.@Nullable Bar foobar;
259274
}
260-
275+
261276
interface Foo {
262277
class Bar {
263278
@NonNull

0 commit comments

Comments
 (0)