Skip to content

[JEP 513] Add support for flexible constructor bodies#4919

Merged
jlerbsc merged 5 commits into
javaparser:masterfrom
johannescoetzee:johannes/flexible-constructor-bodies
Dec 11, 2025
Merged

[JEP 513] Add support for flexible constructor bodies#4919
jlerbsc merged 5 commits into
javaparser:masterfrom
johannescoetzee:johannes/flexible-constructor-bodies

Conversation

@johannescoetzee

Copy link
Copy Markdown
Collaborator

Fixes #4849
Replaces #4903

This PR removes the restriction that explicit constructor invocations must appear as the first statement in a constructor body. See https://openjdk.org/jeps/513 for more details regarding the motivations behind this change.

The grammar change was inspired by #4903 opened by @rpx99, although I did add my own comment explaining why handling it this way should be fine, even if it isn't 100% correct according to the JLS (we handle compiling code correctly, but also parse some non-compiling code without reporting errors; if users choose to parse non-compiling code, then they will need to do their own validation according to their needs).

I've also included a simplified validator compared to #4903 with validator tests and AST tests.

Finally, I've also included pretty printer and LPP tests, but didn't need to update either of those to support this.

@johannescoetzee

Copy link
Copy Markdown
Collaborator Author

@jlerbsc I would like to discuss some things regarding the project with you (how we could best collaborate, etc.) and sent you a message on the JavaParser Gitter to that effect. Since that doesn't seem to be a platform either of us uses regularly, feel free to contact me via email (should be visible in my commit information) or suggest a suitable platform if you're interested :)

@johannescoetzee johannescoetzee force-pushed the johannes/flexible-constructor-bodies branch from 2bea554 to 0e6f25b Compare December 10, 2025 15:48
@codecov

codecov Bot commented Dec 10, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 58.445%. Comparing base (605b4d7) to head (0e6f25b).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
...r/language_level_validations/Java1_0Validator.java 88.888% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##              master     #4919       +/-   ##
===============================================
+ Coverage     58.430%   58.445%   +0.015%     
  Complexity      2560      2560               
===============================================
  Files            689       689               
  Lines          39543     39553       +10     
  Branches        7173      7176        +3     
===============================================
+ Hits           23105     23117       +12     
+ Misses         13498     13497        -1     
+ Partials        2940      2939        -1     
Flag Coverage Δ
AlsoSlowTests 58.445% <90.000%> (+0.015%) ⬆️
javaparser-core 58.445% <90.000%> (+0.015%) ⬆️
javaparser-symbol-solver 58.445% <90.000%> (+0.015%) ⬆️
jdk-10 58.009% <90.000%> (+0.015%) ⬆️
jdk-11 58.008% <90.000%> (+0.013%) ⬆️
jdk-12 58.008% <90.000%> (+0.013%) ⬆️
jdk-13 58.011% <90.000%> (+0.018%) ⬆️
jdk-14 58.246% <90.000%> (+0.015%) ⬆️
jdk-15 58.246% <90.000%> (+0.015%) ⬆️
jdk-16 58.221% <90.000%> (+0.015%) ⬆️
jdk-17 58.372% <90.000%> (+0.015%) ⬆️
jdk-18 58.372% <90.000%> (+0.015%) ⬆️
jdk-8 57.854% <90.000%> (+0.018%) ⬆️
jdk-9 58.007% <90.000%> (+0.013%) ⬆️
macos-latest 58.438% <90.000%> (+0.045%) ⬆️
ubuntu-latest 58.432% <90.000%> (+0.015%) ⬆️
windows-latest 58.427% <90.000%> (+0.015%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...or/language_level_validations/Java25Validator.java 100.000% <100.000%> (ø)
...r/language_level_validations/Java1_0Validator.java 92.028% <88.888%> (-0.220%) ⬇️

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6232a21...0e6f25b. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jlerbsc

jlerbsc commented Dec 10, 2025

Copy link
Copy Markdown
Collaborator

Does this seem correct to me? Can I merge this PR?

@jlerbsc

jlerbsc commented Dec 11, 2025

Copy link
Copy Markdown
Collaborator

@jlerbsc I would like to discuss some things regarding the project with you (how we could best collaborate, etc.) and sent you a message on the JavaParser Gitter to that effect. Since that doesn't seem to be a platform either of us uses regularly, feel free to contact me via email (should be visible in my commit information) or suggest a suitable platform if you're interested :)

I have replied to your message on Gitter. I hope you find my answers helpful.

@johannescoetzee

Copy link
Copy Markdown
Collaborator Author

Does this seem correct to me? Can I merge this PR?

Yes, this can be merged if you're satisfied with it

@jlerbsc

jlerbsc commented Dec 11, 2025

Copy link
Copy Markdown
Collaborator

Thank you for this contribution.

@jlerbsc jlerbsc merged commit a5a9bae into javaparser:master Dec 11, 2025
35 checks passed
@jlerbsc jlerbsc added this to the next release milestone Dec 11, 2025
@jlerbsc jlerbsc added the PR: Added A PR that introduces new behaviour (e.g. functionality, tests) label Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Added A PR that introduces new behaviour (e.g. functionality, tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JEP 513 : Flexible Constructor Bodies

2 participants