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 8269b77ce67..902c143ac04 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 @@ -173,6 +173,27 @@ private void firstArgOnNewLine( ); } + @Test + void alignMethodDeclarationParamsWhenContinuationIndentUsingTabs() { + rewriteRun( + tabsAndIndents(style -> style.withUseTabCharacter(true)), + java( + """ + import java.util.*; + + class Foo { + Foo( + String var1, + String var2, + String var3 + ) { + } + } + """ + ) + ); + } + // https://rules.sonarsource.com/java/tag/confusing/RSPEC-3973 @DocumentExample @SuppressWarnings("SuspiciousIndentAfterControlStatement") 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 fb4ca5940a2..268a9d3258e 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 @@ -235,7 +235,7 @@ public JRightPadded visitRightPadded(@Nullable JRightPadded right, JRi if (method != null) { int alignTo; if (firstArg.getPrefix().getLastWhitespace().contains("\n")) { - alignTo = firstArg.getPrefix().getLastWhitespace().length() - 1; + alignTo = getLengthOfWhitespace(firstArg.getPrefix().getLastWhitespace()); } else { String source = method.print(getCursor()); int firstArgIndex = source.indexOf(firstArg.print(getCursor()));