Skip to content

Commit

Permalink
refactor: Move @Nullable method annotations to the return type
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider and TeamModerne committed Jul 16, 2024
1 parent 36c4ca5 commit f67d4df
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,18 +443,15 @@ public <N extends NameTree> N visitTypeName(N nameTree, P p) {
return nameTree;
}

@Nullable
private <N extends NameTree> JLeftPadded<N> visitTypeName(@Nullable JLeftPadded<N> nameTree, P p) {
private <N extends NameTree> @Nullable JLeftPadded<N> visitTypeName(@Nullable JLeftPadded<N> nameTree, P p) {
return nameTree == null ? null : nameTree.withElement(visitTypeName(nameTree.getElement(), p));
}

@Nullable
private <N extends NameTree> JRightPadded<N> visitTypeName(@Nullable JRightPadded<N> nameTree, P p) {
private <N extends NameTree> @Nullable JRightPadded<N> visitTypeName(@Nullable JRightPadded<N> nameTree, P p) {
return nameTree == null ? null : nameTree.withElement(visitTypeName(nameTree.getElement(), p));
}

@Nullable
private <J2 extends J> JContainer<J2> visitTypeNames(@Nullable JContainer<J2> nameTrees, P p) {
private <J2 extends J> @Nullable JContainer<J2> visitTypeNames(@Nullable JContainer<J2> nameTrees, P p) {
if (nameTrees == null) {
return null;
}
Expand Down
30 changes: 10 additions & 20 deletions src/main/java/org/openrewrite/javascript/TypeScriptTypeMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -490,8 +481,7 @@ public JavaType.Variable variableType(TSCNode node, @Nullable JavaType.FullyQual
return variable;
}

@Nullable
private List<JavaType.FullyQualified> mapAnnotations(@Nullable List<TSCNode> modifiers) {
private @Nullable List<JavaType.FullyQualified> mapAnnotations(@Nullable List<TSCNode> modifiers) {
if (modifiers == null || modifiers.isEmpty()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class JavaScriptTypeCache implements Cloneable {

Map<Object, Object> typeCache = new HashMap<>();

@Nullable
public <T> T get(String signature) {
public <T> @Nullable T get(String signature) {
//noinspection unchecked
return (T) typeCache.get(key(signature));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ private void visitBinaryUpdateExpression(TSCNode incrementor, List<JRightPadded<
updates.add(padRight(r, after));
}

@Nullable
private J.Block visitBlock(@Nullable TSCNode node) {
private @Nullable J.Block visitBlock(@Nullable TSCNode node) {
if (node == null) {
return null;
}
Expand Down Expand Up @@ -2822,8 +2821,7 @@ private J visitYieldExpression(TSCNode node) {
);
}

@Nullable
private J visitNode(@Nullable TSCNode node) {
private @Nullable J visitNode(@Nullable TSCNode node) {
if (node == null) {
return null;
}
Expand Down Expand Up @@ -3451,8 +3449,7 @@ private List<J.Modifier> mapModifiers(@Nullable List<TSCNode> nodes, List<J.Anno
return modifiers.isEmpty() ? new ArrayList<>() : modifiers;
}

@Nullable
private J.TypeParameters mapTypeParameters(@Nullable List<TSCNode> typeParameters) {
private @Nullable J.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 @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -250,8 +248,7 @@ public int getChildCount() {
}

@Deprecated
@Nullable
public TSCNode getChildNode(String name) {
public @Nullable TSCNode getChildNode(String name) {
return getOptionalNodeProperty(name);
}

Expand Down
Loading

0 comments on commit f67d4df

Please sign in to comment.