feature: add support for java 14 switch/yield #3314
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Java 14 Switches
Jep361 defines a new switchExpression.
@Egor18 implemented them already without yield( awesome work btw).
This pr adds support for java14 switches with yield and with this change spoon supports all java14 features that are non preview(records and textblocks are only part of jdt beta branch and still preview)
Whats part of this PR
Consequences
There are 2 consequence expect more code.
spoon loses the ability to parse java 12 preview code with break [expression]
Currently spoon supports them, but i would instantly drop support for a feature that was never part java (only preview) and wont come back.
Yield
replaces this.Supported preview features should be seen as an experimental feature and i hope no one is relaying on them.
####junit5 in testclasses####
I cant guarantee that every testrunner in everyones IDE fully supports junit5.
I would be nice if you could test the refactored SwitchCaseTest.
Reward is a much clearer design for the testclasses.
upgrading jdt to 3.20 produced 2 problems
Luckily there were only 2 visible problems after upgrading it.
break.isImplicit
flag was removedwasn't a big problem, because there are no longer needed.
PackageBinding.java was changed to a abstract class
Is a bigger problem, but current there is a fix.
For (potential) fix see src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java#363
Maybe someone with more knowledge about this class could review it.
interesting more academic fact
Is allowed code
but the following is not allowed.
This behavior seems intended, because looking at java grammar we find:
SwitchRule:
SwitchLabel -> Expression ;
SwitchLabel -> Block
SwitchLabel -> ThrowStatement
and yield is not an expression but a StatementWithoutTrailingSubstatement from my understanding.
tl;dr;