Skip to content

[JEP 512] Add support for compact source files#4940

Merged
jlerbsc merged 13 commits intojavaparser:masterfrom
johannescoetzee:johannes/compact-classes
Jan 10, 2026
Merged

[JEP 512] Add support for compact source files#4940
jlerbsc merged 13 commits intojavaparser:masterfrom
johannescoetzee:johannes/compact-classes

Conversation

@johannescoetzee
Copy link
Copy Markdown
Collaborator

Resolves #4869 and replaces #4902 by @rpx99. I adapted the logic introduced to java.jj in that PR to fix an issue with the ordering of the members of the compact class.

This PR adds support for compact source files/classes introduced in Java 25. It does so by explicitly creating the ClassOrInterfaceDeclaration node for the compact class with a new isCompact field set to true.

Adding support for the LPP turned out to be quite complicated. Support for adding/removing members from a compact class was fairly straightforward, but I ran into lots of issues when adding support for converting a non-compact class a compact class and vice-versa. The implementation here still doesn't handle whitespace 100% correctly, but it's close to correct and I've already spent about as much time as I reasonably can debugging it. In my opinion this niche case should not be a blocker, especially considering the LPP does support "normal" operations on these classes.

@johannescoetzee johannescoetzee added this to the next release milestone Dec 24, 2025
@johannescoetzee johannescoetzee added the PR: Added A PR that introduces new behaviour (e.g. functionality, tests) label Dec 24, 2025
@jlerbsc
Copy link
Copy Markdown
Collaborator

jlerbsc commented Dec 31, 2025

@johannescoetzee The PR will be merged as soon as the errors have been corrected. A new version of JavaParser will then be released.

JavaParserVariableDeclarationTest.javaBaseTypeFromImplicitCompactClassImport:171 » UnsolvedSymbol Unsolved symbol : List

@johannescoetzee johannescoetzee force-pushed the johannes/compact-classes branch from c6557c0 to d043ca8 Compare January 5, 2026 13:04
@johannescoetzee johannescoetzee force-pushed the johannes/compact-classes branch from d043ca8 to d780adb Compare January 5, 2026 13:06
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 76.79325% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.394%. Comparing base (7de2cc3) to head (4fd7325).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
.../github/javaparser/printer/PrettyPrintVisitor.java 21.153% 34 Missing and 7 partials ⚠️
...vaparser/ast/body/ClassOrInterfaceDeclaration.java 91.111% 3 Missing and 1 partial ⚠️
...parser/printer/lexicalpreservation/Difference.java 78.571% 1 Missing and 2 partials ⚠️
...m/github/javaparser/ast/visitor/EqualsVisitor.java 0.000% 0 Missing and 1 partial ⚠️
...github/javaparser/ast/visitor/HashCodeVisitor.java 0.000% 0 Missing and 1 partial ⚠️
...javaparser/ast/visitor/NoCommentEqualsVisitor.java 0.000% 0 Missing and 1 partial ⚠️
...vaparser/ast/visitor/NoCommentHashCodeVisitor.java 0.000% 0 Missing and 1 partial ⚠️
...parser/resolution/logic/MethodResolutionLogic.java 0.000% 1 Missing ⚠️
...com/github/javaparser/GeneratedJavaParserBase.java 95.238% 0 Missing and 1 partial ⚠️
...del/contexts/JavaParserTypeDeclarationAdapter.java 83.333% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##              master     #4940   +/-   ##
===========================================
  Coverage     58.394%   58.394%           
  Complexity      2564      2564           
===========================================
  Files            689       689           
  Lines          39798     39798           
  Branches        7244      7244           
===========================================
  Hits           23240     23240           
  Misses         13605     13605           
  Partials        2953      2953           
Flag Coverage Δ
AlsoSlowTests 58.394% <76.793%> (ø)
javaparser-core 58.394% <76.793%> (ø)
javaparser-symbol-solver 58.394% <76.793%> (ø)
jdk-10 57.964% <76.793%> (ø)
jdk-11 57.963% <76.793%> (ø)
jdk-12 57.963% <76.793%> (ø)
jdk-13 57.963% <76.793%> (ø)
jdk-14 58.196% <76.793%> (ø)
jdk-15 58.194% <76.793%> (-0.003%) ⬇️
jdk-16 58.171% <76.793%> (+0.002%) ⬆️
jdk-17 58.322% <76.793%> (ø)
jdk-18 58.322% <76.793%> (ø)
jdk-8 57.797% <75.105%> (ø)
jdk-9 57.959% <76.793%> (ø)
macos-latest 58.387% <76.793%> (ø)
ubuntu-latest 58.382% <76.793%> (ø)
windows-latest 58.377% <76.793%> (ø)

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

Files with missing lines Coverage Δ
...ub/javaparser/ast/observer/ObservableProperty.java 87.096% <100.000%> (ø)
...om/github/javaparser/ast/visitor/CloneVisitor.java 42.164% <100.000%> (ø)
...etamodel/ClassOrInterfaceDeclarationMetaModel.java 100.000% <ø> (ø)
...thub/javaparser/metamodel/JavaParserMetaModel.java 99.709% <100.000%> (ø)
...github/javaparser/printer/ConcreteSyntaxModel.java 99.262% <100.000%> (ø)
...avaparser/printer/DefaultPrettyPrinterVisitor.java 93.233% <100.000%> (ø)
...l/contexts/ClassOrInterfaceDeclarationContext.java 90.000% <ø> (ø)
...m/github/javaparser/ast/visitor/EqualsVisitor.java 23.205% <0.000%> (ø)
...github/javaparser/ast/visitor/HashCodeVisitor.java 61.351% <0.000%> (ø)
...javaparser/ast/visitor/NoCommentEqualsVisitor.java 4.852% <0.000%> (ø)
... and 7 more

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 a45797e...4fd7325. Read the comment docs.

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

@johannescoetzee johannescoetzee force-pushed the johannes/compact-classes branch from d780adb to 266c0bb Compare January 5, 2026 13:31
@johannescoetzee
Copy link
Copy Markdown
Collaborator Author

I missed this testcase since I was running all the tests with Java 8, apparently. It's all fixed now

customInitialization();
}

/**
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't really understand what the point of it was.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the comment to simplify it somewhat. Please let me know if it's still unclear

return SymbolReference.solved(JavaParserFacade.get(typeSolver).getTypeDeclaration(wrappedNode));
}

if (this.wrappedNode.isClassOrInterfaceDeclaration()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this redundant with what is already done in the ClassOrInterfaceDeclarationContext class?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I did in the ClassOrInterfaceDeclarationContext class was actually incorrect. That logic was triggered for solving symbols as values (for example resolving the identifier listMember to the relevant member), so it was actually just attempting to resolve names like java.util.listMember. I've removed this logic from ClassOrInterfaceDeclarationContext and added a test to demonstrate that resolving such symbols works.

@jlerbsc
Copy link
Copy Markdown
Collaborator

jlerbsc commented Jan 6, 2026

Have you finished this PR?

@jlerbsc
Copy link
Copy Markdown
Collaborator

jlerbsc commented Jan 6, 2026

I will have to be away for two or three days, but as soon as I am back, I will create a new version of JP.

@jlerbsc jlerbsc merged commit 65b4cbc into javaparser:master Jan 10, 2026
35 checks passed
@jlerbsc
Copy link
Copy Markdown
Collaborator

jlerbsc commented Jan 10, 2026

Thank you for this important new PR

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 512: Compact Source Files and Instance Main Methods

2 participants