Skip to content

Commit

Permalink
Use method declaration parameters to check for continuation indentation
Browse files Browse the repository at this point in the history
Fixes: #3552
  • Loading branch information
knutwannheden committed Sep 15, 2023
1 parent 1a1d07c commit b876c43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ boolean eq(){
assertThat(tabsAndIndents.getContinuationIndent()).isEqualTo(8);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/3552")
void continuationIndentFromParameters() {
var cus = jp().parse(
"""
class Test {
void foo(String s1,
String s2,
String s3) {
}
}
"""
);

var detector = Autodetect.detector();
cus.forEach(detector::sample);
var styles = detector.build();
var tabsAndIndents = NamedStyles.merge(TabsAndIndentsStyle.class, singletonList(styles));

assertThat(tabsAndIndents.getContinuationIndent()).isEqualTo(5);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/3550")
void alignParametersWhenMultiple() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, In
stats.multilineAlignedToFirstArgument++;
} else {
stats.multilineNotAlignedToFirstArgument++;
countIndents(parameters.get(i).getPrefix().getWhitespace(), true, stats);
}
}
}
Expand Down

0 comments on commit b876c43

Please sign in to comment.