Skip to content

Commit

Permalink
Print idempotence for prefix of varargs parameters in Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Jan 15, 2024
1 parent 78f82c8 commit 8955881
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ public J visitArrayType(ArrayTypeTree node, Space fmt) {
dimension = JLeftPadded.build(Space.build(sourceBeforeAsString("]"), emptyList())).withBefore(before);
} else {
cursor = saveCursor;
return elemType;
return elemType.withPrefix(fmt);
}

return new J.ArrayType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ public J visitArrayType(ArrayTypeTree node, Space fmt) {
dimension = JLeftPadded.build(Space.build(sourceBeforeAsString("]"), emptyList())).withBefore(before);
} else {
cursor = saveCursor;
return elemType;
return elemType.withPrefix(fmt);
}

return new J.ArrayType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ public J visitArrayType(ArrayTypeTree node, Space fmt) {
dimension = JLeftPadded.build(Space.build(sourceBeforeAsString("]"), emptyList())).withBefore(before);
} else {
cursor = saveCursor;
return elemType;
return elemType.withPrefix(fmt);
}

return new J.ArrayType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ public J visitArrayType(ArrayTypeTree node, Space fmt) {
dimension = JLeftPadded.build(Space.build(sourceBeforeAsString("]"), emptyList())).withBefore(before);
} else {
cursor = saveCursor;
return elemType;
return elemType.withPrefix(fmt);
}

return new J.ArrayType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,33 @@ public static void varargsMethod(String... args) {
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/3575")
void varargsWithPrefix() {
rewriteRun(
// for some reason the compiler AST's type attribution is incomplete here
spec -> spec.typeValidationOptions(TypeValidation.none()),
java(
"""
class A {
/**
* A dummy main method. This method is not actually called, but we'll use its Javadoc comment to test that
* OpenRewrite can handle references like the following: {@link A#varargsMethod( Object, String...)} }.
*
* @param args The arguments to the method.
*/
public static void main(String[] args) {
System.out.println("Hello, world! This is my original class' main method.");
}
public static void varargsMethod(Object o, String... args) {
System.out.println("Hello, world! This is my original class' varargs method.");
}
}
"""
)
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/3575")
void arrayMethod() {
Expand Down

0 comments on commit 8955881

Please sign in to comment.