Skip to content
Closed
Changes from all 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 @@ -765,4 +765,67 @@ private static Consumer<SourceSpec<J.CompilationUnit>> autoFormatIsIdempotent()
return spec -> spec.afterRecipe(cu ->
Assertions.assertThat(new AutoFormatVisitor<>().visit(cu, 0)).isEqualTo(cu));
}

@Test
void forLoopWithCorrectSpacing() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not reproduceable yet.

rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().styles(noWhitespaceBeforeStyle())),
java(
"""
class Test {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.println(args[i]);
}
}
public static void main2(String[] args) {
for (final String arg : args) {
System.out.println(arg);
}
}
public int indexOfFirstValue(final Object[] multipleValues) {
for (int i = 0; i < multipleValues.length; i++) {
if (multipleValues[i] != null) {
return i;
}
}
for (int i = 0; i < multipleValues.length; i++) { // space
if (multipleValues[i] != null) {
return i;
}
}
return -1;
}
}
""",
"""
class Test {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.println(args[i]);
}
}
public static void main2(String[] args) {
for (final String arg : args) {
System.out.println(arg);
}
}
public int indexOfFirstValue(final Object[] multipleValues) {
for (int i = 0; i < multipleValues.length; i++) {
if (multipleValues[i] != null) {
return i;
}
}
for (int i = 0; i < multipleValues.length; i++) { // space
if (multipleValues[i] != null) {
return i;
}
}
return -1;
}
}
"""
)
);
}
}