Title: Keep the rows of a table that follows an operator such as -> or += by abashev · Pull Request #170 · openjavaformat/open-java-format · GitHub
Open Graph Title: Keep the rows of a table that follows an operator such as -> or += by abashev · Pull Request #170 · openjavaformat/open-java-format
X Title: Keep the rows of a table that follows an operator such as -> or += by abashev · Pull Request #170 · openjavaformat/open-java-format
Description: A table of arguments or array elements that the author lays out by hand keeps its rows, but it did not when an operator of more than one character came before it on its line. This stayed a table: return Map.of("one", 1, "two", 2); while this came out as return () -> Map.of("one", 1, "two", 2);, or with one argument per line where that does not fit: return () -> Map.of("one", 1, "two", 2); The same went for an array initializer after mode == 0 ?, where one after mode < 1 ? kept its rows. Why The lexer splits an operator such as ==, -> or += into toks of one character, since >> cannot be told from two > without the parser. For each of those toks it moved the column on by the whole operator, so every tok after == on its line sat two columns too far right, and after >>>= twelve. argumentsAreTabular is the only reader of these columns: it compares the column each row starts at with the first row's, and a first row shifted that way never matched the rows under it. The column now moves on by the tok's own text, a one-word change in JavaInput.buildToks. continueTrailingComment from #169 gave this bug as its reason to read the column of a trailing comment in the text. It still reads it there, together with whether code comes before the comment, and its comment now says only that. Effect Of the 15,747 files of the JDK 21 sources, 4 format differently, each with a call laid out by hand in pairs after += or ->, which now keeps its pairs as it would after =. In sun/awt/geom/Curve.java: - crossings += pointCrossingsForLine(px, py, curx, cury, movx, movy); + crossings += pointCrossingsForLine( + px, py, + curx, cury, + movx, movy); The other three are javax/swing/plaf/basic/BasicTableHeaderUI.java (after +=), com/sun/tools/jdeps/Analyzer.java and jdk/internal/classfile/impl/ClassPrinterImpl.java (after ->). The files that change on a second run are the same 67 as before. The output of these tables changes, so the CLI and the plugins format such files differently. Not in this change The formatter still only keeps a table it finds in the input; it does not make one. A long Map.of(...) written on one line comes out with one argument per line before and after this change, which is what #31 is about (palantir#1731 for palantir#1602). Two other reasons a hand-made table is not kept stay as well, and both reproduce here: pairs whose values are different kinds of expression (palantir#204), and a block of a single row (google/google-java-format#572). Tests The case tablesAfterMultiCharacterOperators, pairs after -> and an array after ==, fails without the fix. FormatterCasesTest 886 → 887. ./gradlew test passes on JDK 21, and the formatter module's 1408 tests on JDK 25 and 27 as well.
Open Graph Description: A table of arguments or array elements that the author lays out by hand keeps its rows, but it did not when an operator of more than one character came before it on its line. This stayed a table: r...
X Description: A table of arguments or array elements that the author lays out by hand keeps its rows, but it did not when an operator of more than one character came before it on its line. This stayed a table: r...
Opengraph URL: https://github.com/openjavaformat/open-java-format/pull/170
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:583cfedb-d5f1-cfaf-0b9c-3636a2327ab1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A3E4:205907:660F64:8B508C:6AFBC697 |
| html-safe-nonce | fe5dd29012781045ddad54a3e34eedeecebfeb9c09a117e6724fdb69de522f20 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0U0OjIwNTkwNzo2NjBGNjQ6OEI1MDhDOjZBRkJDNjk3IiwidmlzaXRvcl9pZCI6IjQyMjk1MDg4OTA5NDI0OTAyNjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 499ac96de4bada3df77598e4f3cd5823993738286d7dae0bc4490045f9091b85 |
| hovercard-subject-tag | pull_request:5082266982 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/openjavaformat/open-java-format/pull/170/files |
| twitter:image | https://avatars.githubusercontent.com/u/214171?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/214171?s=400&v=4 |
| og:image:alt | A table of arguments or array elements that the author lays out by hand keeps its rows, but it did not when an operator of more than one character came before it on its line. This stayed a table: r... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | d440bda0d812801778b27bfe9f7c1ce9ff22420c73f6f95150c4fcbca311c50b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git |
| octolytics-dimension-user_id | 325177626 |
| octolytics-dimension-user_login | openjavaformat |
| octolytics-dimension-repository_id | 1288055459 |
| octolytics-dimension-repository_nwo | openjavaformat/open-java-format |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 214273098 |
| octolytics-dimension-repository_parent_nwo | palantir/palantir-java-format |
| octolytics-dimension-repository_network_root_id | 214273098 |
| octolytics-dimension-repository_network_root_nwo | palantir/palantir-java-format |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2c43021aed8695990c86c0eaaedc600bfeffec36 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width