René's URL Explorer Experiment


Title: Indent a comment after an opening delimiter like the code after it by abashev · Pull Request #175 · openjavaformat/open-java-format · GitHub

Open Graph Title: Indent a comment after an opening delimiter like the code after it by abashev · Pull Request #175 · openjavaformat/open-java-format

X Title: Indent a comment after an opening delimiter like the code after it by abashev · Pull Request #175 · openjavaformat/open-java-format

Description: Fixes #171. What happens A comment on its own line right after an opening delimiter came out at the indent of the statement, and so did the code after it. The delimiters are for (, the ( of a try with several resources and of a multi-catch clause, the < of explicit type arguments (new T(), T::g), assert with a detail message, and the ; that ends the constants of an enum. For the enum, the comment and the ; even landed in the enum's own column. Input: class T { void f(int n) { for ( // comment int i = 0; i < n; i++) {} } } enum E { A, // comment ; } Before: class T { void f(int n) { for ( // comment int i = 0; i < n; i++) {} } } enum E { A, // comment ; } After: class T { void f(int n) { for ( // comment int i = 0; i < n; i++) {} } } enum E { A, // comment ; } Why OpsBuilder.build places the comments before a token ahead of the OpenOps right before it, so that a comment before a statement or an expression stays out of their levels. Each of these delimiters opens the level that indents what follows it right before that level's first token. The comment therefore left the level, and the forced break after the comment took the next line out with it. google/google-java-format#1501 fixes the same defect in google-java-format's new layout builder (groundwork in google/google-java-format#1500, baseline cases in google/google-java-format#1502). Its code does not apply to our engine, but the idea does. The fix OpsBuilder.fenceComments() adds a marker that build stops at when it looks back over OpenOps, and drops before the ops become a Doc. The six places call it right after they open their level, as upstream does: visitAssert, the ; after enum constants, visitForLoop, visitTry, visitCatchClause and addTypeArguments. The comment now breaks the level it sits in. The parts of a for header and the : of an assert get a line each, as they do whenever that level breaks. An assert without a detail message and a try with one resource open a level without indent, so their comments stay where they were. A block comment that shares its line with the code after it stays with it, on the line of the delimiter when that fits: for (/* c */ int i = 0; i < n; i++) {}. Tests There are six new cases, test-cases/commentAfterOpeningDelimiter-{assert,enumSemicolon,forHeader,tryResources,multiCatch,typeArguments}.case. Each input mixes upstream's shape, the shape 21.X.X produces today, and odd breaks and spacing. All six failed on the unchanged code with the comment at the statement's indent, and they pass with the fix, including the second run. On JDK 21: FormatterCasesTest: 887 → 893. The module: 1408 → 1414 tests, 14 skipped. ./gradlew test --rerun is green for all modules (Gradle plugin 51 tests, IntelliJ plugin 10). JDK corpus None of the 15,747 files of the JDK 21 sources formats differently. None of them has a comment on its own line after one of these delimiters.

Open Graph Description: Fixes #171. What happens A comment on its own line right after an opening delimiter came out at the indent of the statement, and so did the code after it. The delimiters are for (, the ( of a try w...

X Description: Fixes #171. What happens A comment on its own line right after an opening delimiter came out at the indent of the statement, and so did the code after it. The delimiters are for (, the ( of a try w...

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

X: @github

direct link

Domain: 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:5533d5e3-fa45-152b-13d0-46f7f2e34342
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id86A8:1F855F:67D9F2:8E649E:6AFBC69D
html-safe-noncefcf0f3c84dae3a86d6f9196ec6f70257eab36eafdedee4269dc83ff47ced90b9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkE4OjFGODU1Rjo2N0Q5RjI6OEU2NDlFOjZBRkJDNjlEIiwidmlzaXRvcl9pZCI6IjU2MTA2MzgxNTI3Njc4ODI5MDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac2d2243e997bea488f1c12f575ec15b62755e0763f57e22ccd96a6c2e56e5b48b
hovercard-subject-tagpull_request:5082989942
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/175/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 #171. What happens A comment on its own line right after an opening delimiter came out at the indent of the statement, and so did the code after it. The delimiters are for (, the ( of a try w...
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://github.com/openjavaformat/open-java-format/pull/175/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenjavaformat%2Fopen-java-format%2Fpull%2F175%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://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenjavaformat%2Fopen-java-format%2Fpull%2F175%2Ffiles
Sign uphttps://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://github.com/openjavaformat/open-java-format/pull/175/files
Reloadhttps://github.com/openjavaformat/open-java-format/pull/175/files
Reloadhttps://github.com/openjavaformat/open-java-format/pull/175/files
openjavaformathttps://github.com/openjavaformat
open-java-formathttps://github.com/openjavaformat/open-java-format
Codehttps://github.com/openjavaformat/open-java-format
Issues30 (30)https://github.com/openjavaformat/open-java-format/issues
Pull requests5 (5)https://github.com/openjavaformat/open-java-format/pulls
Discussionshttps://github.com/openjavaformat/open-java-format/discussions
Actionshttps://github.com/openjavaformat/open-java-format/actions
Security and qualityhttps://github.com/openjavaformat/open-java-format/security
Insightshttps://github.com/openjavaformat/open-java-format/pulse
Sign up for GitHub https://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://github.com/login?return_to=%2Fopenjavaformat%2Fopen-java-format%2Fissues%2Fnew%2Fchoose
abashevhttps://github.com/abashev
21.X.Xhttps://github.com/openjavaformat/open-java-format/tree/21.X.X
fix/comment-after-opening-delimiterhttps://github.com/openjavaformat/open-java-format/tree/fix/comment-after-opening-delimiter
Conversation 0 https://github.com/openjavaformat/open-java-format/pull/175
Commits 1 https://github.com/openjavaformat/open-java-format/pull/175/commits
Checks 17 https://github.com/openjavaformat/open-java-format/pull/175/checks
Files changed https://github.com/openjavaformat/open-java-format/pull/175/files
Please reload this pagehttps://github.com/openjavaformat/open-java-format/pull/175/files
Indent a comment after an opening delimiter like the code after it https://github.com/openjavaformat/open-java-format/pull/175/files#top
Show all changes 1 commit https://github.com/openjavaformat/open-java-format/pull/175/files
06edc5b Indent a comment after an opening delimiter like the code after it abashev Oct 30, 2026 https://github.com/openjavaformat/open-java-format/pull/175/commits/06edc5bf9cb9d0088986737419b5975d75fd957c
Clear filters https://github.com/openjavaformat/open-java-format/pull/175/files
Please reload this pagehttps://github.com/openjavaformat/open-java-format/pull/175/files
Please reload this pagehttps://github.com/openjavaformat/open-java-format/pull/175/files
OpsBuilder.java https://github.com/openjavaformat/open-java-format/pull/175/files#diff-8fde53d5c7976d369ff9f2bb92828e5db2c64633df01fc1c75de795586ea6cd9
JavaInputAstVisitor.java https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
commentAfterOpeningDelimiter-assert.case https://github.com/openjavaformat/open-java-format/pull/175/files#diff-786b1610fff9f8d5c7465cecaf21f18ab049e96ffb88fd8914ef0149d1879bea
commentAfterOpeningDelimiter-enumSemicolon.case https://github.com/openjavaformat/open-java-format/pull/175/files#diff-89f43edf947c2e04fceee9ea1129b3afffeacdd60887ac753ec2f2e3a179f871
commentAfterOpeningDelimiter-forHeader.case https://github.com/openjavaformat/open-java-format/pull/175/files#diff-d77ee5303a4f3ff6856b21f90a69020cce363700180f4e600914ccdf69cac0be
commentAfterOpeningDelimiter-multiCatch.case https://github.com/openjavaformat/open-java-format/pull/175/files#diff-8dde1b1f49e9dee3dbe7fbf5053f525487bc4965fa80ab6863ce4c2aff7d736e
commentAfterOpeningDelimiter-tryResources.case https://github.com/openjavaformat/open-java-format/pull/175/files#diff-530ce6e3d3afdc93a74be92a3ed94e0fa3e4204ce7e8040ca1eb498f09d2a8d8
commentAfterOpeningDelimiter-typeArguments.case https://github.com/openjavaformat/open-java-format/pull/175/files#diff-bbc6d111ef7d91bd94192133d26b4e8202503d2bbae1822831a6972c7e846865
open-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.javahttps://github.com/openjavaformat/open-java-format/pull/175/files#diff-8fde53d5c7976d369ff9f2bb92828e5db2c64633df01fc1c75de795586ea6cd9
View file https://github.com/openjavaformat/open-java-format/blob/06edc5bf9cb9d0088986737419b5975d75fd957c/open-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/openjavaformat/open-java-format/pull/175/{{ revealButtonHref }}
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-8fde53d5c7976d369ff9f2bb92828e5db2c64633df01fc1c75de795586ea6cd9
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-8fde53d5c7976d369ff9f2bb92828e5db2c64633df01fc1c75de795586ea6cd9
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-8fde53d5c7976d369ff9f2bb92828e5db2c64633df01fc1c75de795586ea6cd9
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-8fde53d5c7976d369ff9f2bb92828e5db2c64633df01fc1c75de795586ea6cd9
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-8fde53d5c7976d369ff9f2bb92828e5db2c64633df01fc1c75de795586ea6cd9
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-8fde53d5c7976d369ff9f2bb92828e5db2c64633df01fc1c75de795586ea6cd9
open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.javahttps://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
View file https://github.com/openjavaformat/open-java-format/blob/06edc5bf9cb9d0088986737419b5975d75fd957c/open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/openjavaformat/open-java-format/pull/175/{{ revealButtonHref }}
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
https://github.com/openjavaformat/open-java-format/pull/175/files#diff-4c56c3f402a5387ffa98b467fa35d91986b454b87e4a1b47b11da48e30272fc3
open-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-assert.casehttps://github.com/openjavaformat/open-java-format/pull/175/files#diff-786b1610fff9f8d5c7465cecaf21f18ab049e96ffb88fd8914ef0149d1879bea
View file https://github.com/openjavaformat/open-java-format/blob/06edc5bf9cb9d0088986737419b5975d75fd957c/open-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-assert.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/openjavaformat/open-java-format/pull/175/{{ revealButtonHref }}
...java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-enumSemicolon.casehttps://github.com/openjavaformat/open-java-format/pull/175/files#diff-89f43edf947c2e04fceee9ea1129b3afffeacdd60887ac753ec2f2e3a179f871
View file https://github.com/openjavaformat/open-java-format/blob/06edc5bf9cb9d0088986737419b5975d75fd957c/open-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-enumSemicolon.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/openjavaformat/open-java-format/pull/175/{{ revealButtonHref }}
open-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-forHeader.casehttps://github.com/openjavaformat/open-java-format/pull/175/files#diff-d77ee5303a4f3ff6856b21f90a69020cce363700180f4e600914ccdf69cac0be
View file https://github.com/openjavaformat/open-java-format/blob/06edc5bf9cb9d0088986737419b5975d75fd957c/open-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-forHeader.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/openjavaformat/open-java-format/pull/175/{{ revealButtonHref }}
open-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-multiCatch.casehttps://github.com/openjavaformat/open-java-format/pull/175/files#diff-8dde1b1f49e9dee3dbe7fbf5053f525487bc4965fa80ab6863ce4c2aff7d736e
View file https://github.com/openjavaformat/open-java-format/blob/06edc5bf9cb9d0088986737419b5975d75fd957c/open-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-multiCatch.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/openjavaformat/open-java-format/pull/175/{{ revealButtonHref }}
...-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-tryResources.casehttps://github.com/openjavaformat/open-java-format/pull/175/files#diff-530ce6e3d3afdc93a74be92a3ed94e0fa3e4204ce7e8040ca1eb498f09d2a8d8
View file https://github.com/openjavaformat/open-java-format/blob/06edc5bf9cb9d0088986737419b5975d75fd957c/open-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-tryResources.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/openjavaformat/open-java-format/pull/175/{{ revealButtonHref }}
...java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-typeArguments.casehttps://github.com/openjavaformat/open-java-format/pull/175/files#diff-bbc6d111ef7d91bd94192133d26b4e8202503d2bbae1822831a6972c7e846865
View file https://github.com/openjavaformat/open-java-format/blob/06edc5bf9cb9d0088986737419b5975d75fd957c/open-java-format/src/test/resources/test-cases/commentAfterOpeningDelimiter-typeArguments.case
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/openjavaformat/open-java-format/pull/175/{{ revealButtonHref }}
Please reload this pagehttps://github.com/openjavaformat/open-java-format/pull/175/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.