diff --git a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java index e9d67d54a6d..425fc0af604 100644 --- a/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java +++ b/rewrite-java-17/src/main/java/org/openrewrite/java/isolated/ReloadableJava17ParserVisitor.java @@ -1298,7 +1298,11 @@ public J visitAnnotatedType(AnnotatedTypeTree node, Space fmt) { if (node.getUnderlyingType() instanceof JCFieldAccess) { return new J.AnnotatedType(randomId(), fmt, Markers.EMPTY, leadingAnnotations, annotatedTypeTree(node.getUnderlyingType(), annotationPosTable)); } else if (node.getUnderlyingType() instanceof JCArrayTypeTree) { - return new J.AnnotatedType(randomId(), fmt, Markers.EMPTY, leadingAnnotations, arrayTypeTree(node, annotationPosTable)); + J.AnnotatedType annotatedType = new J.AnnotatedType(randomId(), fmt, Markers.EMPTY, leadingAnnotations, arrayTypeTree(node, annotationPosTable)); +// if (((JCArrayTypeTree) node.getUnderlyingType()).getType() instanceof JCAnnotatedType) { +// visitAnnotatedType((AnnotatedTypeTree) ((JCArrayTypeTree) node.getUnderlyingType()).getType(), fmt); +// } + return annotatedType; } } return new J.AnnotatedType(randomId(), fmt, Markers.EMPTY, leadingAnnotations, convert(node.getUnderlyingType())); @@ -1387,7 +1391,7 @@ private TypeTree mapDimensions(TypeTree baseType, Tree tree, Map annotations = leadingAnnotations(annotationPosTable); int saveCursor = cursor; - whitespace(); + Space space = whitespace(); if (source.startsWith("[", cursor)) { cursor = saveCursor; JLeftPadded dimension = padLeft(sourceBefore("["), sourceBefore("]")); @@ -1400,6 +1404,18 @@ private TypeTree mapDimensions(TypeTree baseType, Tree tree, Map p) { getCursor() .dropParentUntil( c -> c instanceof Switch || - c instanceof SwitchExpression || - c == Cursor.ROOT_VALUE + c instanceof SwitchExpression || + c == Cursor.ROOT_VALUE ) .getValue(); if (aSwitch instanceof SwitchExpression) { @@ -848,6 +848,15 @@ public J visitVariableDeclarations(VariableDeclarations multiVariable, PrintOutp p.append(']'); } if (multiVariable.getVarargs() != null) { + if (!(multiVariable.getTypeExpression() instanceof ArrayType)) { + if (p.out.charAt(p.out.length() - 1) == ']') { + int posToCheck = p.out.length() - 2; + while (p.out.charAt(posToCheck) != '[') { + posToCheck--; + } + p.out.delete(posToCheck, p.out.length()); + } + } visitSpace(multiVariable.getVarargs(), Space.Location.VARARGS, p); p.append("..."); }