Skip to content

Commit

Permalink
Migrate to JSpecify from OpenRewrite JSR-305 meta-annotations
Browse files Browse the repository at this point in the history
Use this link to re-run the recipe: https://app.moderne.io/builder/gW3xaSLWV?organizationId=T3BlblJld3JpdGU%3D

Co-authored-by: Moderne <[email protected]>
  • Loading branch information
jkschneider and TeamModerne committed Aug 15, 2024
1 parent ac8c497 commit 37bf99e
Show file tree
Hide file tree
Showing 42 changed files with 78 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/kotlin/AddImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package org.openrewrite.kotlin;

import lombok.EqualsAndHashCode;
import org.jspecify.annotations.Nullable;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.marker.JavaSourceSet;
import org.openrewrite.java.search.FindMethods;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/kotlin/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@


import org.intellij.lang.annotations.Language;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.ThrowingConsumer;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.search.FindMissingTypes;
import org.openrewrite.java.tree.*;
import org.openrewrite.kotlin.marker.Extension;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/openrewrite/kotlin/FindKotlinSources.java
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.kotlin.table.KotlinSourceFile;
import org.openrewrite.kotlin.tree.K;
import org.openrewrite.marker.SearchResult;
Expand Down Expand Up @@ -65,7 +65,7 @@ public Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
return tree;
}

private @Nullable KotlinSourceFile.SourceFileType getSourceFileType(SourceFile sourceFile) {
private KotlinSourceFile.@Nullable SourceFileType getSourceFileType(SourceFile sourceFile) {
KotlinSourceFile.SourceFileType sourceFileType = null;
if (sourceFile instanceof K.CompilationUnit) {
sourceFileType = KotlinSourceFile.SourceFileType.Kotlin;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/kotlin/KotlinParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices;
import org.jetbrains.kotlin.utils.PathUtil;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.internal.JavaTypeCache;
import org.openrewrite.java.marker.JavaSourceSet;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/kotlin/KotlinVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package org.openrewrite.kotlin;

import org.jspecify.annotations.Nullable;
import org.openrewrite.Cursor;
import org.openrewrite.SourceFile;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.tree.*;
import org.openrewrite.kotlin.marker.*;
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.tree.Expression;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.Space;
Expand All @@ -37,8 +37,8 @@
@Value
@EqualsAndHashCode(callSuper = false)
public class EqualsMethodUsage extends Recipe {
@Nullable
private static J.Binary equalsBinaryTemplate;

private static J.@Nullable Binary equalsBinaryTemplate;

@Override
public String getDisplayName() {
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.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.PrintOutputCapture;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.Space;
import org.openrewrite.kotlin.KotlinIsoVisitor;
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.kotlin.cleanup;

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 @@ -16,10 +16,10 @@
package org.openrewrite.kotlin.format;


import org.jspecify.annotations.Nullable;
import org.openrewrite.Cursor;
import org.openrewrite.SourceFile;
import org.openrewrite.Tree;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaSourceFile;
import org.openrewrite.kotlin.KotlinIsoVisitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package org.openrewrite.kotlin.format;


import org.jspecify.annotations.Nullable;
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.tree.*;
import org.openrewrite.kotlin.KotlinIsoVisitor;
import org.openrewrite.kotlin.marker.OmitBraces;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package org.openrewrite.kotlin.format;

import com.fasterxml.jackson.annotation.JsonCreator;
import org.jspecify.annotations.Nullable;
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.marker.ImplicitReturn;
import org.openrewrite.java.tree.*;
import org.openrewrite.kotlin.KotlinIsoVisitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package org.openrewrite.kotlin.format;

import com.fasterxml.jackson.annotation.JsonCreator;
import org.jspecify.annotations.Nullable;
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.JavadocVisitor;
import org.openrewrite.java.tree.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package org.openrewrite.kotlin.format;

import org.jspecify.annotations.Nullable;
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.JavadocVisitor;
import org.openrewrite.java.tree.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package org.openrewrite.kotlin.format;


import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.internal.lang.NonNull;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.JavadocVisitor;
import org.openrewrite.java.tree.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@


import com.fasterxml.jackson.annotation.JsonCreator;
import org.jspecify.annotations.Nullable;
import org.openrewrite.Tree;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaSourceFile;
import org.openrewrite.java.tree.Space;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package org.openrewrite.kotlin.format;

import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Tree;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.tree.J;
import org.openrewrite.kotlin.KotlinIsoVisitor;
import org.openrewrite.kotlin.style.IntelliJ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package org.openrewrite.kotlin.format;

import org.jspecify.annotations.Nullable;
import org.openrewrite.PrintOutputCapture;
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.marker.OmitParentheses;
import org.openrewrite.java.marker.TrailingComma;
import org.openrewrite.java.tree.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package org.openrewrite.kotlin.format;

import org.jspecify.annotations.Nullable;
import org.openrewrite.Cursor;
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.marker.ImplicitReturn;
import org.openrewrite.java.tree.*;
import org.openrewrite.kotlin.KotlinIsoVisitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package org.openrewrite.kotlin.format;


import org.jspecify.annotations.Nullable;
import org.openrewrite.Cursor;
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.tree.*;
import org.openrewrite.kotlin.KotlinIsoVisitor;
import org.openrewrite.kotlin.marker.OmitBraces;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/openrewrite/kotlin/format/package-info.java
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.kotlin.format;

import org.openrewrite.internal.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
import org.openrewrite.internal.lang.NonNullFields;
10 changes: 5 additions & 5 deletions src/main/java/org/openrewrite/kotlin/internal/KotlinPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package org.openrewrite.kotlin.internal;

import org.jspecify.annotations.Nullable;
import org.openrewrite.Cursor;
import org.openrewrite.PrintOutputCapture;
import org.openrewrite.Tree;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaPrinter;
import org.openrewrite.java.marker.ImplicitReturn;
import org.openrewrite.java.marker.OmitParentheses;
Expand Down Expand Up @@ -645,7 +645,7 @@ public J visitClassDeclaration(J.ClassDeclaration classDecl, PrintOutputCapture<
return visitClassDeclaration0(classDecl, null, p);
}

private J.ClassDeclaration visitClassDeclaration0(J.ClassDeclaration classDecl, @Nullable K.TypeConstraints typeConstraints, PrintOutputCapture<P> p) {
private J.ClassDeclaration visitClassDeclaration0(J.ClassDeclaration classDecl, K.@Nullable TypeConstraints typeConstraints, PrintOutputCapture<P> p) {
beforeSyntax(classDecl, Space.Location.CLASS_DECLARATION_PREFIX, p);
visit(classDecl.getLeadingAnnotations(), p);
for (J.Modifier m : classDecl.getModifiers()) {
Expand Down Expand Up @@ -884,7 +884,7 @@ public J visitMethodDeclaration(J.MethodDeclaration method, PrintOutputCapture<P
return visitMethodDeclaration0(method, null, p);
}

private J.MethodDeclaration visitMethodDeclaration0(J.MethodDeclaration method, @Nullable K.TypeConstraints typeConstraints, PrintOutputCapture<P> p) {
private J.MethodDeclaration visitMethodDeclaration0(J.MethodDeclaration method, K.@Nullable TypeConstraints typeConstraints, PrintOutputCapture<P> p) {
// Do not print generated methods.
for (Marker marker : method.getMarkers().getMarkers()) {
if (marker instanceof Implicit || marker instanceof PrimaryConstructor) {
Expand Down Expand Up @@ -1404,7 +1404,7 @@ private void beforeSyntax(J j, Space.Location loc, PrintOutputCapture<P> p) {
beforeSyntax(j.getPrefix(), j.getMarkers(), loc, p);
}

private void beforeSyntax(Space prefix, Markers markers, @Nullable KSpace.Location loc, PrintOutputCapture<P> p) {
private void beforeSyntax(Space prefix, Markers markers, KSpace.@Nullable Location loc, PrintOutputCapture<P> p) {
for (Marker marker : markers.getMarkers()) {
p.append(p.getMarkerPrinter().beforePrefix(marker, new Cursor(getCursor(), marker), JAVA_MARKER_WRAPPER));
}
Expand All @@ -1421,7 +1421,7 @@ private void beforeSyntax(K k, Space.Location loc, PrintOutputCapture<P> p) {
beforeSyntax(k.getPrefix(), k.getMarkers(), loc, p);
}

private void beforeSyntax(Space prefix, Markers markers, @Nullable Space.Location loc, PrintOutputCapture<P> p) {
private void beforeSyntax(Space prefix, Markers markers, Space.@Nullable Location loc, PrintOutputCapture<P> p) {
for (Marker marker : markers.getMarkers()) {
p.append(p.getMarkerPrinter().beforePrefix(marker, new Cursor(getCursor(), marker), JAVA_MARKER_WRAPPER));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
import org.jetbrains.kotlin.parsing.ParseUtilsKt;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.FileAttributes;
import org.openrewrite.ParseExceptionResult;
import org.openrewrite.Tree;
import org.openrewrite.internal.EncodingDetectingInputStream;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.lang.NonNull;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.marker.ImplicitReturn;
import org.openrewrite.java.marker.OmitParentheses;
import org.openrewrite.java.marker.Quoted;
Expand Down Expand Up @@ -1923,7 +1923,7 @@ public J visitBinaryExpression(KtBinaryExpression expression, ExecutionContext d
return mapFunctionCall(expression, data);
}

private @Nullable J.AssignmentOperation.Type mapAssignmentOperationType(KtOperationReferenceExpression operationReference) {
private J.AssignmentOperation.@Nullable Type mapAssignmentOperationType(KtOperationReferenceExpression operationReference) {
IElementType elementType = operationReference.getOperationSignTokenType();

if (elementType == KtTokens.PLUSEQ) {
Expand Down Expand Up @@ -3301,7 +3301,7 @@ public J visitValueArgumentList(KtValueArgumentList list, ExecutionContext data)
/*====================================================================
* Mapping methods
* ====================================================================*/
private @Nullable K.Binary.Type mapKBinaryType(KtOperationReferenceExpression operationReference) {
private K.Binary.@Nullable Type mapKBinaryType(KtOperationReferenceExpression operationReference) {
IElementType elementType = operationReference.getOperationSignTokenType();
if (elementType == null) {
return null;
Expand All @@ -3328,7 +3328,7 @@ public J visitValueArgumentList(KtValueArgumentList list, ExecutionContext data)
}
}

private @Nullable J.Binary.Type mapJBinaryType(KtOperationReferenceExpression operationReference) {
private J.Binary.@Nullable Type mapJBinaryType(KtOperationReferenceExpression operationReference) {
IElementType elementType = operationReference.getOperationSignTokenType();

if (elementType == null) {
Expand Down Expand Up @@ -3378,7 +3378,7 @@ else if (elementType == KtTokens.OROR)
return null;
}

private @Nullable J.Unary.Type mapJUnaryType(KtSimpleNameExpression operationReference) {
private J.Unary.@Nullable Type mapJUnaryType(KtSimpleNameExpression operationReference) {
IElementType elementType = operationReference.getReferencedNameElementType();

if (elementType == KtTokens.EXCL) {
Expand Down Expand Up @@ -3444,7 +3444,7 @@ private JRightPadded<Statement> buildIfThenPart(KtIfExpression expression) {
Space.EMPTY);
}

private @Nullable J.If.Else buildIfElsePart(KtIfExpression expression) {
private J.If.@Nullable Else buildIfElsePart(KtIfExpression expression) {
if (expression.getElse() == null) {
return null;
}
Expand Down Expand Up @@ -3637,15 +3637,15 @@ private JavaType.Primitive primitiveType(PsiElement psi) {
return psiElementAssociations.primitiveType(psi);
}

private @Nullable JavaType.Variable variableType(PsiElement psi, @Nullable FirElement parent) {
private JavaType.@Nullable Variable variableType(PsiElement psi, @Nullable FirElement parent) {
return psiElementAssociations.variableType(psi, parent);
}

private @Nullable JavaType.Method methodDeclarationType(PsiElement psi) {
private JavaType.@Nullable Method methodDeclarationType(PsiElement psi) {
return psiElementAssociations.methodDeclarationType(psi);
}

private @Nullable JavaType.Method methodInvocationType(PsiElement psi) {
private JavaType.@Nullable Method methodInvocationType(PsiElement psi) {
return psiElementAssociations.methodInvocationType(psi);
}

Expand All @@ -3669,7 +3669,7 @@ private J.Identifier createIdentifier(String name, Space prefix,

private J.Identifier createIdentifier(String name, Space prefix,
@Nullable JavaType type,
@Nullable JavaType.Variable fieldType) {
JavaType.@Nullable Variable fieldType) {
Markers markers = Markers.EMPTY;
String updated = name;
if (name.startsWith("`")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.internal.JavaTypeCache;
import org.openrewrite.java.tree.*;
import org.openrewrite.kotlin.KotlinIrTypeMapping;
Expand Down
Loading

0 comments on commit 37bf99e

Please sign in to comment.