diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/format/TabsAndIndentsTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/format/TabsAndIndentsTest.java index 90dd75b751e..024ef3dc51f 100644 --- a/rewrite-java-test/src/test/java/org/openrewrite/java/format/TabsAndIndentsTest.java +++ b/rewrite-java-test/src/test/java/org/openrewrite/java/format/TabsAndIndentsTest.java @@ -103,9 +103,10 @@ void alignMethodDeclarationParamsWhenMultiple() { java( """ class Test { + @SuppressWarnings private void firstArgNoPrefix(String first, - int times, - String third + int times, + String third ) { } private void firstArgOnNewLine( @@ -118,6 +119,7 @@ private void firstArgOnNewLine( """, """ class Test { + @SuppressWarnings private void firstArgNoPrefix(String first, int times, String third diff --git a/rewrite-java/src/main/java/org/openrewrite/java/format/TabsAndIndentsVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/format/TabsAndIndentsVisitor.java index a4effda558d..f61b11520ab 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/format/TabsAndIndentsVisitor.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/format/TabsAndIndentsVisitor.java @@ -227,7 +227,9 @@ public JRightPadded visitRightPadded(@Nullable JRightPadded right, JRi alignTo = firstArg.getPrefix().getLastWhitespace().length() - 1; } else { String source = method.print(getCursor()); - alignTo = source.indexOf(firstArg.print(getCursor())) - 1; + int firstArgIndex = source.indexOf(firstArg.print(getCursor())); + int lineBreakIndex = source.lastIndexOf('\n', firstArgIndex); + alignTo = (firstArgIndex - (lineBreakIndex == -1 ? 0 : lineBreakIndex)) - 1; } getCursor().getParentOrThrow().putMessage("lastIndent", alignTo - style.getContinuationIndent()); elem = visitAndCast(elem, p);