diff --git a/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java b/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java index 6c41d40a..42c4cf5d 100644 --- a/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java +++ b/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java @@ -443,18 +443,15 @@ public N visitTypeName(N nameTree, P p) { return nameTree; } - @Nullable - private JLeftPadded visitTypeName(@Nullable JLeftPadded nameTree, P p) { + private @Nullable JLeftPadded visitTypeName(@Nullable JLeftPadded nameTree, P p) { return nameTree == null ? null : nameTree.withElement(visitTypeName(nameTree.getElement(), p)); } - @Nullable - private JRightPadded visitTypeName(@Nullable JRightPadded nameTree, P p) { + private @Nullable JRightPadded visitTypeName(@Nullable JRightPadded nameTree, P p) { return nameTree == null ? null : nameTree.withElement(visitTypeName(nameTree.getElement(), p)); } - @Nullable - private JContainer visitTypeNames(@Nullable JContainer nameTrees, P p) { + private @Nullable JContainer visitTypeNames(@Nullable JContainer nameTrees, P p) { if (nameTrees == null) { return null; } diff --git a/src/main/java/org/openrewrite/javascript/TypeScriptTypeMapping.java b/src/main/java/org/openrewrite/javascript/TypeScriptTypeMapping.java index 4e4d07b8..5ea0619c 100644 --- a/src/main/java/org/openrewrite/javascript/TypeScriptTypeMapping.java +++ b/src/main/java/org/openrewrite/javascript/TypeScriptTypeMapping.java @@ -107,13 +107,11 @@ private JavaType array(TSCNode node, String signature) { return arr; } - @Nullable - private JavaType.FullyQualified classType(@Nullable TSCNode node) { + private @Nullable JavaType.FullyQualified classType(@Nullable TSCNode node) { return classType(node, signatureBuilder.signature(node)); } - @Nullable - private JavaType.FullyQualified classType(@Nullable TSCNode node, String signature) { + private @Nullable JavaType.FullyQualified classType(@Nullable TSCNode node, String signature) { if (node == null || node.syntaxKind() != TSCSyntaxKind.SourceFile && node.getTypeForNode() == null) { return null; } @@ -281,13 +279,11 @@ public JavaType.GenericTypeVariable generic(TSCNode node, String signature) { return gtv; } - @Nullable - public JavaType.Method methodDeclarationType(TSCNode node) { + public @Nullable JavaType.Method methodDeclarationType(TSCNode node) { return methodDeclarationType(node, null); } - @Nullable - public JavaType.Method methodDeclarationType(TSCNode node, @Nullable JavaType.FullyQualified declaringType) { + public @Nullable JavaType.Method methodDeclarationType(TSCNode node, @Nullable JavaType.FullyQualified declaringType) { String signature = signatureBuilder.methodSignature(node); JavaType.Method existing = typeCache.get(signature); @@ -347,8 +343,7 @@ public JavaType.Method methodDeclarationType(TSCNode node, @Nullable JavaType.Fu return method; } - @Nullable - public JavaType.Method methodInvocationType(TSCNode node) { + public @Nullable JavaType.Method methodInvocationType(TSCNode node) { String signature = signatureBuilder.methodSignature(node); JavaType.Method existing = typeCache.get(signature); if (existing != null) { @@ -435,23 +430,19 @@ public JavaType.Primitive primitive(TSCNode node) { return JavaType.Primitive.None; } - @Nullable - public JavaType.Variable variableType(TSCNode node) { + public @Nullable JavaType.Variable variableType(TSCNode node) { return variableType(node, null, signatureBuilder.variableSignature(node)); } - @Nullable - public JavaType.Variable variableType(TSCNode node, String signature) { + public @Nullable JavaType.Variable variableType(TSCNode node, String signature) { return variableType(node, null, signature); } - @Nullable - public JavaType.Variable variableType(TSCNode node, @Nullable JavaType.FullyQualified declaringType) { + public @Nullable JavaType.Variable variableType(TSCNode node, @Nullable JavaType.FullyQualified declaringType) { return variableType(node, declaringType, signatureBuilder.variableSignature(node)); } - @Nullable - public JavaType.Variable variableType(TSCNode node, @Nullable JavaType.FullyQualified declaringType, String signature) { + public @Nullable JavaType.Variable variableType(TSCNode node, @Nullable JavaType.FullyQualified declaringType, String signature) { JavaType.Variable existing = typeCache.get(signature); if (existing != null) { return existing; @@ -490,8 +481,7 @@ public JavaType.Variable variableType(TSCNode node, @Nullable JavaType.FullyQual return variable; } - @Nullable - private List mapAnnotations(@Nullable List modifiers) { + private @Nullable List mapAnnotations(@Nullable List modifiers) { if (modifiers == null || modifiers.isEmpty()) { return null; } diff --git a/src/main/java/org/openrewrite/javascript/internal/JavaScriptTypeCache.java b/src/main/java/org/openrewrite/javascript/internal/JavaScriptTypeCache.java index 585c6e2e..a0c5f487 100644 --- a/src/main/java/org/openrewrite/javascript/internal/JavaScriptTypeCache.java +++ b/src/main/java/org/openrewrite/javascript/internal/JavaScriptTypeCache.java @@ -24,8 +24,7 @@ public class JavaScriptTypeCache implements Cloneable { Map typeCache = new HashMap<>(); - @Nullable - public T get(String signature) { + public @Nullable T get(String signature) { //noinspection unchecked return (T) typeCache.get(key(signature)); } diff --git a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java index 3d21e247..f25987ac 100644 --- a/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java +++ b/src/main/java/org/openrewrite/javascript/internal/TypeScriptParserVisitor.java @@ -486,8 +486,7 @@ private void visitBinaryUpdateExpression(TSCNode incrementor, List mapModifiers(@Nullable List nodes, List() : modifiers; } - @Nullable - private J.TypeParameters mapTypeParameters(@Nullable List typeParameters) { + private @Nullable J.TypeParameters mapTypeParameters(@Nullable List typeParameters) { return typeParameters == null ? null : new J.TypeParameters(randomId(), sourceBefore(TSCSyntaxKind.LessThanToken), Markers.EMPTY, emptyList(), convertAll(typeParameters, commaDelim, t -> sourceBefore(TSCSyntaxKind.GreaterThanToken))); diff --git a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCNode.java b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCNode.java index cc3db7b6..e23b25fe 100644 --- a/src/main/java/org/openrewrite/javascript/internal/tsc/TSCNode.java +++ b/src/main/java/org/openrewrite/javascript/internal/tsc/TSCNode.java @@ -135,8 +135,7 @@ public TSCSyntaxKind syntaxKind() { return TSCSyntaxKind.fromCode(this.syntaxKindCode()); } - @Nullable - public TSCType getTypeForNode() { + public @Nullable TSCType getTypeForNode() { return this.programContext.getTypeChecker().getTypeAtLocation(this); } @@ -209,8 +208,7 @@ public boolean containsPosition(int position) { return position >= this.getStart() && position < this.getEnd(); } - @Nullable - public TSCSymbol getSymbolForNode() { + public @Nullable TSCSymbol getSymbolForNode() { return this.programContext.getTypeChecker().getSymbolAtLocation(this); } @@ -250,8 +248,7 @@ public int getChildCount() { } @Deprecated - @Nullable - public TSCNode getChildNode(String name) { + public @Nullable TSCNode getChildNode(String name) { return getOptionalNodeProperty(name); } diff --git a/src/main/java/org/openrewrite/javascript/tree/JS.java b/src/main/java/org/openrewrite/javascript/tree/JS.java index 6737da78..e390532c 100644 --- a/src/main/java/org/openrewrite/javascript/tree/JS.java +++ b/src/main/java/org/openrewrite/javascript/tree/JS.java @@ -56,8 +56,7 @@ default

boolean isAcceptable(TreeVisitor v, P p) { return v.isAdaptableTo(JavaScriptVisitor.class); } - @Nullable - default

J acceptJavaScript(JavaScriptVisitor

v, P p) { + default

@Nullable J acceptJavaScript(JavaScriptVisitor

v, P p) { return v.defaultValue(this, p); } @@ -310,9 +309,8 @@ public

J acceptJavaScript(JavaScriptVisitor

v, P p) { return v.visitAlias(this, p); } - @Nullable @Override - public JavaType getType() { + public @Nullable JavaType getType() { return propertyName.getElement().getType(); } @@ -497,8 +495,7 @@ class Export implements JS, Statement { @Nullable JContainer exports; - @Nullable - public List getExports() { + public @Nullable List getExports() { return exports == null ? null : exports.getElements(); } @@ -519,8 +516,7 @@ public Export withExports(List exports) { @Nullable JLeftPadded initializer; - @Nullable - public Expression getInitializer() { + public @Nullable Expression getInitializer() { return initializer == null ? null : initializer.getElement(); } @@ -557,8 +553,7 @@ public Export.Padding getPadding() { public static class Padding { private final Export t; - @Nullable - public JContainer getExports() { + public @Nullable JContainer getExports() { return t.exports; } @@ -566,8 +561,7 @@ public Export withExports(@Nullable JContainer exports) { return t.exports == exports ? t : new Export(t.id, t.prefix, t.markers, exports, t.from, t.target, t.initializer); } - @Nullable - public JLeftPadded getInitializer() { + public @Nullable JLeftPadded getInitializer() { return t.initializer; } @@ -621,9 +615,8 @@ public Markers getMarkers() { return expression.getMarkers(); } - @Nullable @Override - public JavaType getType() { + public @Nullable JavaType getType() { return expression.getType(); } @@ -750,8 +743,7 @@ class JsImport implements JS, Statement { @Nullable JRightPadded name; - @Nullable - public J.Identifier getName() { + public @Nullable J.Identifier getName() { return name == null ? null : name.getElement(); } @@ -762,8 +754,7 @@ public JsImport withName(@Nullable J.Identifier name) { @Nullable JContainer imports; - @Nullable - public List getImports() { + public @Nullable List getImports() { return imports == null ? null : imports.getElements(); } @@ -784,8 +775,7 @@ public JsImport withImports(List imports) { @Nullable JLeftPadded initializer; - @Nullable - public Expression getInitializer() { + public @Nullable Expression getInitializer() { return initializer == null ? null : initializer.getElement(); } @@ -822,8 +812,7 @@ public JsImport.Padding getPadding() { public static class Padding { private final JsImport t; - @Nullable - public JRightPadded getName() { + public @Nullable JRightPadded getName() { return t.name; } @@ -831,8 +820,7 @@ public JsImport withName(@Nullable JRightPadded name) { return t.name == name ? t : new JsImport(t.id, t.prefix, t.markers, name, t.imports, t.from, t.target, t.initializer); } - @Nullable - public JContainer getImports() { + public @Nullable JContainer getImports() { return t.imports; } @@ -840,8 +828,7 @@ public JsImport withImports(@Nullable JContainer imports) { return t.imports == imports ? t : new JsImport(t.id, t.prefix, t.markers, t.name, imports, t.from, t.target, t.initializer); } - @Nullable - public JLeftPadded getInitializer() { + public @Nullable JLeftPadded getInitializer() { return t.initializer; } @@ -1076,8 +1063,7 @@ public ObjectBindingDeclarations withBindings(List initializer; - @Nullable - public Expression getInitializer() { + public @Nullable Expression getInitializer() { return initializer == null ? null : initializer.getElement(); } @@ -1108,14 +1094,12 @@ public List getAllAnnotations() { return allAnnotations; } - @Nullable - public JavaType.FullyQualified getTypeAsFullyQualified() { + public @Nullable JavaType.FullyQualified getTypeAsFullyQualified() { return typeExpression == null ? null : TypeUtils.asFullyQualified(typeExpression.getType()); } - @Nullable @Override - public JavaType getType() { + public @Nullable JavaType getType() { return typeExpression == null ? null : typeExpression.getType(); } @@ -1153,8 +1137,7 @@ public static final class Binding implements JS, NameTree { @Nullable JRightPadded propertyName; - @Nullable - public J.Identifier getPropertyName() { + public @Nullable J.Identifier getPropertyName() { return propertyName == null ? null : propertyName.getElement(); } @@ -1178,8 +1161,7 @@ public ObjectBindingDeclarations.Binding withPropertyName(@Nullable J.Identifier @Nullable JLeftPadded initializer; - @Nullable - public Expression getInitializer() { + public @Nullable Expression getInitializer() { return initializer == null ? null : initializer.getElement(); } @@ -1231,8 +1213,7 @@ public ObjectBindingDeclarations.Binding.Padding getPadding() { public static class Padding { private final ObjectBindingDeclarations.Binding t; - @Nullable - public JRightPadded getPropertyName() { + public @Nullable JRightPadded getPropertyName() { return t.propertyName; } @@ -1240,8 +1221,7 @@ public ObjectBindingDeclarations.Binding withPropertyName(@Nullable JRightPadded return t.propertyName == propertyName ? t : new ObjectBindingDeclarations.Binding(t.id, t.prefix, t.markers, propertyName, t.name, t.dimensionsAfterName, t.afterVararg, t.initializer, t.variableType); } - @Nullable - public JLeftPadded getInitializer() { + public @Nullable JLeftPadded getInitializer() { return t.initializer; } @@ -1282,8 +1262,7 @@ public ObjectBindingDeclarations withBindings(JContainer getInitializer() { + public @Nullable JLeftPadded getInitializer() { return t.initializer; } @@ -1337,9 +1316,8 @@ public Markers getMarkers() { return statement.getMarkers(); } - @Nullable @Override - public JavaType getType() { + public @Nullable JavaType getType() { return null; } @@ -1382,8 +1360,7 @@ final class TemplateExpression implements JS, Statement, Expression { @Nullable JRightPadded tag; - @Nullable - public Expression getTag() { + public @Nullable Expression getTag() { return tag == null ? null : tag.getElement(); } @@ -1446,8 +1423,7 @@ public TemplateExpression.Padding getPadding() { public static class Padding { private final TemplateExpression t; - @Nullable - public JRightPadded getTag() { + public @Nullable JRightPadded getTag() { return t.tag; } @@ -1579,9 +1555,8 @@ public TypeDeclaration withInitializer(Expression initializer) { @Nullable JavaType javaType; - @Nullable @Override - public JavaType getType() { + public @Nullable JavaType getType() { return javaType; } @@ -1665,9 +1640,8 @@ public JS.TypeOperator withExpression(Expression expression) { return getPadding().withExpression(this.expression.withElement(expression)); } - @Nullable @Override - public JavaType getType() { + public @Nullable JavaType getType() { return expression.getElement().getType(); }