From bf233bfc94021e7f635c1ba201eebc7e6a4e4bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Schn=C3=A9ider?= Date: Thu, 15 Aug 2024 04:19:01 +0000 Subject: [PATCH 1/2] Migrate to JSpecify from OpenRewrite JSR-305 meta-annotations Use this link to re-run the recipe: https://app.moderne.io/builder/gW3xaSLWV?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne --- .../java/testing/assertj/SimplifyAssertJAssertion.java | 2 +- .../testing/assertj/SimplifyChainedAssertJAssertion.java | 2 +- .../org/openrewrite/java/testing/assertj/package-info.java | 4 ++-- .../java/testing/cleanup/SimplifyTestThrows.java | 2 +- .../java/testing/cleanup/TestsShouldIncludeAssertions.java | 2 +- .../java/testing/cleanup/TestsShouldNotBePublic.java | 2 +- .../org/openrewrite/java/testing/cleanup/package-info.java | 4 ++-- .../java/testing/hamcrest/HamcrestMatcherToAssertJ.java | 2 +- .../java/testing/hamcrest/HamcrestNotMatcherToAssertJ.java | 2 +- .../org/openrewrite/java/testing/hamcrest/package-info.java | 4 ++-- .../java/testing/jmockit/JMockitBlockRewriter.java | 2 +- .../org/openrewrite/java/testing/jmockit/package-info.java | 4 ++-- .../java/testing/junit5/AddJupiterDependencies.java | 2 +- .../openrewrite/java/testing/junit5/AddMissingNested.java | 2 +- .../openrewrite/java/testing/junit5/AssertToAssertions.java | 2 +- .../testing/junit5/ExpectedExceptionToAssertThrows.java | 2 +- .../java/testing/junit5/GradleUseJunitJupiter.java | 2 +- .../testing/junit5/JUnitParamsRunnerToParameterized.java | 2 +- .../java/testing/junit5/MigrateJUnitTestCase.java | 4 ++-- .../testing/junit5/ParameterizedRunnerToParameterized.java | 2 +- .../openrewrite/java/testing/junit5/RunnerToExtension.java | 2 +- .../java/testing/junit5/TemporaryFolderToTempDir.java | 2 +- .../openrewrite/java/testing/junit5/TestRuleToTestInfo.java | 2 +- .../java/testing/junit5/UpdateMockWebServer.java | 2 +- .../java/testing/junit5/UpdateTestAnnotation.java | 2 +- .../openrewrite/java/testing/junit5/UseTestMethodOrder.java | 2 +- .../org/openrewrite/java/testing/junit5/package-info.java | 4 ++-- .../org/openrewrite/java/testing/mockito/AnyToNullable.java | 2 +- .../java/testing/mockito/CleanupMockitoImports.java | 2 +- .../testing/mockito/PowerMockitoMockStaticToMockito.java | 6 +++--- .../org/openrewrite/java/testing/mockito/package-info.java | 4 ++-- .../java/testing/testcontainers/package-info.java | 4 ++-- 32 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertion.java b/src/main/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertion.java index 56a787bad..1d3685955 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertion.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/SimplifyAssertJAssertion.java @@ -17,11 +17,11 @@ import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; diff --git a/src/main/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertion.java b/src/main/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertion.java index d84b1179a..bfbf9fc43 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertion.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/SimplifyChainedAssertJAssertion.java @@ -17,11 +17,11 @@ import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; diff --git a/src/main/java/org/openrewrite/java/testing/assertj/package-info.java b/src/main/java/org/openrewrite/java/testing/assertj/package-info.java index 6f32eb963..44f3754e0 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/package-info.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/package-info.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@NonNullApi +@NullMarked package org.openrewrite.java.testing.assertj; -import org.openrewrite.internal.lang.NonNullApi; +import org.jspecify.annotations.NullMarked; diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/SimplifyTestThrows.java b/src/main/java/org/openrewrite/java/testing/cleanup/SimplifyTestThrows.java index 2c97e26bf..a33911d34 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/SimplifyTestThrows.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/SimplifyTestThrows.java @@ -15,8 +15,8 @@ */ package org.openrewrite.java.testing.cleanup; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.search.UsesType; import org.openrewrite.java.tree.*; diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java index de89e78f6..82e4290f0 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldIncludeAssertions.java @@ -17,8 +17,8 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java index 7ea4850ce..c8dfe2387 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java @@ -19,12 +19,12 @@ import lombok.EqualsAndHashCode; import lombok.RequiredArgsConstructor; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.ScanningRecipe; import org.openrewrite.TreeVisitor; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.ChangeMethodAccessLevelVisitor; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.MethodMatcher; diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/package-info.java b/src/main/java/org/openrewrite/java/testing/cleanup/package-info.java index 100496815..59fc9b2c0 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/package-info.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/package-info.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@NonNullApi +@NullMarked package org.openrewrite.java.testing.cleanup; -import org.openrewrite.internal.lang.NonNullApi; +import org.jspecify.annotations.NullMarked; diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJ.java b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJ.java index 8f0a6958c..345373b61 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJ.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestMatcherToAssertJ.java @@ -17,8 +17,8 @@ import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJ.java b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJ.java index eaa9b8dbe..1f235ea35 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJ.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/HamcrestNotMatcherToAssertJ.java @@ -17,8 +17,8 @@ import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; diff --git a/src/main/java/org/openrewrite/java/testing/hamcrest/package-info.java b/src/main/java/org/openrewrite/java/testing/hamcrest/package-info.java index 7f9f59ac6..e6e451241 100644 --- a/src/main/java/org/openrewrite/java/testing/hamcrest/package-info.java +++ b/src/main/java/org/openrewrite/java/testing/hamcrest/package-info.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@NonNullApi +@NullMarked @NonNullFields package org.openrewrite.java.testing.hamcrest; -import org.openrewrite.internal.lang.NonNullApi; +import org.jspecify.annotations.NullMarked; import org.openrewrite.internal.lang.NonNullFields; diff --git a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitBlockRewriter.java b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitBlockRewriter.java index 5544bb5d3..4dc1df56f 100644 --- a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitBlockRewriter.java +++ b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitBlockRewriter.java @@ -18,9 +18,9 @@ import lombok.AccessLevel; import lombok.Data; import lombok.Setter; +import org.jspecify.annotations.Nullable; import org.openrewrite.Cursor; import org.openrewrite.ExecutionContext; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; diff --git a/src/main/java/org/openrewrite/java/testing/jmockit/package-info.java b/src/main/java/org/openrewrite/java/testing/jmockit/package-info.java index 85365fe33..af3338fa5 100644 --- a/src/main/java/org/openrewrite/java/testing/jmockit/package-info.java +++ b/src/main/java/org/openrewrite/java/testing/jmockit/package-info.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@NonNullApi +@NullMarked package org.openrewrite.java.testing.jmockit; -import org.openrewrite.internal.lang.NonNullApi; +import org.jspecify.annotations.NullMarked; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AddJupiterDependencies.java b/src/main/java/org/openrewrite/java/testing/junit5/AddJupiterDependencies.java index 928a7646f..889ec1a9d 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/AddJupiterDependencies.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AddJupiterDependencies.java @@ -17,12 +17,12 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; import org.openrewrite.gradle.marker.GradleDependencyConfiguration; import org.openrewrite.gradle.marker.GradleProject; import org.openrewrite.groovy.GroovyIsoVisitor; import org.openrewrite.groovy.tree.G; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.dependencies.AddDependency; import org.openrewrite.maven.MavenIsoVisitor; import org.openrewrite.maven.tree.ResolvedDependency; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java b/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java index 547b25a08..844d832e4 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AddMissingNested.java @@ -17,11 +17,11 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.NonNull; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.NonNull; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java b/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java index 497713472..4c9f4caaa 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java @@ -15,12 +15,12 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.ChangeMethodTargetToStatic; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.search.UsesType; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java index 2e04cc991..f05e4084e 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java @@ -15,9 +15,9 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/GradleUseJunitJupiter.java b/src/main/java/org/openrewrite/java/testing/junit5/GradleUseJunitJupiter.java index 995408803..8fbe83308 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/GradleUseJunitJupiter.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/GradleUseJunitJupiter.java @@ -17,6 +17,7 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; @@ -25,7 +26,6 @@ import org.openrewrite.groovy.GroovyIsoVisitor; import org.openrewrite.groovy.tree.G; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.MethodMatcher; import org.openrewrite.java.tree.J; import org.openrewrite.java.tree.JavaType; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java index 420046147..eccdb8fef 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java @@ -15,9 +15,9 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.*; import org.openrewrite.java.search.UsesType; import org.openrewrite.java.tree.Expression; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java b/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java index ea1e1870c..0e07eed51 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java @@ -15,12 +15,12 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.*; import org.openrewrite.java.search.FindAnnotations; import org.openrewrite.java.search.UsesType; @@ -39,7 +39,7 @@ public class MigrateJUnitTestCase extends Recipe { private static final AnnotationMatcher JUNIT_AFTER_ANNOTATION_MATCHER = new AnnotationMatcher("@org.junit.*After*"); private static final AnnotationMatcher JUNIT_BEFORE_ANNOTATION_MATCHER = new AnnotationMatcher("@org.junit.*Before*"); - private static boolean isSupertypeTestCase(@Nullable JavaType.FullyQualified fullyQualified) { + private static boolean isSupertypeTestCase(JavaType.@Nullable FullyQualified fullyQualified) { if (fullyQualified == null || fullyQualified.getSupertype() == null || "java.lang.Object".equals(fullyQualified.getFullyQualifiedName())) { return false; } diff --git a/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java b/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java index fa8d51a3e..269390a54 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java @@ -15,9 +15,9 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.*; import org.openrewrite.java.search.UsesType; import org.openrewrite.java.tree.*; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/RunnerToExtension.java b/src/main/java/org/openrewrite/java/testing/junit5/RunnerToExtension.java index 660f756b6..90f9f71fc 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/RunnerToExtension.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/RunnerToExtension.java @@ -19,8 +19,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java b/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java index 7137f3ada..1613ffdf8 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java @@ -15,11 +15,11 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.*; import org.openrewrite.java.search.UsesType; import org.openrewrite.java.tree.*; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java b/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java index 28cef3cad..3f2daf94e 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java @@ -15,12 +15,12 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.*; import org.openrewrite.java.search.UsesType; import org.openrewrite.java.tree.J; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java b/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java index 05eb54297..40a175b0b 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java @@ -15,9 +15,9 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.AnnotationMatcher; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java index da3a0eb6f..1759af29c 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java @@ -15,12 +15,12 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.*; import org.openrewrite.java.search.FindImports; import org.openrewrite.java.search.UsesType; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java b/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java index 41e4f8127..26979c81d 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java @@ -15,11 +15,11 @@ */ package org.openrewrite.java.testing.junit5; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/package-info.java b/src/main/java/org/openrewrite/java/testing/junit5/package-info.java index db2dbd7ea..b05bb236e 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/package-info.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/package-info.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@NonNullApi +@NullMarked @NonNullFields package org.openrewrite.java.testing.junit5; -import org.openrewrite.internal.lang.NonNullApi; +import org.jspecify.annotations.NullMarked; import org.openrewrite.internal.lang.NonNullFields; diff --git a/src/main/java/org/openrewrite/java/testing/mockito/AnyToNullable.java b/src/main/java/org/openrewrite/java/testing/mockito/AnyToNullable.java index d9a201b17..8595085d2 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/AnyToNullable.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/AnyToNullable.java @@ -15,8 +15,8 @@ */ package org.openrewrite.java.testing.mockito; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.ChangeMethodName; import org.openrewrite.java.ChangeMethodTargetToStatic; import org.openrewrite.java.tree.J; diff --git a/src/main/java/org/openrewrite/java/testing/mockito/CleanupMockitoImports.java b/src/main/java/org/openrewrite/java/testing/mockito/CleanupMockitoImports.java index b8e63c553..2a120e833 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/CleanupMockitoImports.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/CleanupMockitoImports.java @@ -15,11 +15,11 @@ */ package org.openrewrite.java.testing.mockito; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.search.UsesType; import org.openrewrite.java.tree.J; diff --git a/src/main/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockito.java b/src/main/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockito.java index edec2dd80..4c8def8f0 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockito.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockito.java @@ -15,9 +15,9 @@ */ package org.openrewrite.java.testing.mockito; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.*; import org.openrewrite.java.search.FindAnnotations; import org.openrewrite.java.search.UsesType; @@ -210,7 +210,7 @@ private static boolean isFieldAlreadyDefined(J.Block classBody, String fieldName return false; } - private static @Nullable J.MethodDeclaration getFirstTestMethod(List methods) { + private static J.@Nullable MethodDeclaration getFirstTestMethod(List methods) { for (J.MethodDeclaration methodDeclaration : methods) { for (J.Annotation annotation : methodDeclaration.getLeadingAnnotations()) { if ("Test".equals(annotation.getSimpleName())) { @@ -567,7 +567,7 @@ private J.MethodInvocation modifyWhenMethodInvocation(J.MethodInvocation whenMet return null; } - private @Nullable J.Identifier getFieldIdentifier(String fieldName) { + private J.@Nullable Identifier getFieldIdentifier(String fieldName) { return getMockedTypesFields().keySet().stream() .filter(identifier -> identifier.getSimpleName().equals(fieldName)).findFirst() .orElseGet(() -> { diff --git a/src/main/java/org/openrewrite/java/testing/mockito/package-info.java b/src/main/java/org/openrewrite/java/testing/mockito/package-info.java index 208941548..3a3ec2512 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/package-info.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/package-info.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@NonNullApi +@NullMarked package org.openrewrite.java.testing.mockito; -import org.openrewrite.internal.lang.NonNullApi; +import org.jspecify.annotations.NullMarked; diff --git a/src/main/java/org/openrewrite/java/testing/testcontainers/package-info.java b/src/main/java/org/openrewrite/java/testing/testcontainers/package-info.java index 956a3fb3f..4d843dc72 100644 --- a/src/main/java/org/openrewrite/java/testing/testcontainers/package-info.java +++ b/src/main/java/org/openrewrite/java/testing/testcontainers/package-info.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@NonNullApi +@NullMarked package org.openrewrite.java.testing.testcontainers; -import org.openrewrite.internal.lang.NonNullApi; +import org.jspecify.annotations.NullMarked; From 39af3aea0a200d1a22c0bb68481e9c45da65017a Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Thu, 15 Aug 2024 11:16:15 +0200 Subject: [PATCH 2/2] Move nullable annotations on lazy init JavaParser.Builder --- .../junit5/ExpectedExceptionToAssertThrows.java | 3 +-- .../junit5/JUnitParamsRunnerToParameterized.java | 3 +-- .../testing/junit5/TemporaryFolderToTempDir.java | 12 ++++++------ .../java/testing/junit5/TestRuleToTestInfo.java | 6 ++---- .../java/testing/junit5/UpdateMockWebServer.java | 3 +-- .../java/testing/junit5/UpdateTestAnnotation.java | 7 +++---- .../java/testing/junit5/UseTestMethodOrder.java | 4 ++-- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java index f05e4084e..fd62333f7 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java @@ -58,8 +58,7 @@ public TreeVisitor getVisitor() { public static class ExpectedExceptionToAssertThrowsVisitor extends JavaIsoVisitor { - @Nullable - private JavaParser.Builder javaParser; + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { diff --git a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java index eccdb8fef..5c0e2e3ac 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java @@ -176,8 +176,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct */ private static class ParametersNoArgsImplicitMethodSource extends JavaIsoVisitor { - @Nullable - private JavaParser.Builder javaParser; + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { diff --git a/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java b/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java index 1613ffdf8..d67f5b5a9 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java @@ -49,8 +49,8 @@ public TreeVisitor getVisitor() { final AnnotationMatcher classRule = new AnnotationMatcher("@org.junit.ClassRule"); final AnnotationMatcher rule = new AnnotationMatcher("@org.junit.Rule"); - @Nullable - private JavaParser.Builder javaParser; + + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { @@ -157,8 +157,8 @@ private J convertToNewFile(J.MethodInvocation mi, ExecutionContext ctx) { private static class AddNewFolderMethod extends JavaIsoVisitor { private final J.MethodInvocation methodInvocation; - @Nullable - private JavaParser.Builder javaParser; + + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { @@ -236,8 +236,8 @@ private static class TranslateNewFolderMethodInvocation extends JavaVisitor javaParser; + + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { diff --git a/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java b/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java index 3f2daf94e..53e3c4fb0 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/TestRuleToTestInfo.java @@ -54,8 +54,7 @@ private static class TestRuleToTestInfoVisitor extends JavaIsoVisitor javaParser; + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { @@ -162,8 +161,7 @@ private static class BeforeMethodToTestInfoVisitor extends JavaIsoVisitor javaParser; + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java b/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java index 40a175b0b..3c6389e1b 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UpdateMockWebServer.java @@ -70,8 +70,7 @@ public TreeVisitor getVisitor() { new UsesType<>("okhttp3.mockwebserver.MockWebServer", false) ), new JavaIsoVisitor() { - @Nullable - private JavaParser.Builder javaParser; + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java index 1759af29c..743ccb69d 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java @@ -54,8 +54,8 @@ public TreeVisitor getVisitor() { private static class UpdateTestAnnotationVisitor extends JavaIsoVisitor { private static final AnnotationMatcher JUNIT4_TEST = new AnnotationMatcher("@org.junit.Test"); - @Nullable - private JavaParser.Builder javaParser; + + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { @@ -182,8 +182,7 @@ private static class ChangeTestAnnotation extends JavaIsoVisitor javaParser; + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) { diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java b/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java index 26979c81d..5fa7ef266 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java @@ -45,8 +45,8 @@ public String getDescription() { public TreeVisitor getVisitor() { return Preconditions.check(new UsesType<>("org.junit.FixMethodOrder", false), new JavaIsoVisitor() { - @Nullable - private JavaParser.Builder javaParser; + + private JavaParser.@Nullable Builder javaParser; private JavaParser.Builder javaParser(ExecutionContext ctx) { if (javaParser == null) {