Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1348,9 +1348,22 @@ private TypeTree arrayTypeTree(Tree tree, Map<Integer, JCAnnotation> annotationP
Space prefix = whitespace();
TypeTree elemType = convert(typeIdent);
List<J.Annotation> annotations = leadingAnnotations(annotationPosTable);
JLeftPadded<Space> dimension = padLeft(sourceBefore("["), sourceBefore("]"));

// Check if this is varargs (...) or regular array brackets ([])
Markers markers = Markers.EMPTY;
JLeftPadded<Space> dimension;
int nextNonWhitespace = indexOfNextNonWhitespace(cursor, source);
if (source.startsWith("...", nextNonWhitespace)) {
// Varargs syntax
markers = markers.addIfAbsent(new org.openrewrite.java.marker.Varargs(randomId()));
dimension = padLeft(sourceBefore("..."), EMPTY);
} else {
// Regular array brackets
dimension = padLeft(sourceBefore("["), sourceBefore("]"));
}

assert arrayTypeTree != null;
return new J.ArrayType(randomId(), prefix, Markers.EMPTY,
return new J.ArrayType(randomId(), prefix, markers,
count == 1 ? elemType : mapDimensions(elemType, arrayTypeTree.getType(), annotationPosTable),
annotations,
dimension,
Expand All @@ -1366,22 +1379,32 @@ private TypeTree mapDimensions(TypeTree baseType, Tree tree, Map<Integer, JCAnno

if (typeIdent instanceof JCArrayTypeTree) {
List<J.Annotation> annotations = leadingAnnotations(annotationPosTable);
int saveCursor = cursor;
whitespace();
if (source.startsWith("[", cursor)) {
cursor = saveCursor;
JLeftPadded<Space> dimension = padLeft(sourceBefore("["), sourceBefore("]"));
return new J.ArrayType(
randomId(),
EMPTY,
Markers.EMPTY,
mapDimensions(baseType, ((JCArrayTypeTree) typeIdent).elemtype, annotationPosTable),
annotations,
dimension,
typeMapping.type(tree)
);

// Check if this is varargs (...) or regular array brackets ([])
Markers markers = Markers.EMPTY;
JLeftPadded<Space> dimension;
int nextNonWhitespace = indexOfNextNonWhitespace(cursor, source);
if (source.startsWith("...", nextNonWhitespace)) {
// Varargs syntax
markers = markers.addIfAbsent(new org.openrewrite.java.marker.Varargs(randomId()));
dimension = padLeft(sourceBefore("..."), EMPTY);
} else if (source.startsWith("[", nextNonWhitespace)) {
// Regular array brackets
dimension = padLeft(sourceBefore("["), sourceBefore("]"));
} else {
// No dimension found
return baseType;
}
cursor = saveCursor;

return new J.ArrayType(
randomId(),
EMPTY,
markers,
mapDimensions(baseType, ((JCArrayTypeTree) typeIdent).elemtype, annotationPosTable),
annotations,
dimension,
typeMapping.type(tree)
);
}
return baseType;
}
Expand Down Expand Up @@ -1562,7 +1585,7 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
}
}
int idx = indexOfNextNonWhitespace(elementType.getEndPosition(endPosTable), source);
typeExpr = idx != -1 && (source.charAt(idx) == '[' || source.charAt(idx) == '@') ? convert(vartype) :
typeExpr = idx != -1 && (source.charAt(idx) == '[' || source.charAt(idx) == '@' || source.startsWith("...", idx)) ? convert(vartype) :
// we'll capture the array dimensions in a bit, just convert the element type
convert(elementType);
} else {
Expand All @@ -1588,17 +1611,6 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
typeExpr = new J.AnnotatedType(randomId(), prefix, Markers.EMPTY, ListUtils.mapFirst(typeExprAnnotations, a -> a.withPrefix(EMPTY)), typeExpr);
}

List<JLeftPadded<Space>> beforeDimensions = emptyList();

Space varargs = null;
if (typeExpr != null && typeExpr.getMarkers().findFirst(JavaVarKeyword.class).isEmpty()) {
int varargStart = indexOfNextNonWhitespace(cursor, source);
if (source.startsWith("...", varargStart)) {
varargs = format(source, cursor, varargStart);
cursor = varargStart + 3;
}
}

List<JRightPadded<J.VariableDeclarations.NamedVariable>> vars = new ArrayList<>(nodes.size());
for (int i = 0; i < nodes.size(); i++) {
JCVariableDecl n = (JCVariableDecl) nodes.get(i);
Expand All @@ -1624,7 +1636,7 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
);
}

return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, varargs, beforeDimensions, vars);
return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, null, vars);
}

private List<JLeftPadded<Space>> arrayDimensions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1491,9 +1491,22 @@ private TypeTree arrayTypeTree(Tree tree, Map<Integer, JCAnnotation> annotationP
Space prefix = whitespace();
TypeTree elemType = convert(typeIdent);
List<J.Annotation> annotations = leadingAnnotations(annotationPosTable);
JLeftPadded<Space> dimension = padLeft(sourceBefore("["), sourceBefore("]"));

// Check if this is varargs (...) or regular array brackets ([])
Markers markers = Markers.EMPTY;
JLeftPadded<Space> dimension;
int nextNonWhitespace = indexOfNextNonWhitespace(cursor, source);
if (source.startsWith("...", nextNonWhitespace)) {
// Varargs syntax
markers = markers.addIfAbsent(new org.openrewrite.java.marker.Varargs(randomId()));
dimension = padLeft(sourceBefore("..."), EMPTY);
} else {
// Regular array brackets
dimension = padLeft(sourceBefore("["), sourceBefore("]"));
}

assert arrayTypeTree != null;
return new J.ArrayType(randomId(), prefix, Markers.EMPTY,
return new J.ArrayType(randomId(), prefix, markers,
count == 1 ? elemType : mapDimensions(elemType, arrayTypeTree.getType(), annotationPosTable),
annotations,
dimension,
Expand All @@ -1509,22 +1522,32 @@ private TypeTree mapDimensions(TypeTree baseType, Tree tree, Map<Integer, JCAnno

if (typeIdent instanceof JCArrayTypeTree) {
List<J.Annotation> annotations = leadingAnnotations(annotationPosTable);
int saveCursor = cursor;
whitespace();
if (source.startsWith("[", cursor)) {
cursor = saveCursor;
JLeftPadded<Space> dimension = padLeft(sourceBefore("["), sourceBefore("]"));
return new J.ArrayType(
randomId(),
EMPTY,
Markers.EMPTY,
mapDimensions(baseType, ((JCArrayTypeTree) typeIdent).elemtype, annotationPosTable),
annotations,
dimension,
typeMapping.type(tree)
);

// Check if this is varargs (...) or regular array brackets ([])
Markers markers = Markers.EMPTY;
JLeftPadded<Space> dimension;
int nextNonWhitespace = indexOfNextNonWhitespace(cursor, source);
if (source.startsWith("...", nextNonWhitespace)) {
// Varargs syntax
markers = markers.addIfAbsent(new org.openrewrite.java.marker.Varargs(randomId()));
dimension = padLeft(sourceBefore("..."), EMPTY);
} else if (source.startsWith("[", nextNonWhitespace)) {
// Regular array brackets
dimension = padLeft(sourceBefore("["), sourceBefore("]"));
} else {
// No dimension found
return baseType;
}
cursor = saveCursor;

return new J.ArrayType(
randomId(),
EMPTY,
markers,
mapDimensions(baseType, ((JCArrayTypeTree) typeIdent).elemtype, annotationPosTable),
annotations,
dimension,
typeMapping.type(tree)
);
}
return baseType;
}
Expand Down Expand Up @@ -1705,7 +1728,7 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
}
}
int idx = indexOfNextNonWhitespace(elementType.getEndPosition(endPosTable), source);
typeExpr = idx != -1 && (source.charAt(idx) == '[' || source.charAt(idx) == '@') ? convert(vartype) :
typeExpr = idx != -1 && (source.charAt(idx) == '[' || source.charAt(idx) == '@' || source.startsWith("...", idx)) ? convert(vartype) :
// we'll capture the array dimensions in a bit, just convert the element type
convert(elementType);
} else {
Expand All @@ -1721,15 +1744,6 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
typeExpr = new J.AnnotatedType(randomId(), prefix, Markers.EMPTY, ListUtils.mapFirst(typeExprAnnotations, a -> a.withPrefix(EMPTY)), typeExpr);
}

Space varargs = null;
if (typeExpr != null && typeExpr.getMarkers().findFirst(JavaVarKeyword.class).isEmpty()) {
int varargStart = indexOfNextNonWhitespace(cursor, source);
if (source.startsWith("...", varargStart)) {
varargs = format(source, cursor, varargStart);
cursor = varargStart + 3;
}
}

List<JRightPadded<J.VariableDeclarations.NamedVariable>> vars = new ArrayList<>(nodes.size());
for (int i = 0; i < nodes.size(); i++) {
JCVariableDecl n = (JCVariableDecl) nodes.get(i);
Expand All @@ -1755,7 +1769,7 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
);
}

return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, varargs, vars);
return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, null, vars);
}

private List<JLeftPadded<Space>> arrayDimensions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1520,9 +1520,22 @@ private TypeTree arrayTypeTree(Tree tree, Map<Integer, JCAnnotation> annotationP
Space prefix = whitespace();
TypeTree elemType = convert(typeIdent);
List<J.Annotation> annotations = leadingAnnotations(annotationPosTable);
JLeftPadded<Space> dimension = padLeft(sourceBefore("["), sourceBefore("]"));

// Check if this is varargs (...) or regular array brackets ([])
Markers markers = Markers.EMPTY;
JLeftPadded<Space> dimension;
int nextNonWhitespace = indexOfNextNonWhitespace(cursor, source);
if (source.startsWith("...", nextNonWhitespace)) {
// Varargs syntax
markers = markers.addIfAbsent(new org.openrewrite.java.marker.Varargs(randomId()));
dimension = padLeft(sourceBefore("..."), EMPTY);
} else {
// Regular array brackets
dimension = padLeft(sourceBefore("["), sourceBefore("]"));
}

assert arrayTypeTree != null;
return new J.ArrayType(randomId(), prefix, Markers.EMPTY,
return new J.ArrayType(randomId(), prefix, markers,
count == 1 ? elemType : mapDimensions(elemType, arrayTypeTree.getType(), annotationPosTable),
annotations,
dimension,
Expand All @@ -1538,22 +1551,32 @@ private TypeTree mapDimensions(TypeTree baseType, Tree tree, Map<Integer, JCAnno

if (typeIdent instanceof JCArrayTypeTree) {
List<J.Annotation> annotations = leadingAnnotations(annotationPosTable);
int saveCursor = cursor;
whitespace();
if (source.startsWith("[", cursor)) {
cursor = saveCursor;
JLeftPadded<Space> dimension = padLeft(sourceBefore("["), sourceBefore("]"));
return new J.ArrayType(
randomId(),
EMPTY,
Markers.EMPTY,
mapDimensions(baseType, ((JCArrayTypeTree) typeIdent).elemtype, annotationPosTable),
annotations,
dimension,
typeMapping.type(tree)
);

// Check if this is varargs (...) or regular array brackets ([])
Markers markers = Markers.EMPTY;
JLeftPadded<Space> dimension;
int nextNonWhitespace = indexOfNextNonWhitespace(cursor, source);
if (source.startsWith("...", nextNonWhitespace)) {
// Varargs syntax
markers = markers.addIfAbsent(new org.openrewrite.java.marker.Varargs(randomId()));
dimension = padLeft(sourceBefore("..."), EMPTY);
} else if (source.startsWith("[", nextNonWhitespace)) {
// Regular array brackets
dimension = padLeft(sourceBefore("["), sourceBefore("]"));
} else {
// No dimension found
return baseType;
}
cursor = saveCursor;

return new J.ArrayType(
randomId(),
EMPTY,
markers,
mapDimensions(baseType, ((JCArrayTypeTree) typeIdent).elemtype, annotationPosTable),
annotations,
dimension,
typeMapping.type(tree)
);
}
return baseType;
}
Expand Down Expand Up @@ -1734,7 +1757,7 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
}
}
int idx = indexOfNextNonWhitespace(elementType.getEndPosition(endPosTable), source);
typeExpr = idx != -1 && (source.charAt(idx) == '[' || source.charAt(idx) == '@') ? convert(vartype) :
typeExpr = idx != -1 && (source.charAt(idx) == '[' || source.charAt(idx) == '@' || source.startsWith("...", idx)) ? convert(vartype) :
// we'll capture the array dimensions in a bit, just convert the element type
convert(elementType);
} else {
Expand All @@ -1750,15 +1773,6 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
typeExpr = new J.AnnotatedType(randomId(), prefix, Markers.EMPTY, ListUtils.mapFirst(typeExprAnnotations, a -> a.withPrefix(EMPTY)), typeExpr);
}

Space varargs = null;
if (typeExpr != null && typeExpr.getMarkers().findFirst(JavaVarKeyword.class).isEmpty()) {
int varargStart = indexOfNextNonWhitespace(cursor, source);
if (source.startsWith("...", varargStart)) {
varargs = format(source, cursor, varargStart);
cursor = varargStart + 3;
}
}

List<JRightPadded<J.VariableDeclarations.NamedVariable>> vars = new ArrayList<>(nodes.size());
for (int i = 0; i < nodes.size(); i++) {
JCVariableDecl n = (JCVariableDecl) nodes.get(i);
Expand All @@ -1784,7 +1798,7 @@ private J.VariableDeclarations visitVariables(List<VariableTree> nodes, Space fm
);
}

return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, varargs, vars);
return new J.VariableDeclarations(randomId(), fmt, Markers.EMPTY, modifierResults.getLeadingAnnotations(), modifierResults.getModifiers(), typeExpr, null, vars);
}

private List<JLeftPadded<Space>> arrayDimensions() {
Expand Down
Loading