Skip to content

Commit

Permalink
Migrate to JSpecify from OpenRewrite JSR-305 meta-annotations (#580)
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]>

* Move nullable annotations on lazy init JavaParser.Builder

---------

Co-authored-by: Moderne <[email protected]>
Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent 41f6e03 commit 17b0427
Show file tree
Hide file tree
Showing 32 changed files with 58 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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.testing.assertj;

import org.openrewrite.internal.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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.testing.cleanup;

import org.openrewrite.internal.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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.testing.jmockit;

import org.openrewrite.internal.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,8 +58,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {

public static class ExpectedExceptionToAssertThrowsVisitor extends JavaIsoVisitor<ExecutionContext> {

@Nullable
private JavaParser.Builder<?, ?> javaParser;
private JavaParser.@Nullable Builder<?, ?> javaParser;

private JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -176,8 +176,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct
*/
private static class ParametersNoArgsImplicitMethodSource extends JavaIsoVisitor<ExecutionContext> {

@Nullable
private JavaParser.Builder<?, ?> javaParser;
private JavaParser.@Nullable Builder<?, ?> javaParser;

private JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -49,8 +49,8 @@ public TreeVisitor<?, ExecutionContext> 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) {
Expand Down Expand Up @@ -157,8 +157,8 @@ private J convertToNewFile(J.MethodInvocation mi, ExecutionContext ctx) {
private static class AddNewFolderMethod extends JavaIsoVisitor<ExecutionContext> {
private final J.MethodInvocation methodInvocation;

@Nullable
private JavaParser.Builder<?, ?> javaParser;

private JavaParser.@Nullable Builder<?, ?> javaParser;

private JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
Expand Down Expand Up @@ -236,8 +236,8 @@ private static class TranslateNewFolderMethodInvocation extends JavaVisitor<Exec
J.MethodInvocation methodScope;
JavaType.Method newMethodType;

@Nullable
private JavaParser.Builder<?, ?> javaParser;

private JavaParser.@Nullable Builder<?, ?> javaParser;

private JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,8 +54,7 @@ private static class TestRuleToTestInfoVisitor extends JavaIsoVisitor<ExecutionC
private static final AnnotationMatcher JUNIT_BEFORE_MATCHER = new AnnotationMatcher("@org.junit.Before");
private static final AnnotationMatcher JUPITER_BEFORE_EACH_MATCHER = new AnnotationMatcher("@org.junit.jupiter.api.BeforeEach");

@Nullable
private JavaParser.Builder<?, ?> javaParser;
private JavaParser.@Nullable Builder<?, ?> javaParser;

private JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
Expand Down Expand Up @@ -162,8 +161,7 @@ private static class BeforeMethodToTestInfoVisitor extends JavaIsoVisitor<Execut
private final J.VariableDeclarations varDecls;
private final String testMethodStatement;

@Nullable
private JavaParser.Builder<?, ?> javaParser;
private JavaParser.@Nullable Builder<?, ?> javaParser;

private JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,8 +70,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
new UsesType<>("okhttp3.mockwebserver.MockWebServer", false)
),
new JavaIsoVisitor<ExecutionContext>() {
@Nullable
private JavaParser.Builder<?, ?> javaParser;
private JavaParser.@Nullable Builder<?, ?> javaParser;

private JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
Expand Down
Loading

0 comments on commit 17b0427

Please sign in to comment.