Skip to content

Commit

Permalink
Migrate to JSpecify from OpenRewrite JSR-305 meta-annotations (#110)
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 authored Aug 15, 2024
1 parent 858d8b2 commit 2cbc367
Show file tree
Hide file tree
Showing 37 changed files with 78 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/javascript/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.ExecutionContext;
import org.openrewrite.ParseExceptionResult;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.Space;
import org.openrewrite.javascript.tree.JS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package org.openrewrite.javascript;

import lombok.Value;
import org.jspecify.annotations.Nullable;
import org.openrewrite.ExecutionContext;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Parser;
import org.openrewrite.SourceFile;
import org.openrewrite.internal.EncodingDetectingInputStream;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.internal.JavaTypeCache;
import org.openrewrite.javascript.internal.JavetNativeBridge;
import org.openrewrite.javascript.internal.TypeScriptParserVisitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package org.openrewrite.javascript;

import org.jspecify.annotations.Nullable;
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.javascript.tree.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.openrewrite.javascript;

import org.jspecify.annotations.Nullable;
import org.openrewrite.Incubating;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaTypeSignatureBuilder;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.javascript.internal.tsc.TSCNode;
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/openrewrite/javascript/TypeScriptTypeMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.openrewrite.javascript;

import org.jspecify.annotations.Nullable;
import org.openrewrite.Incubating;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaTypeMapping;
import org.openrewrite.java.internal.JavaTypeCache;
import org.openrewrite.java.tree.Flag;
Expand Down Expand Up @@ -107,11 +107,11 @@ private JavaType array(TSCNode node, String signature) {
return arr;
}

private @Nullable JavaType.FullyQualified classType(@Nullable TSCNode node) {
private JavaType.@Nullable FullyQualified classType(@Nullable TSCNode node) {
return classType(node, signatureBuilder.signature(node));
}

private @Nullable JavaType.FullyQualified classType(@Nullable TSCNode node, String signature) {
private JavaType.@Nullable FullyQualified classType(@Nullable TSCNode node, String signature) {
if (node == null || node.syntaxKind() != TSCSyntaxKind.SourceFile && node.getTypeForNode() == null) {
return null;
}
Expand Down Expand Up @@ -279,11 +279,11 @@ public JavaType.GenericTypeVariable generic(TSCNode node, String signature) {
return gtv;
}

public @Nullable JavaType.Method methodDeclarationType(TSCNode node) {
public JavaType.@Nullable Method methodDeclarationType(TSCNode node) {
return methodDeclarationType(node, null);
}

public @Nullable JavaType.Method methodDeclarationType(TSCNode node, @Nullable JavaType.FullyQualified declaringType) {
public JavaType.@Nullable Method methodDeclarationType(TSCNode node, JavaType.@Nullable FullyQualified declaringType) {

String signature = signatureBuilder.methodSignature(node);
JavaType.Method existing = typeCache.get(signature);
Expand Down Expand Up @@ -343,7 +343,7 @@ public JavaType.GenericTypeVariable generic(TSCNode node, String signature) {
return method;
}

public @Nullable JavaType.Method methodInvocationType(TSCNode node) {
public JavaType.@Nullable Method methodInvocationType(TSCNode node) {
String signature = signatureBuilder.methodSignature(node);
JavaType.Method existing = typeCache.get(signature);
if (existing != null) {
Expand Down Expand Up @@ -430,19 +430,19 @@ public JavaType.Primitive primitive(TSCNode node) {
return JavaType.Primitive.None;
}

public @Nullable JavaType.Variable variableType(TSCNode node) {
public JavaType.@Nullable Variable variableType(TSCNode node) {
return variableType(node, null, signatureBuilder.variableSignature(node));
}

public @Nullable JavaType.Variable variableType(TSCNode node, String signature) {
public JavaType.@Nullable Variable variableType(TSCNode node, String signature) {
return variableType(node, null, signature);
}

public @Nullable JavaType.Variable variableType(TSCNode node, @Nullable JavaType.FullyQualified declaringType) {
public JavaType.@Nullable Variable variableType(TSCNode node, JavaType.@Nullable FullyQualified declaringType) {
return variableType(node, declaringType, signatureBuilder.variableSignature(node));
}

public @Nullable JavaType.Variable variableType(TSCNode node, @Nullable JavaType.FullyQualified declaringType, String signature) {
public JavaType.@Nullable Variable variableType(TSCNode node, JavaType.@Nullable FullyQualified declaringType, String signature) {
JavaType.Variable existing = typeCache.get(signature);
if (existing != null) {
return existing;
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.javascript.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 @@ -15,8 +15,8 @@
*/
package org.openrewrite.javascript.format;

import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.tree.J;
import org.openrewrite.javascript.JavaScriptIsoVisitor;
import org.openrewrite.javascript.style.IntelliJ;
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.javascript.format;

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 @@ -15,10 +15,10 @@
*/
package org.openrewrite.javascript.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.OmitParentheses;
import org.openrewrite.java.marker.Semicolon;
Expand Down Expand Up @@ -758,7 +758,7 @@ protected void beforeSyntax(J j, JsSpace.Location loc, PrintOutputCapture<P> p)
beforeSyntax(j.getPrefix(), j.getMarkers(), loc, p);
}

private void beforeSyntax(Space prefix, Markers markers, @Nullable JsSpace.Location loc, PrintOutputCapture<P> p) {
private void beforeSyntax(Space prefix, Markers markers, JsSpace.@Nullable Location loc, PrintOutputCapture<P> p) {
for (Marker marker : markers.getMarkers()) {
p.append(p.getMarkerPrinter().beforePrefix(marker, new Cursor(getCursor(), marker), JAVA_SCRIPT_MARKER_WRAPPER));
}
Expand All @@ -775,7 +775,7 @@ protected void beforeSyntax(J j, Space.Location loc, PrintOutputCapture<P> p) {
beforeSyntax(j.getPrefix(), j.getMarkers(), loc, p);
}

protected void beforeSyntax(Space prefix, Markers markers, @Nullable Space.Location loc, PrintOutputCapture<P> p) {
protected void beforeSyntax(Space prefix, Markers markers, Space.@Nullable Location loc, PrintOutputCapture<P> p) {
for (Marker marker : markers.getMarkers()) {
p.out.append(p.getMarkerPrinter().beforePrefix(marker, new Cursor(getCursor(), marker), JAVA_SCRIPT_MARKER_WRAPPER));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.openrewrite.javascript.internal;

import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.caoccao.javet.exceptions.JavetException;
import com.caoccao.javet.interop.loader.JavetLibLoader;
import com.caoccao.javet.utils.JavetOSUtils;
import org.jspecify.annotations.Nullable;
import org.openrewrite.internal.StringUtils;
import org.openrewrite.internal.lang.Nullable;

import java.io.File;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.openrewrite.javascript.internal;

import com.caoccao.javet.values.IV8Value;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;

public class JavetUtils {
private JavetUtils() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.tree.*;
import org.openrewrite.javascript.internal.tsc.TSCNode;
import org.openrewrite.javascript.internal.tsc.TSCSourceFileContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package org.openrewrite.javascript.internal;

import org.jspecify.annotations.Nullable;
import org.openrewrite.FileAttributes;
import org.openrewrite.ParseExceptionResult;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.internal.JavaTypeCache;
import org.openrewrite.java.marker.Semicolon;
import org.openrewrite.java.marker.TrailingComma;
Expand Down Expand Up @@ -486,7 +486,7 @@ private void visitBinaryUpdateExpression(TSCNode incrementor, List<JRightPadded<
updates.add(padRight(r, after));
}

private @Nullable J.Block visitBlock(@Nullable TSCNode node) {
private J.@Nullable Block visitBlock(@Nullable TSCNode node) {
if (node == null) {
return null;
}
Expand Down Expand Up @@ -1320,7 +1320,7 @@ private J.Identifier visitIdentifier(TSCNode node, @Nullable JavaType type) {
return visitIdentifier(node, type, null);
}

private J.Identifier visitIdentifier(TSCNode node, @Nullable JavaType type, @Nullable JavaType.Variable fieldType) {
private J.Identifier visitIdentifier(TSCNode node, @Nullable JavaType type, JavaType.@Nullable Variable fieldType) {
Space prefix = whitespace();
skip(node.getText());
// TODO: check on escapedText property.
Expand Down Expand Up @@ -3449,7 +3449,7 @@ private List<J.Modifier> mapModifiers(@Nullable List<TSCNode> nodes, List<J.Anno
return modifiers.isEmpty() ? new ArrayList<>() : modifiers;
}

private @Nullable J.TypeParameters mapTypeParameters(@Nullable List<TSCNode> typeParameters) {
private J.@Nullable TypeParameters mapTypeParameters(@Nullable List<TSCNode> typeParameters) {
return typeParameters == null ? null : new J.TypeParameters(randomId(), sourceBefore(TSCSyntaxKind.LessThanToken), Markers.EMPTY,
emptyList(),
convertAll(typeParameters, commaDelim, t -> sourceBefore(TSCSyntaxKind.GreaterThanToken)));
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.javascript.internal;

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 @@ -17,7 +17,7 @@

import com.caoccao.javet.exceptions.JavetException;
import com.caoccao.javet.values.V8Value;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;

public interface TSCConversion<T> {
T convertUnsafe(TSCProgramContext context, V8Value value) throws JavetException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.caoccao.javet.exceptions.JavetException;
import com.caoccao.javet.values.reference.V8ValueObject;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.function.Supplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.caoccao.javet.values.reference.V8ValueFunction;
import com.caoccao.javet.values.reference.V8ValueObject;
import org.intellij.lang.annotations.Language;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;

public class TSCInstanceOfChecks extends TSCV8ValueHolder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.caoccao.javet.values.V8Value;
import com.caoccao.javet.values.reference.V8ValueArray;
import com.caoccao.javet.values.reference.V8ValueObject;
import org.jspecify.annotations.Nullable;
import org.openrewrite.DebugOnly;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.javascript.internal.tsc.generated.TSCSyntaxKind;

import java.io.PrintStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.caoccao.javet.values.reference.V8ValueObject;
import lombok.Getter;
import lombok.Value;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -109,11 +109,11 @@ public TSCGlobals getTypeScriptGlobals() {
return this.typescriptGlobals;
}

public @Nullable TSCInstanceOfChecks.InterfaceKind identifyInterfaceKind(V8Value valueV8) {
public TSCInstanceOfChecks.@Nullable InterfaceKind identifyInterfaceKind(V8Value valueV8) {
return this.getInstanceOfChecks().identifyInterfaceKind(valueV8);
}

public @Nullable TSCInstanceOfChecks.ConstructorKind identifyConstructorKind(V8Value valueV8) {
public TSCInstanceOfChecks.@Nullable ConstructorKind identifyConstructorKind(V8Value valueV8) {
return this.getInstanceOfChecks().identifyConstructorKind(valueV8);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import com.caoccao.javet.values.reference.V8ValueMap;
import com.caoccao.javet.values.reference.V8ValueObject;
import org.intellij.lang.annotations.Language;
import org.jspecify.annotations.Nullable;
import org.openrewrite.DebugOnly;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.javascript.internal.JavetUtils;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.caoccao.javet.exceptions.JavetException;
import com.caoccao.javet.values.reference.V8ValueObject;
import lombok.Value;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.openrewrite.javascript.internal.tsc.generated.TSCSymbolFlag;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package org.openrewrite.javascript.internal.tsc;

import com.caoccao.javet.values.reference.V8ValueObject;
import org.openrewrite.internal.lang.NonNull;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.openrewrite.javascript.internal.tsc;

import org.jspecify.annotations.Nullable;
import org.openrewrite.DebugOnly;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.javascript.internal.tsc.generated.TSCObjectFlag;
import org.openrewrite.javascript.internal.tsc.generated.TSCTypeFlag;

Expand Down Expand Up @@ -312,7 +312,7 @@ default TSCType getTarget() {
return getTypeProperty("target");
}

default @Nullable TSCNode.TypeNode getNode() {
default TSCNode.@Nullable TypeNode getNode() {
return getOptionalTypeNodeProperty("node");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.openrewrite.javascript.internal.tsc;

import com.caoccao.javet.values.reference.V8ValueObject;
import org.openrewrite.internal.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.openrewrite.javascript.internal.tsc.generated.TSCIndexKind;
import org.openrewrite.javascript.internal.tsc.generated.TSCSignatureKind;
import org.openrewrite.javascript.internal.tsc.generated.TSCSymbolFlag;
Expand Down
Loading

0 comments on commit 2cbc367

Please sign in to comment.