Skip to content

Commit

Permalink
Migrate to JSpecify from OpenRewrite JSR-305 meta-annotations (#104)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Add dep

---------

Co-authored-by: Moderne <[email protected]>
  • Loading branch information
jkschneider and TeamModerne authored Aug 15, 2024
1 parent 1007f46 commit e713ca6
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 57 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ dependencies {
compileOnly("org.projectlombok:lombok:latest.release")
annotationProcessor("org.projectlombok:lombok:latest.release")
compileOnly("org.openrewrite:rewrite-java:latest.release")
implementation("org.jspecify:jspecify:latest.release")

// Needed for annotation processing tests
testImplementation(files(tools))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.sun.tools.javac.tree.TreeScanner;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;

import javax.tools.JavaFileObject;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.SourceFile;
import org.openrewrite.Tree;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor;
import org.openrewrite.java.tree.Expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
@NullMarked
package org.openrewrite.java.template.internal;

import org.openrewrite.internal.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
4 changes: 2 additions & 2 deletions src/main/java/org/openrewrite/java/template/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
@NullMarked
package org.openrewrite.java.template;

import org.openrewrite.internal.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Context;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.openrewrite.java.template.internal.ImportDetector;
import org.openrewrite.java.template.internal.JavacResolution;
import org.openrewrite.java.template.internal.TemplateCode;
Expand Down Expand Up @@ -669,7 +669,7 @@ private Class<? extends JCTree> getType(JCTree.JCMethodDecl method) {
return returnExpression != null ? returnExpression.getClass() : method.getBody().getStatements().last().getClass();
}

private @Nullable JCTree.JCExpression getReturnExpression(JCTree.JCMethodDecl method) {
private JCTree.@Nullable JCExpression getReturnExpression(JCTree.JCMethodDecl method) {
JCTree.JCStatement statement = method.getBody().getStatements().last();
if (statement instanceof JCTree.JCReturn) {
return ((JCTree.JCReturn) statement).expr;
Expand Down Expand Up @@ -935,7 +935,7 @@ private boolean resolve() {
return method != null;
}

private @Nullable JCTree.JCMethodDecl resolve(JCTree.JCMethodDecl method) {
private JCTree.@Nullable JCMethodDecl resolve(JCTree.JCMethodDecl method) {
JavacResolution res = new JavacResolution(context);
try {
classDecl.defs = classDecl.defs.prepend(method);
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/ArraysRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand All @@ -39,7 +39,7 @@
* OpenRewrite recipe created for Refaster template {@code Arrays}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class ArraysRecipe extends Recipe {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand All @@ -39,7 +39,7 @@
* OpenRewrite recipe created for Refaster template {@code CharacterEscapeAnnotation}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class CharacterEscapeAnnotationRecipe extends Recipe {

Expand Down
6 changes: 3 additions & 3 deletions src/test/resources/refaster/EscapesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand Down Expand Up @@ -67,7 +67,7 @@ public List<Recipe> getRecipeList() {
* OpenRewrite recipe created for Refaster template {@code Escapes.ConstantsFormat}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class ConstantsFormatRecipe extends Recipe {

Expand Down Expand Up @@ -129,7 +129,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
* OpenRewrite recipe created for Refaster template {@code Escapes.Split}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class SplitRecipe extends Recipe {

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/FindListAddRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand All @@ -40,7 +40,7 @@
* OpenRewrite recipe created for Refaster template {@code FindListAdd}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class FindListAddRecipe extends Recipe {

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/GenericsRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand Down Expand Up @@ -66,7 +66,7 @@ public List<Recipe> getRecipeList() {
* OpenRewrite recipe created for Refaster template {@code Generics.FirstElement}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class FirstElementRecipe extends Recipe {

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/MatchingRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand Down Expand Up @@ -71,7 +71,7 @@ public List<Recipe> getRecipeList() {
* OpenRewrite recipe created for Refaster template {@code Matching.StringIsEmpty}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class StringIsEmptyRecipe extends Recipe {

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/MethodThrowsRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand All @@ -38,7 +38,7 @@
* OpenRewrite recipe created for Refaster template {@code MethodThrows}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class MethodThrowsRecipe extends Recipe {

Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/refaster/MultipleDereferencesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand Down Expand Up @@ -68,7 +68,7 @@ public List<Recipe> getRecipeList() {
* OpenRewrite recipe created for Refaster template {@code MultipleDereferences.VoidType}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class VoidTypeRecipe extends Recipe {

Expand Down Expand Up @@ -127,7 +127,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
* OpenRewrite recipe created for Refaster template {@code MultipleDereferences.StringIsEmpty}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class StringIsEmptyRecipe extends Recipe {

Expand Down Expand Up @@ -182,7 +182,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
* OpenRewrite recipe created for Refaster template {@code MultipleDereferences.EqualsItself}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class EqualsItselfRecipe extends Recipe {

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/NestedPreconditionsRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand All @@ -38,7 +38,7 @@
* OpenRewrite recipe created for Refaster template {@code NestedPreconditions}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class NestedPreconditionsRecipe extends Recipe {

Expand Down
6 changes: 3 additions & 3 deletions src/test/resources/refaster/ParametersRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand Down Expand Up @@ -67,7 +67,7 @@ public List<Recipe> getRecipeList() {
* OpenRewrite recipe created for Refaster template {@code Parameters.Reuse}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class ReuseRecipe extends Recipe {

Expand Down Expand Up @@ -119,7 +119,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) {
* OpenRewrite recipe created for Refaster template {@code Parameters.Order}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class OrderRecipe extends Recipe {

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/PicnicRulesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand Down Expand Up @@ -66,7 +66,7 @@ public List<Recipe> getRecipeList() {
* OpenRewrite recipe created for Refaster template {@code PicnicRules.NestedRule}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class NestedRuleRecipe extends Recipe {

Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/refaster/RefasterAnyOfRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package foo;

import org.jspecify.annotations.NullMarked;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.JavaTemplate;
import org.openrewrite.java.JavaVisitor;
Expand Down Expand Up @@ -68,7 +68,7 @@ public List<Recipe> getRecipeList() {
* OpenRewrite recipe created for Refaster template {@code RefasterAnyOf.StringIsEmpty}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class StringIsEmptyRecipe extends Recipe {

Expand Down Expand Up @@ -134,7 +134,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
* OpenRewrite recipe created for Refaster template {@code RefasterAnyOf.EmptyList}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class EmptyListRecipe extends Recipe {

Expand Down Expand Up @@ -214,7 +214,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
* OpenRewrite recipe created for Refaster template {@code RefasterAnyOf.NewStringFromCharArraySubSequence}.
*/
@SuppressWarnings("all")
@NonNullApi
@NullMarked
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class NewStringFromCharArraySubSequenceRecipe extends Recipe {

Expand Down
Loading

0 comments on commit e713ca6

Please sign in to comment.