Skip to content

Commit

Permalink
Update to match recent J.ArrayType refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Jan 4, 2024
1 parent 9a9cc84 commit 72fe3f7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 41 deletions.
24 changes: 0 additions & 24 deletions src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,30 +417,6 @@ public J visitAnnotatedType(J.AnnotatedType annotatedType, P p) {
return a;
}

@Override
public J visitArrayType(J.ArrayType arrayType, P p) {
J.ArrayType a = arrayType;
a = a.withPrefix(visitSpace(a.getPrefix(), Space.Location.ARRAY_TYPE_PREFIX, p));
a = a.withMarkers(visitMarkers(a.getMarkers(), p));
Expression temp = (Expression) visitExpression(a, p);
if (!(temp instanceof J.ArrayType)) {
return temp;
} else {
a = (J.ArrayType) temp;
}
//noinspection DataFlowIssue
a = a.withElementType(visitAndCast(a.getElementType(), p));
a = a.withElementType(visitTypeName(a.getElementType(), p));
a = a.withDimensions(
ListUtils.map(a.getDimensions(), dim ->
visitRightPadded(dim.withElement(
visitSpace(dim.getElement(), Space.Location.DIMENSION, p)
), JRightPadded.Location.DIMENSION, p)
)
);
return a;
}

@Override
public J visitParameterizedType(J.ParameterizedType type, P p) {
J.ParameterizedType pt = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public JavaType type(@Nullable TSCNode node) {
}

private JavaType array(TSCNode node, String signature) {
JavaType.Array arr = new JavaType.Array(null, null);
JavaType.Array arr = new JavaType.Array(null, null, JavaType.EMPTY_FULLY_QUALIFIED_ARRAY);
typeCache.put(signature, arr);
TSCNode elementType = node.getNodeProperty("elementType");
arr.unsafeSet(type(elementType));
arr.unsafeSet(type(elementType), null);
return arr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3332,27 +3332,16 @@ private <J2 extends J> J.ControlParentheses<J2> mapControlParentheses(TSCNode no

private J.ArrayType mapArrayType(TSCNode node) {
Space prefix = whitespace();

int dimensionsCount = 1;
TSCNode curElement = node.getNodeProperty("elementType");
while (curElement.syntaxKind() == TSCSyntaxKind.ArrayType) {
dimensionsCount++;
curElement = curElement.getNodeProperty("elementType");
}

TypeTree typeTree = (TypeTree) visitNode(curElement);
List<JRightPadded<Space>> dimensions = new ArrayList<>(dimensionsCount);
for (int i = 0; i < dimensionsCount; i++) {
Space before = sourceBefore(TSCSyntaxKind.OpenBracketToken);
dimensions.add(padRight(before, sourceBefore(TSCSyntaxKind.CloseBracketToken)));
}
TypeTree typeTree = (TypeTree) visitNode(node.getNodeProperty("elementType"));

return new J.ArrayType(
randomId(),
prefix,
Markers.EMPTY,
typeTree,
dimensions
null,
new JLeftPadded<>(sourceBefore(TSCSyntaxKind.OpenBracketToken), sourceBefore(TSCSyntaxKind.CloseBracketToken), Markers.EMPTY),
typeTree.getType()
);
}

Expand Down

0 comments on commit 72fe3f7

Please sign in to comment.