Skip to content

Commit

Permalink
Jspecify nullmarked (#600)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Nov 12, 2024
1 parent 1cba1dc commit 941c654
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/rewrite/jspecify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ recipeList:
oldFullyQualifiedTypeName: javax.annotation.Nonnull
newFullyQualifiedTypeName: org.jspecify.annotations.NonNull
ignoreDefinition: true
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: javax.annotation.ParametersAreNonnullByDefault
newFullyQualifiedTypeName: org.jspecify.annotation.NullMarked
ignoreDefinition: true
- org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType:
annotationType: org.jspecify.annotations.*
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ class Bar {
}
}
"""
),
// package-info.java
java(
"""
@ParametersAreNonnullByDefault
package org.openrewrite.example;
import javax.annotation.ParametersAreNonnullByDefault;
""",
"""
@NullMarked
package org.openrewrite.example;
import org.jspecify.annotation.NullMarked;
"""
)
),
//language=xml
Expand Down Expand Up @@ -136,7 +151,7 @@ void migrateFromJakartaAnnotationApiToJspecify() {
"""
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
public class Test {
@Nonnull
public String field1;
Expand All @@ -145,7 +160,7 @@ public class Test {
@Nullable
public Foo.Bar foobar;
}
interface Foo {
class Bar {
@Nonnull
Expand All @@ -156,16 +171,16 @@ class Bar {
"""
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
public class Test {
@NonNull
public String field1;
@Nullable
public String field2;
public Foo.@Nullable Bar foobar;
}
interface Foo {
class Bar {
@NonNull
Expand Down Expand Up @@ -228,7 +243,7 @@ void migrateFromJetbrainsAnnotationsToJspecify() {
"""
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Test {
@NotNull
public String field1;
Expand All @@ -237,7 +252,7 @@ public class Test {
@Nullable
public Foo.Bar foobar;
}
interface Foo {
class Bar {
@NotNull
Expand All @@ -248,16 +263,16 @@ class Bar {
"""
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
public class Test {
@NonNull
public String field1;
@Nullable
public String field2;
public Foo.@Nullable Bar foobar;
}
interface Foo {
class Bar {
@NonNull
Expand Down

0 comments on commit 941c654

Please sign in to comment.