Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JEP-440 and 441 #4661

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Conversation

nielsdebruin
Copy link
Contributor

@nielsdebruin nielsdebruin commented Nov 11, 2024

What's changed?

Initial test cases for verifying parser support for JEP 440 and 441. The goal of these tests is to demonstrate that code containing JEP 440/441 structures remains unchanged. The tests very closely resemble the code snippets used in the JEPs themselves to describe their changes. They can be summarized as follows:

Pattern Switch Statement
Verifies that switch expressions using patterns for different object types (e.g., Integer, Long, Double, String) maintain structure after parsing.

Pattern Matching for Records
Tests parsing of instanceof with record deconstruction (e.g., if (obj instanceof Point(int x, int y))), ensuring that records can be deconstructed and match syntax remains unchanged.

Nested Pattern Matching for Records and Enums
Ensures that nested pattern matching with records containing other records and enums (e.g., Rectangle(ColoredPoint(Point p, Color c), ColoredPoint lr)) is correctly handled and maintains structure.

null Case Handling in Switch Statements
Checks that switch cases with null handling (e.g., case null ->)

Improved Enum Support with Sealed Types
Tests switch handling for sealed types and enums (e.g., case Foo.CLUBS, case Bar b) to ensure that sealed interfaces with enums and final classes maintain parsing integrity.

Relaxed Type Restrictions in Switch Statements
Verifies that switch cases with mixed types (e.g., String, Color, Point, int[]) correctly serialize and deserialize while preserving type information.

Special Integer Cases in Switch
Tests specific integer cases and when clauses (e.g., case -1, 1, case Integer j when (j - 1) > -1) in switch statements, ensuring all conditional logic remains intact after parsing.

What's your motivation?

Provide support for JEP 440/441

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@nielsdebruin nielsdebruin linked an issue Nov 11, 2024 that may be closed by this pull request
@nielsdebruin nielsdebruin changed the title 4660 support jep 440 and 441 4660 support JEP 440 and 441 Nov 11, 2024
@timtebeek timtebeek self-requested a review November 11, 2024 23:12
@knutwannheden
Copy link
Contributor

Aren't some of the tests (like record pattern matching) for preview only features? So far we haven't supported any preview features and people haven't really asked for it either.

@nielsdebruin
Copy link
Contributor Author

As far as I understand it, both 440/441 have been delivered/closed (see status in 440 and 441) and have been included in the release of Java 21 as permanent JEPs (source: https://www.jrebel.com/blog/java-21).

I double-checked by running some of the code snippets in these using Java Termurin-21.0.4, which worked fine.

@knutwannheden
Copy link
Contributor

I think you are right. I missed that!

@timtebeek timtebeek changed the title 4660 support JEP 440 and 441 Support JEP-440 and 441 Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Support JEP 440 and 441
2 participants