Skip to content

Comments

Check live options when determine what java level is used for parsing#4856

Merged
iloveeclipse merged 2 commits intoeclipse-jdt:masterfrom
laeubi:issue_4849_mr_jls
Feb 19, 2026
Merged

Check live options when determine what java level is used for parsing#4856
iloveeclipse merged 2 commits intoeclipse-jdt:masterfrom
laeubi:issue_4849_mr_jls

Conversation

@laeubi
Copy link
Contributor

@laeubi laeubi commented Feb 19, 2026

Currently the Parser determines what java version is parsed once in the
constructor and store them into (modifiable) fields. This causes issues
when the options are modified as everything else works but this
particular fields are not updated.

Instead of having a way to update those fields and as they do not cache
any complex computations, this fields are now replaced with appropriate
getters like it is already done in some cases.

Fix #4849

@laeubi laeubi changed the title Enhance Testcase to use new Language Feature in MRJar Compilation Check live options when determine what java level is used for parsing Feb 19, 2026
@laeubi
Copy link
Contributor Author

laeubi commented Feb 19, 2026

@stephan-herrmann can you review? This now passes the enhanced test-case with check for new language levels.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the Parser class to dynamically check Java version options instead of caching them in static fields. This enables proper multi-release JAR support where different source folders need different Java Language Specification (JLS) levels.

Changes:

  • Removed static boolean fields (parsingJava*Plus, previewEnabled) from Parser that were set once in the constructor
  • Replaced field access with dynamic getter methods that check this.options.sourceLevel on each call
  • Added a test case with Java 21 features (pattern matching, text blocks) to verify multi-release compilation

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Parser.java Removes cached parser version fields, adds dynamic getter methods that check options live, enabling proper multi-release support
CompletionParser.java Updates single reference from field to method call for preview feature check
MultiReleaseTests.java Adds test case with Java 21 features to verify multi-release compilation works correctly
Comments suppressed due to low confidence (1)

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java:13331

  • Inconsistent spacing around null comparison operator. The codebase predominantly uses spaces around != (e.g., != null), but this code uses !=null without spaces. For consistency, consider using spaces: this.options != null.
	return this.options!=null && this.options.sourceLevel >= ClassFileConstants.JDK9;
}
protected boolean isParsingJava10Plus() {
	return this.options!=null && this.options.sourceLevel >= ClassFileConstants.JDK10;
}
protected boolean isParsingJava11Plus() {
	return this.options!=null && this.options.sourceLevel >= ClassFileConstants.JDK11;
}
protected boolean isParsingJava14Plus() {
	return this.options!=null && this.options.sourceLevel >= ClassFileConstants.JDK14;
}
protected boolean isParsingJava15Plus() {
	return this.options!=null && this.options.sourceLevel >= ClassFileConstants.JDK15;
}
protected boolean isParsingJava17Plus() {
	return this.options!=null && this.options.sourceLevel >= ClassFileConstants.JDK17;
}
protected boolean isParsingJava18Plus() {
	return this.options!=null && this.options.sourceLevel >= ClassFileConstants.JDK18;
}
protected boolean isParsingJava21Plus() {
	return this.options!=null && this.options.sourceLevel >= ClassFileConstants.JDK21;
}
protected boolean isParsingJava22Plus() {
	return this.options!=null && this.options.sourceLevel >= ClassFileConstants.JDK22;
}

protected boolean isPreviewEnabled() {
	return this.options!=null && this.options.sourceLevel == ClassFileConstants.getLatestJDKLevel() && this.options.enablePreviewFeatures;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@srikanth-sankaran srikanth-sankaran left a comment

Choose a reason for hiding this comment

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

Looks good other than that many null checks are provably redundant.

Didn't check the test, only the code changes

Copy link
Member

@iloveeclipse iloveeclipse left a comment

Choose a reason for hiding this comment

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

Moving fields access to methods revealed unused code. I would not add unused methods, we have enough dead code in JDT. Beside this should be OK.

return this.options != null && this.options.sourceLevel >= ClassFileConstants.JDK11;
}

protected boolean isParsingJava14Plus() {
Copy link
Member

Choose a reason for hiding this comment

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

This method can be removed, all callers too, but in a later PR

@iloveeclipse
Copy link
Member

@laeubi : could you please squash three last commits into one, so that PR has two commits - one for tests and one for the fix? Thanks.

Currently the Parser determines what java version is parsed once in the
constructor and store them into (modifiable) fields. This causes issues
when the options are modified as everything else works but this
particular fields are not updated.

Instead of having a way to update those fields and as they do not cache
any complex computations, this fields are now replaced with appropriate
getters like it is already done in some cases.

Fix eclipse-jdt#4849
@laeubi
Copy link
Contributor Author

laeubi commented Feb 19, 2026

Squashed and rebased now.

@iloveeclipse
Copy link
Member

OK all tests green, let's merge for RC1.

@iloveeclipse iloveeclipse merged commit 33d7b9f into eclipse-jdt:master Feb 19, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support compilation for different JLS levels in multi-release projects

3 participants