File tree Expand file tree Collapse file tree
rewrite-java-test/src/test/java/org/openrewrite/java/format
rewrite-java/src/main/java/org/openrewrite/java/format Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -175,6 +175,42 @@ private void firstArgOnNewLine(
175175 );
176176 }
177177
178+ @ Test
179+ void alignMethodDeclarationParamsWhenIndentationNeeded () {
180+ rewriteRun (
181+ java (
182+ """
183+ class Test {
184+ @SuppressWarnings
185+ private void firstArgNoPrefix(
186+ String first,
187+ int times,
188+ String third) {}
189+ private void secondArgOnNewLine(
190+ String first,
191+ int times,
192+ String third
193+ ) {}
194+ }
195+ """ ,
196+ """
197+ class Test {
198+ @SuppressWarnings
199+ private void firstArgNoPrefix(
200+ String first,
201+ int times,
202+ String third) {}
203+ private void secondArgOnNewLine(
204+ String first,
205+ int times,
206+ String third
207+ ) {}
208+ }
209+ """
210+ )
211+ );
212+ }
213+
178214 @ Issue ("https://github.com/openrewrite/rewrite/issues/1913" )
179215 @ Test
180216 void alignMethodDeclarationParamsWhenContinuationIndent () {
Original file line number Diff line number Diff line change @@ -397,7 +397,13 @@ private int computeFirstParameterColumn(J.MethodDeclaration method) {
397397 }
398398
399399 if (firstArg .getPrefix ().getLastWhitespace ().contains ("\n " )) {
400- return getLengthOfWhitespace (firstArg .getPrefix ().getLastWhitespace ());
400+ int declPrefixLength = getLengthOfWhitespace (method .getPrefix ().getLastWhitespace ());
401+ int argPrefixLength = getLengthOfWhitespace (firstArg .getPrefix ().getLastWhitespace ());
402+ //noinspection ConstantConditions to be backwards compatible with older style versions
403+ if (declPrefixLength >= argPrefixLength ) {
404+ return declPrefixLength + style .getContinuationIndent ();
405+ }
406+ return argPrefixLength ;
401407 } else {
402408 return computeColumnPosition (method , firstArg , getCursor ());
403409 }
You can’t perform that action at this time.
0 commit comments