René's URL Explorer Experiment


Title: Join adjacent string literals that share a line by abashev · Pull Request #176 · openjavaformat/open-java-format · GitHub

Open Graph Title: Join adjacent string literals that share a line by abashev · Pull Request #176 · openjavaformat/open-java-format

X Title: Join adjacent string literals that share a line by abashev · Pull Request #176 · openjavaformat/open-java-format

Description: Fixes #148. What When a concatenation of string literals ends up on one line, the + between them stays. The string wrapping pass only looks at lines past the column limit, so the output depends on where the author broke the string. // 21.X.X throw new SafeIllegalArgumentException( "Invalid recipient field - contains multiple " + "foreign key properties.", UnsafeArg.of("field", maybeField)); foo("one " + "two " + value + "three " + "four"); // this PR throw new SafeIllegalArgumentException( "Invalid recipient field - contains multiple foreign key properties.", UnsafeArg.of("field", maybeField)); foo("one two " + value + "three four"); What the pass does StringWrapper now joins each run of adjacent string literals that share a line into one literal, after the reflow and the text block passes, whether the author wrote them so or the layout brought them together. The code is then laid out again around the joined literal, so a call whose argument now fits goes onto one line. A line with a quote on both sides of a + sets the pass off, in needWrapping and in linesNeedWrapping (the --output-replacements path), and the pass returns at once when it finds nothing to do. Literals stay apart: on different lines, which is wrapping done on purpose, by the author or by the reflow; with a comment between them; at a text block (literals after one still join among themselves); on a line that ends in a line comment, which may speak of them as they are written: a NON-NLS marker counts the literals of its line (#23), and a table of literals has a comment for each row; where the left one ends in an octal escape of one or two digits and the right one starts with an octal digit: "\1" + "2" is two characters, "\12" one; where either holds a Unicode escape. A run that a reflowed chain or a text block overlaps is left to that pass. Differences from palantir#1781 The code is Zayan Khan's, from palantir#1781 (closed there unmerged), which addresses palantir#68; the commit keeps the author. Two rules are new here: A line comment at the end of the line. Upstream joins those literals. The JDK's java/util/LocaleISOData.java holds tables of rows such as "aa" + "aar" // Afar, 437 of them, which became "aaaar" // Afar. The rule also keeps our NON-NLS markers with their literals: without it the ojf-issue-23 cases fail. It changes no other JDK file. Unicode escapes. Upstream's octal check reads the raw text, so "\u005c1" + "2", a backslash written as a Unicode escape, became "\u005c12", one character instead of two. The AST check of the pass rejects that, and the whole file fails to format. The goldens and unit tests became case files, and the changelog entry is left out. Tests stringwrapper/adjacentLiteralsAreJoined.case: an argument the formatter brings onto one line, runs around other operands of the +, parentheses, a two-line chain the formatter pulls onto one line, escapes copied as written (\t, \", \\ before a digit, a three-digit octal escape, \1 before 8), literals after a text block, an annotation and a case label. stringwrapper/adjacentLiteralsThatStayApart.case: a comment between, a line comment at the end of the line (a table and a call), short octal escapes, Unicode escapes. testdata/NON-NLS-* and testdata/palantir-10-*, in all three line endings: the expected outputs join their literals, and nothing else in them changes. Upstream's unit tests of joiningWouldChangeEscapes and mayHaveJoinableLiterals were not kept, because the cases already fail when either breaks. I checked that by taking out each rule in turn: the line comment rule, the text block rule, the Unicode rule, the octal rule and the trigger each fail at least one case. Taking out the early return changes no output. A plain formatSource leaves all 889 after blocks as they are. Tests on JDK 21: FormatterCasesTest 887 → 889; 1410 tests in the module, 1471 in all modules. JDK 21 corpus Of the 15,747 files, 787 format differently, in 2,303 places, and each is a join: with the + between two literals taken out and blanks ignored, both versions read the same. 737 files join on lines that stay as they are, for example SSLLogger.fine("Discard invalid record: " + "too small record to hold a handshake fragment"). In 167 the code is then laid out again, mostly a call whose argument now fits on its line, as in java/lang/StackWalker.java: - throw new UnsupportedOperationException( - "This stack walker " + "does not have RETAIN_CLASS_REFERENCE access"); + throw new UnsupportedOperationException("This stack walker does not have RETAIN_CLASS_REFERENCE access"); 221 places join literals with escapes, such as "\"" + ",offset=" into "\",offset=". The pass compares the folded values of the code before and after, and no file failed. The files that change on a second run go down from 67 to 48, and none of them is new. In 19 files, a second run used to move pieces of a chain around, and those pieces are now joined in the first run. No slowdown is visible: 42–48 s with the change and 64 s without, though on a machine under load (load average 15–100), so this is not a clean benchmark. Partial formatting Joins reach as far as the reflow does today, which is the whole file: --lines and --character-ranges: the string pass runs over the whole file, so formatting a few lines can join literals elsewhere in it. --output-replacements (IntelliJ): the pass runs when a line in the ranges needs it, and then answers with one replacement for the whole file. A line in the ranges with joinable literals now counts as such a line. Eclipse plugin: it goes through getFormatReplacements, which has no string pass (#33), so it joins nothing, just as it wraps nothing today. Version This changes the output, so under the version scheme it moves the second number.

Open Graph Description: Fixes #148. What When a concatenation of string literals ends up on one line, the + between them stays. The string wrapping pass only looks at lines past the column limit, so the output depends on ...

X Description: Fixes #148. What When a concatenation of string literals ends up on one line, the + between them stays. The string wrapping pass only looks at lines past the column limit, so the output depends on ...

Opengraph URL: https://github.com/openjavaformat/open-java-format/pull/176

X: @github

direct link

Domain: redirect.github.com

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:8fefb69e-36d6-37e1-e063-86df94904aa0
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE160:3EA038:678ED8:891F5E:6AFBCA17
html-safe-nonce77159a66f9d555109f058450fcd3f7d8e35bb1510e99e145f4eb85d00b654033
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTYwOjNFQTAzODo2NzhFRDg6ODkxRjVFOjZBRkJDQTE3IiwidmlzaXRvcl9pZCI6IjQ5MjQzNTQ1ODg0ODk1MzM5NzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac4d4e9c808d005b5771c0e4e3cf9cb61fa0de29b1d16d4818f48dee67db152d01
hovercard-subject-tagpull_request:5083260146
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/openjavaformat/open-java-format/pull/176/files
twitter:imagehttps://avatars.githubusercontent.com/u/214171?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/214171?s=400&v=4
og:image:altFixes #148. What When a concatenation of string literals ends up on one line, the + between them stays. The string wrapping pass only looks at lines past the column limit, so the output depends on ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noned440bda0d812801778b27bfe9f7c1ce9ff22420c73f6f95150c4fcbca311c50b
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git
octolytics-dimension-user_id325177626
octolytics-dimension-user_loginopenjavaformat
octolytics-dimension-repository_id1288055459
octolytics-dimension-repository_nwoopenjavaformat/open-java-format
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forktrue
octolytics-dimension-repository_parent_id214273098
octolytics-dimension-repository_parent_nwopalantir/palantir-java-format
octolytics-dimension-repository_network_root_id214273098
octolytics-dimension-repository_network_root_nwopalantir/palantir-java-format
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release2c43021aed8695990c86c0eaaedc600bfeffec36
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files#start-of-content
https://redirect.github.com/
Sign inhttps://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenjavaformat%2Fopen-java-format%2Fpull%2F176%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://redirect.github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenjavaformat%2Fopen-java-format%2Fpull%2F176%2Ffiles
Sign uphttps://redirect.github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=openjavaformat%2Fopen-java-format
Reloadhttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files
Reloadhttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files
Reloadhttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files
openjavaformathttps://redirect.github.com/openjavaformat
open-java-formathttps://redirect.github.com/openjavaformat/open-java-format
Codehttps://redirect.github.com/openjavaformat/open-java-format
Issues30 (30)https://redirect.github.com/openjavaformat/open-java-format/issues
Pull requests5 (5)https://redirect.github.com/openjavaformat/open-java-format/pulls
Discussionshttps://redirect.github.com/openjavaformat/open-java-format/discussions
Actionshttps://redirect.github.com/openjavaformat/open-java-format/actions
Security and qualityhttps://redirect.github.com/openjavaformat/open-java-format/security
Insightshttps://redirect.github.com/openjavaformat/open-java-format/pulse
Sign up for GitHub https://redirect.github.com/signup?return_to=%2Fopenjavaformat%2Fopen-java-format%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://redirect.github.com/login?return_to=%2Fopenjavaformat%2Fopen-java-format%2Fissues%2Fnew%2Fchoose
abashevhttps://redirect.github.com/abashev
21.X.Xhttps://redirect.github.com/openjavaformat/open-java-format/tree/21.X.X
fix/join-string-literalshttps://redirect.github.com/openjavaformat/open-java-format/tree/fix/join-string-literals
Conversation 0 https://redirect.github.com/openjavaformat/open-java-format/pull/176
Commits 1 https://redirect.github.com/openjavaformat/open-java-format/pull/176/commits
Checks 17 https://redirect.github.com/openjavaformat/open-java-format/pull/176/checks
Files changed https://redirect.github.com/openjavaformat/open-java-format/pull/176/files
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files
Join adjacent string literals that share a line https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#top
Show all changes 1 commit https://redirect.github.com/openjavaformat/open-java-format/pull/176/files
da784aa Join adjacent string literals that share a line ZayanKhan-12 Oct 30, 2026 https://redirect.github.com/openjavaformat/open-java-format/pull/176/commits/da784aa8b7da1be8ddbfcc61ec21d7b1d1be23c9
Clear filters https://redirect.github.com/openjavaformat/open-java-format/pull/176/files
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files
StringWrapper.java https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
adjacentLiteralsAreJoined.case https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-f609d74f35a805884bb9df177d64bf282785c2930cc973e7ae055f6fa879db0e
adjacentLiteralsThatStayApart.case https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-3e93ffe270b4ced0214eff9caa7196e5138a32a6ac815b054c3a42c1be4632c4
NON-NLS-cr.case https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-42b425b117a4a052bc7524061b9e2c76eb7d01f6637e1b62f59209862799ac84
NON-NLS-crlf.case https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-5553c2a05e976ce952e33fa29c417c5687b4b69167d90d4cfe501ce5cb392588
NON-NLS-lf.case https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-f9db61c91c29a7dcc9b5d570e9ab645fa9dca4bdc5ef75b0452558d258f113ff
palantir-10-cr.case https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-9675ce357b24085e6347754d4b5c469f505e364c24c381c5c15bad5d15ca0aab
palantir-10-crlf.case https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-56b345ab1b3fb6c25963d3069796c57a43a597845925e4accbbfecbafecaf7d3
palantir-10-lf.case https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-b2ea3d9018cafc043c9295a64f0677b183bc3b13d99f80af9895581a30ee2ef1
open-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.javahttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
View file https://redirect.github.com/openjavaformat/open-java-format/blob/da784aa8b7da1be8ddbfcc61ec21d7b1d1be23c9/open-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/openjavaformat/open-java-format/pull/176/{{ revealButtonHref }}
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-e1a3ba2697d8a173c2a21309f93db0dd44e1d34a557cb37877fdafae42b26cd6
open-java-format/src/test/resources/test-cases/stringwrapper/adjacentLiteralsAreJoined.casehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-f609d74f35a805884bb9df177d64bf282785c2930cc973e7ae055f6fa879db0e
View file https://redirect.github.com/openjavaformat/open-java-format/blob/da784aa8b7da1be8ddbfcc61ec21d7b1d1be23c9/open-java-format/src/test/resources/test-cases/stringwrapper/adjacentLiteralsAreJoined.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/openjavaformat/open-java-format/pull/176/{{ revealButtonHref }}
...ava-format/src/test/resources/test-cases/stringwrapper/adjacentLiteralsThatStayApart.casehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-3e93ffe270b4ced0214eff9caa7196e5138a32a6ac815b054c3a42c1be4632c4
View file https://redirect.github.com/openjavaformat/open-java-format/blob/da784aa8b7da1be8ddbfcc61ec21d7b1d1be23c9/open-java-format/src/test/resources/test-cases/stringwrapper/adjacentLiteralsThatStayApart.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/openjavaformat/open-java-format/pull/176/{{ revealButtonHref }}
open-java-format/src/test/resources/test-cases/testdata/NON-NLS-cr.casehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-42b425b117a4a052bc7524061b9e2c76eb7d01f6637e1b62f59209862799ac84
View file https://redirect.github.com/openjavaformat/open-java-format/blob/da784aa8b7da1be8ddbfcc61ec21d7b1d1be23c9/open-java-format/src/test/resources/test-cases/testdata/NON-NLS-cr.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/openjavaformat/open-java-format/pull/176/{{ revealButtonHref }}
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-42b425b117a4a052bc7524061b9e2c76eb7d01f6637e1b62f59209862799ac84
open-java-format/src/test/resources/test-cases/testdata/NON-NLS-crlf.casehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-5553c2a05e976ce952e33fa29c417c5687b4b69167d90d4cfe501ce5cb392588
View file https://redirect.github.com/openjavaformat/open-java-format/blob/da784aa8b7da1be8ddbfcc61ec21d7b1d1be23c9/open-java-format/src/test/resources/test-cases/testdata/NON-NLS-crlf.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/openjavaformat/open-java-format/pull/176/{{ revealButtonHref }}
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-5553c2a05e976ce952e33fa29c417c5687b4b69167d90d4cfe501ce5cb392588
open-java-format/src/test/resources/test-cases/testdata/NON-NLS-lf.casehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-f9db61c91c29a7dcc9b5d570e9ab645fa9dca4bdc5ef75b0452558d258f113ff
View file https://redirect.github.com/openjavaformat/open-java-format/blob/da784aa8b7da1be8ddbfcc61ec21d7b1d1be23c9/open-java-format/src/test/resources/test-cases/testdata/NON-NLS-lf.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://redirect.github.com/openjavaformat/open-java-format/pull/176/{{ revealButtonHref }}
https://redirect.github.com/openjavaformat/open-java-format/pull/176/files#diff-f9db61c91c29a7dcc9b5d570e9ab645fa9dca4bdc5ef75b0452558d258f113ff
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files
Please reload this pagehttps://redirect.github.com/openjavaformat/open-java-format/pull/176/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.