Commit 307e091
Keep the space between a unary minus and a negative literal
javac folds a minus in front of a decimal literal into the literal
itself, so "- -1" parses as one unary minus applied to the literal
"-1". The check that keeps a space between two prefix operators only
looked for a nested unary expression, so the output was "--1": the
decrement operator on a literal, which does not compile. "- -x" was
fine, the literal case was not.
This ports google/google-java-format#576 by Liam Miller-Cushon: a
literal whose source starts with "-" counts as a unary minus in that
check. The golden B183431894 comes from upstream, with the expected
output in this project's style.
The 15,747 files of the JDK 21 sources format exactly as before.1 parent 746fb60 commit 307e091
3 files changed
Lines changed: 30 additions & 7 deletions
File tree
- open-java-format/src
- main/java/com/palantir/javaformat/java
- test/resources/com/palantir/javaformat/java/testdata
Lines changed: 22 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1663 | 1663 | | |
1664 | 1664 | | |
1665 | 1665 | | |
1666 | | - | |
1667 | | - | |
1668 | | - | |
1669 | | - | |
1670 | | - | |
| 1666 | + | |
1671 | 1667 | | |
1672 | 1668 | | |
1673 | 1669 | | |
1674 | 1670 | | |
1675 | 1671 | | |
1676 | 1672 | | |
1677 | 1673 | | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
1678 | 1682 | | |
1679 | 1683 | | |
1680 | 1684 | | |
| |||
1759 | 1763 | | |
1760 | 1764 | | |
1761 | 1765 | | |
1762 | | - | |
| 1766 | + | |
| 1767 | + | |
1763 | 1768 | | |
1764 | 1769 | | |
1765 | | - | |
1766 | 1770 | | |
1767 | 1771 | | |
1768 | 1772 | | |
| |||
1772 | 1776 | | |
1773 | 1777 | | |
1774 | 1778 | | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
1775 | 1790 | | |
1776 | 1791 | | |
1777 | 1792 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments