Skip to content

Commit e86d8b3

Browse files
dansanduleacbulldozer-bot[bot]
authored andcommitted
Fix: Limit dotted chains for expressions starting with complex expression (#71)
Limit dotted chains for expressions starting with a complex expression such as a parenthesized expression or a constructor.
1 parent 750740b commit e86d8b3

File tree

7 files changed

+38
-5
lines changed

7 files changed

+38
-5
lines changed

changelog/@unreleased/pr-71.v2.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: fix
2+
fix:
3+
description: Limit dotted chains for expressions starting with constructor.
4+
links:
5+
- https://github.com/palantir/palantir-java-format/pull/71

palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,8 +2600,13 @@ void visitDot(ExpressionTree node0) {
26002600
scan(getArrayBase(node), null);
26012601
token(".");
26022602
} else {
2603-
builder.open(
2604-
plusFour, BreakBehaviours.preferBreakingLastInnerLevel(true), LastLevelBreakability.BREAK_HERE);
2603+
builder.open(OpenOp.builder()
2604+
.debugName("visitDot")
2605+
.plusIndent(plusFour)
2606+
.breakBehaviour(BreakBehaviours.preferBreakingLastInnerLevel(true))
2607+
.breakabilityIfLastLevel(LastLevelBreakability.BREAK_HERE)
2608+
.columnLimitBeforeLastBreak(METHOD_CHAIN_COLUMN_LIMIT)
2609+
.build());
26052610
scan(getArrayBase(node), null);
26062611
builder.breakOp();
26072612
needDot = true;
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
public class B21031147 {
22
{
3-
return new StringBuilder(maxLength).append(seq, 0, truncationLength).append(truncationIndicator).toString();
3+
return new StringBuilder(maxLength)
4+
.append(seq, 0, truncationLength)
5+
.append(truncationIndicator)
6+
.toString();
47
}
58
}

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B22488373.output

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ class B22488373 {
22
{
33
if (enumBindingKeys.contains(bindingKey)
44
&& (bindingKey.key().type().getKind().equals(DECLARED)
5-
&& !((DeclaredType) bindingKey.key().type()).getTypeArguments().isEmpty())) {}
5+
&& !((DeclaredType) bindingKey.key().type())
6+
.getTypeArguments()
7+
.isEmpty())) {}
68
}
79
}

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/M.output

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,11 @@ class M {
868868

869869
void f(int... x) {
870870
M m = null;
871-
((m.identity().identity().identity().identity()).identity().identity().identity().identity())
871+
((m.identity().identity().identity().identity())
872+
.identity()
873+
.identity()
874+
.identity()
875+
.identity())
872876
.identity()
873877
.identity()
874878
.identity()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class PalantirLongMethodChain {
2+
private static void foo() {
3+
new ObjectMapper().registerModule(new Jdk8Module()).readValue(file, TestCases.class).getClient();
4+
}
5+
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class PalantirLongMethodChain {
2+
private static void foo() {
3+
new ObjectMapper()
4+
.registerModule(new Jdk8Module())
5+
.readValue(file, TestCases.class)
6+
.getClient();
7+
}
8+
}

0 commit comments

Comments
 (0)