Skip to content

added the new switch expression usage for jdk equal or greater than 13#4065

Open
bydrim wants to merge 1 commit into
mapstruct:mainfrom
bydrim:feat/switch-exp-jdk13
Open

added the new switch expression usage for jdk equal or greater than 13#4065
bydrim wants to merge 1 commit into
mapstruct:mainfrom
bydrim:feat/switch-exp-jdk13

Conversation

@bydrim

@bydrim bydrim commented Jun 5, 2026

Copy link
Copy Markdown

As described in the issue #4062 for jdk equal or greater than 13 the usage of new switch expression added. Related fixtures are updated. Also as discussed with Filip, for switch expressions with only default case, defaultTarget is directly assigned without switch expression, such as

ExternalOrderType externalOrderType = ExternalOrderType.DEFAULT;

@bydrim

bydrim commented Jun 7, 2026

Copy link
Copy Markdown
Author

It seems that the code is not compliant with the formatting rules. Working on it.

@bydrim bydrim force-pushed the feat/switch-exp-jdk13 branch from 6e20680 to ca10fcc Compare June 7, 2026 11:44
@bydrim

bydrim commented Jun 7, 2026

Copy link
Copy Markdown
Author

I realized that Reformat Code on save was not active on my Intellij. I used git squash to keep the git logs clean, so these are the formatting changes:

  • ValueMappingMethod.java line 567
  • DefaultVersionInformation.java line 7 (actually i didn't touch this line in my first commit but intellij formatted when i was reformatting the whole file)

@bydrim

bydrim commented Jun 7, 2026

Copy link
Copy Markdown
Author

The fail seems to be related to codecov migrating their keybase accounts. Their advice is to use v7, and currently v5 is used in this project.

@hduelme

hduelme commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@bydrim yes the JDK 21 pipline failed because of the issue you referenced. We upgraded the plugin to v7.

The fail seems to be related to codecov migrating their keybase accounts. Their advice is to use v7, and currently v5 is used in this project.

@hduelme hduelme left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bydrim nice work.
I think we could stop generating the default branch if all enum values are explicitly covered by case statements. Am I overlooking something, or would that work here? Let me know what you think.

<#list valueMappings as valueMapping>
case <@writeSource source=valueMapping.source/> -> <#if valueMapping.targetAsException > throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} );<#else><@writeTarget target=valueMapping.target/>;</#if>
</#list>
default -> <#if defaultTarget.targetAsException >throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} )<#else><@writeTarget target=defaultTarget.target/></#if>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The default branch is only necessary when not all values are explicitly covered by a case.

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.

2 participants