Skip to content

Commit 57a7c3d

Browse files
sullisgithub-actions[bot]timtebeek
authored
Recipes to migrate from Javax, Jakarta and JetBrains nullability annotations to JSpecify (#541)
* add jspecify recipe * 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> * 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> * 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> * 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> * fix AddCommonAnnotationsDependenciesTest * Upgrade test version of jakarta.annotation-api * Switch to `dependsOn` for AddCommonAnnotationsDependenciesTest * validate jspecify annotations * jspecify onlyIfUsing * jspecify onlyIfUsing pattern * update recipe descriptions * add MigrateFromJetbrainsAnnotations * jspecify -> JSpecify * Scan for the old annotations when adding jspecify dependency * Suppress warnings inside text blocks * Use common capitalization on displayName and description --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tim te Beek <tim@moderne.io>
1 parent 6d5976d commit 57a7c3d

File tree

4 files changed

+407
-3
lines changed

4 files changed

+407
-3
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies {
5353
testRuntimeOnly("com.fasterxml.jackson.core:jackson-core")
5454
testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind")
5555
testRuntimeOnly("org.codehaus.groovy:groovy:latest.release")
56-
testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:1.3.5")
56+
testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:2.1.1")
57+
testRuntimeOnly("com.google.code.findbugs:jsr305:3.0.2")
5758
testRuntimeOnly(gradleApi())
5859
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#
2+
# Copyright 2024 the original author or authors.
3+
# <p>
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# <p>
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
# <p>
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
---
18+
type: specs.openrewrite.org/v1beta/recipe
19+
name: org.openrewrite.java.jspecify.MigrateToJspecify
20+
displayName: Migrate to JSpecify
21+
description: >-
22+
This recipe will migrate to JSpecify annotations from various other nullability annotation standards.
23+
tags:
24+
- java
25+
recipeList:
26+
- org.openrewrite.java.jspecify.MigrateFromJavaxAnnotationApi
27+
- org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi
28+
- org.openrewrite.java.jspecify.MigrateFromJetbrainsAnnotations
29+
30+
---
31+
type: specs.openrewrite.org/v1beta/recipe
32+
name: org.openrewrite.java.jspecify.MigrateFromJavaxAnnotationApi
33+
displayName: Migrate from javax annotation API to JSpecify
34+
description: Migrate from javax annotation API to JSpecify.
35+
recipeList:
36+
- org.openrewrite.java.dependencies.AddDependency:
37+
groupId: org.jspecify
38+
artifactId: jspecify
39+
version: latest.release
40+
onlyIfUsing: javax.annotation.*ull*
41+
- org.openrewrite.java.ChangeType:
42+
oldFullyQualifiedTypeName: javax.annotation.Nullable
43+
newFullyQualifiedTypeName: org.jspecify.annotations.Nullable
44+
ignoreDefinition: true
45+
- org.openrewrite.java.ChangeType:
46+
oldFullyQualifiedTypeName: javax.annotation.Nonnull
47+
newFullyQualifiedTypeName: org.jspecify.annotations.NonNull
48+
ignoreDefinition: true
49+
- org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType:
50+
annotationType: org.jspecify.annotations.*
51+
---
52+
type: specs.openrewrite.org/v1beta/recipe
53+
name: org.openrewrite.java.jspecify.MigrateFromJakartaAnnotationApi
54+
displayName: Migrate from Jakarta annotation API to JSpecify
55+
description: Migrate from Jakarta annotation API to JSpecify.
56+
recipeList:
57+
- org.openrewrite.java.dependencies.AddDependency:
58+
groupId: org.jspecify
59+
artifactId: jspecify
60+
version: 1.0.0
61+
onlyIfUsing: jakarta.annotation.*ull*
62+
- org.openrewrite.java.ChangeType:
63+
oldFullyQualifiedTypeName: jakarta.annotation.Nullable
64+
newFullyQualifiedTypeName: org.jspecify.annotations.Nullable
65+
ignoreDefinition: true
66+
- org.openrewrite.java.ChangeType:
67+
oldFullyQualifiedTypeName: jakarta.annotation.Nonnull
68+
newFullyQualifiedTypeName: org.jspecify.annotations.NonNull
69+
ignoreDefinition: true
70+
- org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType:
71+
annotationType: org.jspecify.annotations.*
72+
---
73+
type: specs.openrewrite.org/v1beta/recipe
74+
name: org.openrewrite.java.jspecify.MigrateFromJetbrainsAnnotations
75+
displayName: Migrate from JetBrains annotations to JSpecify
76+
description: Migrate from JetBrains annotations to JSpecify.
77+
recipeList:
78+
- org.openrewrite.java.dependencies.AddDependency:
79+
groupId: org.jspecify
80+
artifactId: jspecify
81+
version: 1.0.0
82+
onlyIfUsing: org.jetbrains.annotations.*ull*
83+
- org.openrewrite.java.ChangeType:
84+
oldFullyQualifiedTypeName: org.jetbrains.annotations.Nullable
85+
newFullyQualifiedTypeName: org.jspecify.annotations.Nullable
86+
ignoreDefinition: true
87+
- org.openrewrite.java.ChangeType:
88+
oldFullyQualifiedTypeName: org.jetbrains.annotations.NotNull
89+
newFullyQualifiedTypeName: org.jspecify.annotations.NonNull
90+
ignoreDefinition: true
91+
- org.openrewrite.staticanalysis.java.MoveFieldAnnotationToType:
92+
annotationType: org.jspecify.annotations.*

src/test/java/org/openrewrite/java/migrate/javax/AddCommonAnnotationsDependenciesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public void defaults(RecipeSpec spec) {
3636
@Test
3737
void addDependencyIfAnnotationJsr250Present() {
3838
rewriteRun(
39-
spec -> spec.parser(JavaParser.fromJavaVersion().classpath("jakarta.annotation-api")),
39+
spec -> spec.parser(JavaParser.fromJavaVersion().dependsOn("package javax.annotation; public @interface Generated {}")),
4040
mavenProject("my-project",
4141
//language=java
4242
srcMainJava(
4343
java(
4444
"""
4545
import javax.annotation.Generated;
46-
46+
4747
@Generated("Hello")
4848
class A {
4949
}

0 commit comments

Comments
 (0)