Commit 30b63ba
committed
Stop comments that share a line from doubling each other's indent
Comment.computeBreaks moved the column past a comment by adding the
length of the comment's last line to the column the comment started at.
For a comment that spans lines, JavaCommentsHelper.rewrite has already
indented that last line to the start column, so the column was counted
twice, and each further comment on the line was re-indented from the
doubled column. Commented-out code with javadoc in it, where every
"*//** javadoc *//*" puts several multi-line comments on one line, grew
from 817 bytes to 4.3 MB with 16 of them and ran out of a 2 GB heap
with 26 (#36, from google/google-java-format#413).
After a comment that spans lines the column is now the length of its
last line; after a one-line comment it is still the start column plus
the comment. The 26 comments now format into 12.5 kB in 0.33 s, each
indented to the column where it starts.
A golden of the reported file and a test with 16 such comments fail
without the change. The 15,747 files of the JDK 21 sources format
exactly as before.1 parent 53ac7d8 commit 30b63ba
4 files changed
Lines changed: 52 additions & 2 deletions
File tree
- open-java-format/src
- main/java/com/palantir/javaformat/doc
- test
- java/com/palantir/javaformat/java
- resources/com/palantir/javaformat/java/testdata
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
491 | 491 | | |
492 | 492 | | |
493 | 493 | | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
494 | 511 | | |
Lines changed: 14 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 | + | |
Lines changed: 14 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 | + | |
0 commit comments