From 7e05ec5f0e30a80f4b47068df24481efe46819af Mon Sep 17 00:00:00 2001 From: sullis Date: Sun, 25 Aug 2024 09:34:41 -0700 Subject: [PATCH 01/17] add jspecify recipe --- build.gradle.kts | 3 +- .../resources/META-INF/rewrite/jspecify.yml | 69 +++++++ .../jspecify/MigrateToJspecifyTest.java | 177 ++++++++++++++++++ 3 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/META-INF/rewrite/jspecify.yml create mode 100644 src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java diff --git a/build.gradle.kts b/build.gradle.kts index e5fcd685b7..d0ce57de2d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,6 +53,7 @@ dependencies { testRuntimeOnly("com.fasterxml.jackson.core:jackson-core") testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind") testRuntimeOnly("org.codehaus.groovy:groovy:latest.release") - testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:1.3.5") + testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:2.1.1") + testRuntimeOnly("com.google.code.findbugs:jsr305:3.0.2") testRuntimeOnly(gradleApi()) } diff --git a/src/main/resources/META-INF/rewrite/jspecify.yml b/src/main/resources/META-INF/rewrite/jspecify.yml new file mode 100644 index 0000000000..71bf0ca6d2 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/jspecify.yml @@ -0,0 +1,69 @@ +# +# Copyright 2024 the original author or authors. +#

+# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +#

+# https://www.apache.org/licenses/LICENSE-2.0 +#

+# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.jspecify.MigrateToJspecify +displayName: Migrate to jspecify +description: >- + This recipe will migrate to jspecify annotations. +tags: + - java +recipeList: + - org.openrewrite.java.jspecify.MigrateFromJavaxAnnotationApi + - org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.jspecify.MigrateFromJavaxAnnotationApi +displayName: Migrate to JSpecify +description: Migrate from javax Annotation API to JSpecify. +recipeList: + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: javax.annotation.Nullable + newFullyQualifiedTypeName: org.jspecify.annotations.Nullable + ignoreDefinition: true + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: javax.annotation.Nonnull + newFullyQualifiedTypeName: org.jspecify.annotations.NonNull + ignoreDefinition: true + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.jspecify + artifactId: jspecify + version: latest.release + - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: + annotationType: org.jspecify.annotations.* + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi +displayName: Migrate to JSpecify +description: Migrate from Jakarta Annotation API to JSpecify. +recipeList: + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: jakarta.annotation.Nullable + newFullyQualifiedTypeName: org.jspecify.annotations.Nullable + ignoreDefinition: true + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: jakarta.annotation.Nonnull + newFullyQualifiedTypeName: org.jspecify.annotations.NonNull + ignoreDefinition: true + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.jspecify + artifactId: jspecify + version: latest.release + - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: + annotationType: org.jspecify.annotations.* diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java new file mode 100644 index 0000000000..ed3a6bc2c1 --- /dev/null +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -0,0 +1,177 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.migrate.jspecify; + +import org.junit.jupiter.api.Test; +import org.openrewrite.config.Environment; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; +import static org.openrewrite.maven.Assertions.pomXml; + + +class MigrateToJspecifyTest implements RewriteTest { + + @Override + public void defaults(RecipeSpec spec) { + spec + .recipe( + Environment.builder() + .scanRuntimeClasspath("org.openrewrite.java.migrate.jspecify") + .build() + .activateRecipes("org.openrewrite.java.jspecify.MigrateToJspecify") + ) + .parser(JavaParser.fromJavaVersion().classpath("jsr305", "jakarta.annotation-api")); + } + + @Test + void migrateFromJavaxAnnotationApiToJspecify() { + //language=java + rewriteRun( + pomXml( + //language=xml + """ + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + """, + //language=xml + """ + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + org.jspecify + jspecify + 1.0.0 + + + + """), + java( + """ + import javax.annotation.Nonnull; + import javax.annotation.Nullable; + + public class Test { + @Nonnull + public String field1; + @Nullable + public String field2; + } + """, + """ + import org.jspecify.annotations.NonNull; + import org.jspecify.annotations.Nullable; + + public class Test { + @NonNull + public String field1; + @Nullable + public String field2; + } + """) + ); + } + + @Test + void migrateFromJakartaAnnotationApiToJspecify() { + //language=java + rewriteRun( + pomXml( + //language=xml + """ + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + jakarta.annotation + jakarta.annotation-api + 3.0.0 + + + + """, + //language=xml + """ + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + jakarta.annotation + jakarta.annotation-api + 3.0.0 + + + org.jspecify + jspecify + 1.0.0 + + + + """), + java( + """ + import jakarta.annotation.Nonnull; + import jakarta.annotation.Nullable; + + public class Test { + @Nonnull + public String field1; + @Nullable + public String field2; + } + """, + """ + import org.jspecify.annotations.NonNull; + import org.jspecify.annotations.Nullable; + + public class Test { + @NonNull + public String field1; + @Nullable + public String field2; + } + """) + ); + } +} From 7ad86f74544738d19a4b2f1b9746b4f9b8860c16 Mon Sep 17 00:00:00 2001 From: sullis Date: Mon, 26 Aug 2024 15:26:28 -0700 Subject: [PATCH 02/17] Update src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java index ed3a6bc2c1..caa40fe008 100644 --- a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -16,6 +16,7 @@ package org.openrewrite.java.migrate.jspecify; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.config.Environment; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; From bd467a572de7c7cd349b76f0eed4d6f3dc2398f6 Mon Sep 17 00:00:00 2001 From: sullis Date: Mon, 26 Aug 2024 15:26:36 -0700 Subject: [PATCH 03/17] Update src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java index caa40fe008..7f2aa22b08 100644 --- a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -40,6 +40,7 @@ public void defaults(RecipeSpec spec) { .parser(JavaParser.fromJavaVersion().classpath("jsr305", "jakarta.annotation-api")); } + @DocumentExample @Test void migrateFromJavaxAnnotationApiToJspecify() { //language=java From 381f133074094c549fca62f6d05fb302aba680b2 Mon Sep 17 00:00:00 2001 From: sullis Date: Mon, 26 Aug 2024 15:26:45 -0700 Subject: [PATCH 04/17] Update src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../jspecify/MigrateToJspecifyTest.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java index 7f2aa22b08..9e2682a217 100644 --- a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -64,24 +64,24 @@ void migrateFromJavaxAnnotationApiToJspecify() { """, //language=xml """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - javax.annotation - javax.annotation-api - 1.3.2 - - - org.jspecify - jspecify - 1.0.0 - - - + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + org.jspecify + jspecify + 1.0.0 + + + """), java( """ From f5d133e63673819efdf691400a47e5e2f337aa68 Mon Sep 17 00:00:00 2001 From: sullis Date: Mon, 26 Aug 2024 15:26:56 -0700 Subject: [PATCH 05/17] Update src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../jspecify/MigrateToJspecifyTest.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java index 9e2682a217..b88e5054dc 100644 --- a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -132,24 +132,24 @@ void migrateFromJakartaAnnotationApiToJspecify() { """, //language=xml """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - jakarta.annotation - jakarta.annotation-api - 3.0.0 - - - org.jspecify - jspecify - 1.0.0 - - - + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + jakarta.annotation + jakarta.annotation-api + 3.0.0 + + + org.jspecify + jspecify + 1.0.0 + + + """), java( """ From f8a3b9cfbe75ccb08b5423c1ed8fd3f28ca3e052 Mon Sep 17 00:00:00 2001 From: sullis Date: Mon, 26 Aug 2024 19:47:32 -0700 Subject: [PATCH 06/17] fix AddCommonAnnotationsDependenciesTest --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index d0ce57de2d..4665981807 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,7 +53,7 @@ dependencies { testRuntimeOnly("com.fasterxml.jackson.core:jackson-core") testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind") testRuntimeOnly("org.codehaus.groovy:groovy:latest.release") - testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:2.1.1") + testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:1.3.5") testRuntimeOnly("com.google.code.findbugs:jsr305:3.0.2") testRuntimeOnly(gradleApi()) } From 375f3280301fbd1afec92372243d992974131ef5 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 27 Aug 2024 09:58:11 +0200 Subject: [PATCH 07/17] Upgrade test version of jakarta.annotation-api --- build.gradle.kts | 2 +- .../jspecify/MigrateToJspecifyTest.java | 102 +++++++++--------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 4665981807..d0ce57de2d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,7 +53,7 @@ dependencies { testRuntimeOnly("com.fasterxml.jackson.core:jackson-core") testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind") testRuntimeOnly("org.codehaus.groovy:groovy:latest.release") - testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:1.3.5") + testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:2.1.1") testRuntimeOnly("com.google.code.findbugs:jsr305:3.0.2") testRuntimeOnly(gradleApi()) } diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java index b88e5054dc..49099f3eb1 100644 --- a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -17,7 +17,6 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; -import org.openrewrite.config.Environment; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -31,12 +30,7 @@ class MigrateToJspecifyTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { spec - .recipe( - Environment.builder() - .scanRuntimeClasspath("org.openrewrite.java.migrate.jspecify") - .build() - .activateRecipes("org.openrewrite.java.jspecify.MigrateToJspecify") - ) + .recipeFromResource("/META-INF/rewrite/jspecify.yml", "org.openrewrite.java.jspecify.MigrateToJspecify") .parser(JavaParser.fromJavaVersion().classpath("jsr305", "jakarta.annotation-api")); } @@ -64,30 +58,32 @@ void migrateFromJavaxAnnotationApiToJspecify() { """, //language=xml """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - javax.annotation - javax.annotation-api - 1.3.2 - - - org.jspecify - jspecify - 1.0.0 - - - - """), + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + org.jspecify + jspecify + 1.0.0 + + + + """ + ), + //language=java java( """ import javax.annotation.Nonnull; import javax.annotation.Nullable; - + public class Test { @Nonnull public String field1; @@ -98,14 +94,15 @@ public class Test { """ import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; - + public class Test { @NonNull public String field1; @Nullable public String field2; } - """) + """ + ) ); } @@ -132,30 +129,32 @@ void migrateFromJakartaAnnotationApiToJspecify() { """, //language=xml """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - jakarta.annotation - jakarta.annotation-api - 3.0.0 - - - org.jspecify - jspecify - 1.0.0 - - - - """), + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + jakarta.annotation + jakarta.annotation-api + 3.0.0 + + + org.jspecify + jspecify + 1.0.0 + + + + """ + ), + //language=java java( """ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; - + public class Test { @Nonnull public String field1; @@ -166,14 +165,15 @@ public class Test { """ import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; - + public class Test { @NonNull public String field1; @Nullable public String field2; } - """) + """ + ) ); } } From 977546c75c0fea158cbcff0d1180284f269fd491 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 27 Aug 2024 10:04:32 +0200 Subject: [PATCH 08/17] Switch to `dependsOn` for AddCommonAnnotationsDependenciesTest --- .../migrate/javax/AddCommonAnnotationsDependenciesTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/openrewrite/java/migrate/javax/AddCommonAnnotationsDependenciesTest.java b/src/test/java/org/openrewrite/java/migrate/javax/AddCommonAnnotationsDependenciesTest.java index fad8df675a..070f1fac44 100644 --- a/src/test/java/org/openrewrite/java/migrate/javax/AddCommonAnnotationsDependenciesTest.java +++ b/src/test/java/org/openrewrite/java/migrate/javax/AddCommonAnnotationsDependenciesTest.java @@ -36,14 +36,14 @@ public void defaults(RecipeSpec spec) { @Test void addDependencyIfAnnotationJsr250Present() { rewriteRun( - spec -> spec.parser(JavaParser.fromJavaVersion().classpath("jakarta.annotation-api")), + spec -> spec.parser(JavaParser.fromJavaVersion().dependsOn("package javax.annotation; public @interface Generated {}")), mavenProject("my-project", //language=java srcMainJava( java( """ import javax.annotation.Generated; - + @Generated("Hello") class A { } From 3bda8b25152f9186c647d84e0c17eb92fdedb8bc Mon Sep 17 00:00:00 2001 From: sullis Date: Tue, 27 Aug 2024 10:41:19 -0700 Subject: [PATCH 09/17] validate jspecify annotations --- .../jspecify/MigrateToJspecifyTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java index 49099f3eb1..266f47e0f7 100644 --- a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -89,6 +89,15 @@ public class Test { public String field1; @Nullable public String field2; + @Nullable + public Foo.Bar foobar; + } + + interface Foo { + class Bar { + @Nonnull + public String barField; + } } """, """ @@ -100,6 +109,15 @@ public class Test { public String field1; @Nullable public String field2; + + public Foo.@Nullable Bar foobar; + } + + interface Foo { + class Bar { + @NonNull + public String barField; + } } """ ) @@ -160,6 +178,15 @@ public class Test { public String field1; @Nullable public String field2; + @Nullable + public Foo.Bar foobar; + } + + interface Foo { + class Bar { + @Nonnull + public String barField; + } } """, """ @@ -171,6 +198,15 @@ public class Test { public String field1; @Nullable public String field2; + + public Foo.@Nullable Bar foobar; + } + + interface Foo { + class Bar { + @NonNull + public String barField; + } } """ ) From 62650d17585dd6d3f391c81ace90a6a3007b537d Mon Sep 17 00:00:00 2001 From: sullis Date: Tue, 27 Aug 2024 10:52:30 -0700 Subject: [PATCH 10/17] jspecify onlyIfUsing --- src/main/resources/META-INF/rewrite/jspecify.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/META-INF/rewrite/jspecify.yml b/src/main/resources/META-INF/rewrite/jspecify.yml index 71bf0ca6d2..fa00360a3d 100644 --- a/src/main/resources/META-INF/rewrite/jspecify.yml +++ b/src/main/resources/META-INF/rewrite/jspecify.yml @@ -44,6 +44,7 @@ recipeList: groupId: org.jspecify artifactId: jspecify version: latest.release + onlyIfUsing: org.jspecify.annotations.* - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: annotationType: org.jspecify.annotations.* @@ -65,5 +66,6 @@ recipeList: groupId: org.jspecify artifactId: jspecify version: latest.release + onlyIfUsing: org.jspecify.annotations.* - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: annotationType: org.jspecify.annotations.* From 73caddd8c68d48d514be43dcecc890daa038640c Mon Sep 17 00:00:00 2001 From: sullis Date: Tue, 27 Aug 2024 10:53:58 -0700 Subject: [PATCH 11/17] jspecify onlyIfUsing pattern --- src/main/resources/META-INF/rewrite/jspecify.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/jspecify.yml b/src/main/resources/META-INF/rewrite/jspecify.yml index fa00360a3d..7511abe773 100644 --- a/src/main/resources/META-INF/rewrite/jspecify.yml +++ b/src/main/resources/META-INF/rewrite/jspecify.yml @@ -44,7 +44,7 @@ recipeList: groupId: org.jspecify artifactId: jspecify version: latest.release - onlyIfUsing: org.jspecify.annotations.* + onlyIfUsing: org.jspecify.annotations..* - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: annotationType: org.jspecify.annotations.* @@ -66,6 +66,6 @@ recipeList: groupId: org.jspecify artifactId: jspecify version: latest.release - onlyIfUsing: org.jspecify.annotations.* + onlyIfUsing: org.jspecify.annotations..* - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: annotationType: org.jspecify.annotations.* From 2757844412b02502aa9ceff1e933e9dadcc14bfa Mon Sep 17 00:00:00 2001 From: sullis Date: Tue, 27 Aug 2024 10:58:43 -0700 Subject: [PATCH 12/17] update recipe descriptions --- src/main/resources/META-INF/rewrite/jspecify.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/jspecify.yml b/src/main/resources/META-INF/rewrite/jspecify.yml index 7511abe773..2f30ef16d3 100644 --- a/src/main/resources/META-INF/rewrite/jspecify.yml +++ b/src/main/resources/META-INF/rewrite/jspecify.yml @@ -29,8 +29,8 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateFromJavaxAnnotationApi -displayName: Migrate to JSpecify -description: Migrate from javax Annotation API to JSpecify. +displayName: Migrate from javax annotation API to jspecify +description: Migrate from javax annotation API to jspecify. recipeList: - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: javax.annotation.Nullable @@ -51,8 +51,8 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi -displayName: Migrate to JSpecify -description: Migrate from Jakarta Annotation API to JSpecify. +displayName: Migrate from jakarta annotation API to jspecify +description: Migrate from jakarta annotation API to jspecify. recipeList: - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: jakarta.annotation.Nullable From dc695ec54cfb38efa29de11a0a4431c1cb378923 Mon Sep 17 00:00:00 2001 From: sullis Date: Tue, 27 Aug 2024 22:18:20 -0700 Subject: [PATCH 13/17] add MigrateFromJetbrainsAnnotations --- .../resources/META-INF/rewrite/jspecify.yml | 23 ++++- .../jspecify/MigrateToJspecifyTest.java | 91 ++++++++++++++++++- 2 files changed, 112 insertions(+), 2 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/jspecify.yml b/src/main/resources/META-INF/rewrite/jspecify.yml index 2f30ef16d3..30a9183827 100644 --- a/src/main/resources/META-INF/rewrite/jspecify.yml +++ b/src/main/resources/META-INF/rewrite/jspecify.yml @@ -25,6 +25,7 @@ tags: recipeList: - org.openrewrite.java.jspecify.MigrateFromJavaxAnnotationApi - org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi + - org.openrewrite.java.jspecify.MigrateFromJetbrainsAnnotations --- type: specs.openrewrite.org/v1beta/recipe @@ -47,7 +48,6 @@ recipeList: onlyIfUsing: org.jspecify.annotations..* - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: annotationType: org.jspecify.annotations.* - --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi @@ -69,3 +69,24 @@ recipeList: onlyIfUsing: org.jspecify.annotations..* - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: annotationType: org.jspecify.annotations.* +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.jspecify.MigrateFromJetbrainsAnnotations +displayName: Migrate from jetbrains annotations to jspecify +description: Migrate from jetbrains annotations to jspecify. +recipeList: + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.jetbrains.annotations.Nullable + newFullyQualifiedTypeName: org.jspecify.annotations.Nullable + ignoreDefinition: true + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.jetbrains.annotations.NotNull + newFullyQualifiedTypeName: org.jspecify.annotations.NonNull + ignoreDefinition: true + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.jspecify + artifactId: jspecify + version: latest.release + onlyIfUsing: org.jspecify.annotations..* + - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: + annotationType: org.jspecify.annotations.* diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java index 266f47e0f7..62f2ec47b5 100644 --- a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -31,7 +31,7 @@ class MigrateToJspecifyTest implements RewriteTest { public void defaults(RecipeSpec spec) { spec .recipeFromResource("/META-INF/rewrite/jspecify.yml", "org.openrewrite.java.jspecify.MigrateToJspecify") - .parser(JavaParser.fromJavaVersion().classpath("jsr305", "jakarta.annotation-api")); + .parser(JavaParser.fromJavaVersion().classpath("jsr305", "jakarta.annotation-api", "annotations")); } @DocumentExample @@ -212,4 +212,93 @@ class Bar { ) ); } + + @Test + void migrateFromJetbrainsAnnotationsToJspecify() { + //language=java + rewriteRun( + pomXml( + //language=xml + """ + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + org.jetbrains + annotations + 24.1.0 + + + + """, + //language=xml + """ + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + org.jetbrains + annotations + 24.1.0 + + + org.jspecify + jspecify + 1.0.0 + + + + """ + ), + //language=java + java( + """ + import org.jetbrains.annotations.NotNull; + import org.jetbrains.annotations.Nullable; + + public class Test { + @NotNull + public String field1; + @Nullable + public String field2; + @Nullable + public Foo.Bar foobar; + } + + interface Foo { + class Bar { + @NotNull + public String barField; + } + } + """, + """ + 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 + public String barField; + } + } + """ + ) + ); + } } From 10ec3aef21447d1f85f0225e70ecdd7d7456ce45 Mon Sep 17 00:00:00 2001 From: sullis Date: Wed, 28 Aug 2024 16:51:00 -0700 Subject: [PATCH 14/17] jspecify -> JSpecify --- src/main/resources/META-INF/rewrite/jspecify.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/jspecify.yml b/src/main/resources/META-INF/rewrite/jspecify.yml index 30a9183827..1c36ede074 100644 --- a/src/main/resources/META-INF/rewrite/jspecify.yml +++ b/src/main/resources/META-INF/rewrite/jspecify.yml @@ -17,9 +17,9 @@ --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateToJspecify -displayName: Migrate to jspecify +displayName: Migrate to JSpecify description: >- - This recipe will migrate to jspecify annotations. + This recipe will migrate to JSpecify annotations. tags: - java recipeList: @@ -30,8 +30,8 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateFromJavaxAnnotationApi -displayName: Migrate from javax annotation API to jspecify -description: Migrate from javax annotation API to jspecify. +displayName: Migrate from javax annotation API to JSpecify +description: Migrate from javax annotation API to JSpecify. recipeList: - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: javax.annotation.Nullable @@ -51,8 +51,8 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi -displayName: Migrate from jakarta annotation API to jspecify -description: Migrate from jakarta annotation API to jspecify. +displayName: Migrate from jakarta annotation API to JSpecify +description: Migrate from jakarta annotation API to JSpecify. recipeList: - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: jakarta.annotation.Nullable @@ -72,8 +72,8 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateFromJetbrainsAnnotations -displayName: Migrate from jetbrains annotations to jspecify -description: Migrate from jetbrains annotations to jspecify. +displayName: Migrate from jetbrains annotations to JSpecify +description: Migrate from jetbrains annotations to JSpecify. recipeList: - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: org.jetbrains.annotations.Nullable From 74df793ee73f25f201fd5b99a0d970a39a2bbf58 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 30 Aug 2024 11:08:17 +0200 Subject: [PATCH 15/17] Scan for the old annotations when adding jspecify dependency --- .../resources/META-INF/rewrite/jspecify.yml | 30 +- .../jspecify/MigrateToJspecifyTest.java | 484 +++++++++--------- 2 files changed, 260 insertions(+), 254 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/jspecify.yml b/src/main/resources/META-INF/rewrite/jspecify.yml index 1c36ede074..f99ce35ddd 100644 --- a/src/main/resources/META-INF/rewrite/jspecify.yml +++ b/src/main/resources/META-INF/rewrite/jspecify.yml @@ -33,6 +33,11 @@ name: org.openrewrite.java.jspecify.MigrateFromJavaxAnnotationApi displayName: Migrate from javax annotation API to JSpecify description: Migrate from javax annotation API to JSpecify. recipeList: + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.jspecify + artifactId: jspecify + version: latest.release + onlyIfUsing: javax.annotation.*ull* - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: javax.annotation.Nullable newFullyQualifiedTypeName: org.jspecify.annotations.Nullable @@ -41,11 +46,6 @@ recipeList: oldFullyQualifiedTypeName: javax.annotation.Nonnull newFullyQualifiedTypeName: org.jspecify.annotations.NonNull ignoreDefinition: true - - org.openrewrite.java.dependencies.AddDependency: - groupId: org.jspecify - artifactId: jspecify - version: latest.release - onlyIfUsing: org.jspecify.annotations..* - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: annotationType: org.jspecify.annotations.* --- @@ -54,6 +54,11 @@ name: org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi displayName: Migrate from jakarta annotation API to JSpecify description: Migrate from jakarta annotation API to JSpecify. recipeList: + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.jspecify + artifactId: jspecify + version: 1.0.0 + onlyIfUsing: jakarta.annotation.*ull* - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: jakarta.annotation.Nullable newFullyQualifiedTypeName: org.jspecify.annotations.Nullable @@ -62,11 +67,6 @@ recipeList: oldFullyQualifiedTypeName: jakarta.annotation.Nonnull newFullyQualifiedTypeName: org.jspecify.annotations.NonNull ignoreDefinition: true - - org.openrewrite.java.dependencies.AddDependency: - groupId: org.jspecify - artifactId: jspecify - version: latest.release - onlyIfUsing: org.jspecify.annotations..* - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: annotationType: org.jspecify.annotations.* --- @@ -75,6 +75,11 @@ name: org.openrewrite.java.jspecify.MigrateFromJetbrainsAnnotations displayName: Migrate from jetbrains annotations to JSpecify description: Migrate from jetbrains annotations to JSpecify. recipeList: + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.jspecify + artifactId: jspecify + version: 1.0.0 + onlyIfUsing: org.jetbrains.annotations.*ull* - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: org.jetbrains.annotations.Nullable newFullyQualifiedTypeName: org.jspecify.annotations.Nullable @@ -83,10 +88,5 @@ recipeList: oldFullyQualifiedTypeName: org.jetbrains.annotations.NotNull newFullyQualifiedTypeName: org.jspecify.annotations.NonNull ignoreDefinition: true - - org.openrewrite.java.dependencies.AddDependency: - groupId: org.jspecify - artifactId: jspecify - version: latest.release - onlyIfUsing: org.jspecify.annotations..* - org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType: annotationType: org.jspecify.annotations.* diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java index 62f2ec47b5..92542b4c8d 100644 --- a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -21,10 +21,9 @@ import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; -import static org.openrewrite.java.Assertions.java; +import static org.openrewrite.java.Assertions.*; import static org.openrewrite.maven.Assertions.pomXml; - class MigrateToJspecifyTest implements RewriteTest { @Override @@ -37,267 +36,274 @@ public void defaults(RecipeSpec spec) { @DocumentExample @Test void migrateFromJavaxAnnotationApiToJspecify() { - //language=java rewriteRun( - pomXml( - //language=xml - """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - javax.annotation - javax.annotation-api - 1.3.2 - - - - """, + mavenProject("foo", + srcMainJava( + //language=java + java( + """ + import javax.annotation.Nonnull; + import javax.annotation.Nullable; + + public class Test { + @Nonnull + public String field1; + @Nullable + public String field2; + @Nullable + public Foo.Bar foobar; + } + + interface Foo { + class Bar { + @Nonnull + public String barField; + } + } + """, + """ + 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 + public String barField; + } + } + """ + ) + ), //language=xml - """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - javax.annotation - javax.annotation-api - 1.3.2 - - - org.jspecify - jspecify - 1.0.0 - - - + pomXml( """ - ), - //language=java - java( - """ - import javax.annotation.Nonnull; - import javax.annotation.Nullable; - - public class Test { - @Nonnull - public String field1; - @Nullable - public String field2; - @Nullable - public Foo.Bar foobar; - } - - interface Foo { - class Bar { - @Nonnull - public String barField; - } - } - """, - """ - 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 - public String barField; - } - } + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + """, """ + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + javax.annotation + javax.annotation-api + 1.3.2 + + + org.jspecify + jspecify + 1.0.0 + + + + """ + ) ) ); } @Test void migrateFromJakartaAnnotationApiToJspecify() { - //language=java rewriteRun( - pomXml( - //language=xml - """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - jakarta.annotation - jakarta.annotation-api - 3.0.0 - - - - """, + mavenProject("foo", + //language=java + srcMainJava( + java( + """ + import jakarta.annotation.Nonnull; + import jakarta.annotation.Nullable; + + public class Test { + @Nonnull + public String field1; + @Nullable + public String field2; + @Nullable + public Foo.Bar foobar; + } + + interface Foo { + class Bar { + @Nonnull + public String barField; + } + } + """, + """ + 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 + public String barField; + } + } + """ + ) + ) + , //language=xml - """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - jakarta.annotation - jakarta.annotation-api - 3.0.0 - - - org.jspecify - jspecify - 1.0.0 - - - + pomXml( """ - ), - //language=java - java( - """ - import jakarta.annotation.Nonnull; - import jakarta.annotation.Nullable; - - public class Test { - @Nonnull - public String field1; - @Nullable - public String field2; - @Nullable - public Foo.Bar foobar; - } - - interface Foo { - class Bar { - @Nonnull - public String barField; - } - } - """, - """ - 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 - public String barField; - } - } + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + jakarta.annotation + jakarta.annotation-api + 3.0.0 + + + + """, """ + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + jakarta.annotation + jakarta.annotation-api + 3.0.0 + + + org.jspecify + jspecify + 1.0.0 + + + + """ + ) ) ); } @Test void migrateFromJetbrainsAnnotationsToJspecify() { - //language=java rewriteRun( - pomXml( - //language=xml - """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - org.jetbrains - annotations - 24.1.0 - - - - """, + mavenProject("foo", + //language=java + srcMainJava( + java( + """ + import org.jetbrains.annotations.NotNull; + import org.jetbrains.annotations.Nullable; + + public class Test { + @NotNull + public String field1; + @Nullable + public String field2; + @Nullable + public Foo.Bar foobar; + } + + interface Foo { + class Bar { + @NotNull + public String barField; + } + } + """, + """ + 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 + public String barField; + } + } + """ + ) + ), //language=xml - """ - - 4.0.0 - com.example.foobar - foobar-core - 1.0.0 - - - org.jetbrains - annotations - 24.1.0 - - - org.jspecify - jspecify - 1.0.0 - - - + pomXml( """ - ), - //language=java - java( - """ - import org.jetbrains.annotations.NotNull; - import org.jetbrains.annotations.Nullable; - - public class Test { - @NotNull - public String field1; - @Nullable - public String field2; - @Nullable - public Foo.Bar foobar; - } - - interface Foo { - class Bar { - @NotNull - public String barField; - } - } - """, - """ - 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 - public String barField; - } - } + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + org.jetbrains + annotations + 24.1.0 + + + + """, """ + + 4.0.0 + com.example.foobar + foobar-core + 1.0.0 + + + org.jetbrains + annotations + 24.1.0 + + + org.jspecify + jspecify + 1.0.0 + + + + """ + ) ) ); } From 0c28e25b429e6123fc50ba4c290f7b5f00939076 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 30 Aug 2024 11:09:11 +0200 Subject: [PATCH 16/17] Suppress warnings inside text blocks --- .../openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java index 92542b4c8d..fa963d2891 100644 --- a/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java +++ b/src/test/java/org/openrewrite/java/migrate/jspecify/MigrateToJspecifyTest.java @@ -24,6 +24,7 @@ import static org.openrewrite.java.Assertions.*; import static org.openrewrite.maven.Assertions.pomXml; +@SuppressWarnings("NotNullFieldNotInitialized") class MigrateToJspecifyTest implements RewriteTest { @Override From 57eb5f033beca0dcfe4483cc416c7f1d2288efe0 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Fri, 30 Aug 2024 11:22:28 +0200 Subject: [PATCH 17/17] Use common capitalization on displayName and description --- src/main/resources/META-INF/rewrite/jspecify.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/jspecify.yml b/src/main/resources/META-INF/rewrite/jspecify.yml index f99ce35ddd..d3ee6e1164 100644 --- a/src/main/resources/META-INF/rewrite/jspecify.yml +++ b/src/main/resources/META-INF/rewrite/jspecify.yml @@ -19,7 +19,7 @@ type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateToJspecify displayName: Migrate to JSpecify description: >- - This recipe will migrate to JSpecify annotations. + This recipe will migrate to JSpecify annotations from various other nullability annotation standards. tags: - java recipeList: @@ -51,8 +51,8 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi -displayName: Migrate from jakarta annotation API to JSpecify -description: Migrate from jakarta annotation API to JSpecify. +displayName: Migrate from Jakarta annotation API to JSpecify +description: Migrate from Jakarta annotation API to JSpecify. recipeList: - org.openrewrite.java.dependencies.AddDependency: groupId: org.jspecify @@ -72,8 +72,8 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.jspecify.MigrateFromJetbrainsAnnotations -displayName: Migrate from jetbrains annotations to JSpecify -description: Migrate from jetbrains annotations to JSpecify. +displayName: Migrate from JetBrains annotations to JSpecify +description: Migrate from JetBrains annotations to JSpecify. recipeList: - org.openrewrite.java.dependencies.AddDependency: groupId: org.jspecify