Commit b58f5c6
committed
Measure the whole type of a cast before inlining a chain onto it
In sun.rmi.transport.tcp.TCPTransport the cast (PrivilegedAction<String>)
came out cut between "<" and "String", with the lambda it applies to on a
third line, while the call around it stayed on one line (#60):
static final Log tcpLog = Log.getLog(
"sun.rmi.transport.tcp", "tcp", LogStream.parseLevel(AccessController.doPrivileged((PrivilegedAction<
String>)
() -> System.getProperty("sun.rmi.transport.tcp.logLevel"))));
The arguments of getLog are inlined when a prefix of the last one fits,
and CountWidthUntilBreakVisitor measures that prefix up to the first
break inside the last level. visitTypeCast declares its level
ACCEPT_INLINE_CHAIN, which means that first break is the one before the
operand. The first break was the one visitParameterizedType emits after
"<", so the prefix ended at "(PrivilegedAction<", fit, and the type had
to take the break because "String>)" did not fit behind it. A wildcard
bound, an intersection type and an annotated type offer breaks of their
own in the same place and split the same way.
The cast's level now has PartialInlineability.IF_FIRST_LEVEL_FITS, what
visitDotWithPrefix uses for the same purpose: the visitor counts the
whole first inner level, which is the rest of the type up to the break
before the operand, when it fits. A chain is inlined onto a cast only if
the type fits behind it. Here it does not, the chain is not inlined, and
the arguments break one per line, as they do when the type is not
parameterized. The type stays breakable for a cast that does not fit on
a line at all, so the golden C keeps its output.
The golden holds the statement above, the same cast one call shallower,
which fit and does not change, and a method reference, two type
arguments, a wildcard bound, a qualified name, an intersection type and
an annotated type in the cast. Of the 15,747 files of the JDK 21
sources, that one statement in TCPTransport is the only one that
formats differently, and its new output is stable.1 parent 8a39a6a commit b58f5c6
3 files changed
Lines changed: 92 additions & 4 deletions
File tree
- open-java-format/src
- main/java/com/palantir/javaformat/java
- test/resources/com/palantir/javaformat/java/testdata
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
685 | 693 | | |
686 | 694 | | |
687 | 695 | | |
| |||
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
0 commit comments