Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public String getDisplayName() {
@Override
public String getDescription() {
return "Switch statements for which each case is assigning a value to the same variable can be converted to a switch expression that returns the value of the variable. " +
"This is only applicable for Java 17 and later.";
"This recipe is only applicable for Java 21 and later.";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
TreeVisitor<?, ExecutionContext> preconditions = Preconditions.and(
new UsesJavaVersion<>(17),
new UsesJavaVersion<>(21),
Preconditions.not(new KotlinFileChecker<>()),
Preconditions.not(new GroovyFileChecker<>())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ public String getDisplayName() {

@Override
public String getDescription() {
return "Switch statements where each case returns a value can be converted to a switch expression that returns the value directly.";
return "Switch statements where each case returns a value can be converted to a switch expression that returns the value directly. " +
"This recipe is only applicable for Java 21 and later.";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
TreeVisitor<?, ExecutionContext> preconditions = Preconditions.and(
new UsesJavaVersion<>(14),
new UsesJavaVersion<>(21),
Preconditions.not(new KotlinFileChecker<>()),
Preconditions.not(new GroovyFileChecker<>())
);
Expand All @@ -63,12 +64,7 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) {
J.Switch sw = (J.Switch) statement;
if (canConvertToSwitchExpression(sw)) {
J.SwitchExpression switchExpression = convertToSwitchExpression(sw);
return new J.Return(
randomId(),
sw.getPrefix(),
Markers.EMPTY,
switchExpression
);
return new J.Return(randomId(), sw.getPrefix(), Markers.EMPTY, switchExpression);
}
}
return statement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ public String getDisplayName() {

@Override
public String getDescription() {
return "Convert switch expressions with colon cases and yield statements to arrow syntax.";
return "Convert switch expressions with colon cases and yield statements to arrow syntax. " +
"This recipe is only applicable for Java 21 and later.";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
TreeVisitor<?, ExecutionContext> preconditions = Preconditions.and(
new UsesJavaVersion<>(14),
new UsesJavaVersion<>(21),
Preconditions.not(new KotlinFileChecker<>()),
Preconditions.not(new GroovyFileChecker<>())
);
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/META-INF/rewrite/java-version-17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ recipeList:
artifactId: commons-codec
newVersion: 1.17.x
- org.openrewrite.java.migrate.AddLombokMapstructBinding
- org.openrewrite.java.migrate.lang.SwitchCaseAssignmentsToSwitchExpression
- org.openrewrite.java.migrate.lang.SwitchCaseReturnsToSwitchExpression
- org.openrewrite.java.migrate.lang.SwitchExpressionYieldToArrow
- org.openrewrite.java.migrate.UpdateJakartaAnnotationsIfForJavax
- org.openrewrite.java.migrate.UpdateJakartaAnnotationsIfExistsForJakarta

Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/META-INF/rewrite/java-version-21.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ recipeList:
- org.openrewrite.java.migrate.UpgradePluginsForJava21
- org.openrewrite.java.migrate.DeleteDeprecatedFinalize
- org.openrewrite.java.migrate.RemovedSubjectMethods
# TODO: Remove these recipes from this list once `SwitchPatternMatching` has been enabled
- org.openrewrite.java.migrate.lang.SwitchCaseAssignmentsToSwitchExpression
- org.openrewrite.java.migrate.lang.SwitchCaseReturnsToSwitchExpression
- org.openrewrite.java.migrate.lang.SwitchExpressionYieldToArrow
#- org.openrewrite.java.migrate.SwitchPatternMatching
#- org.openrewrite.java.migrate.lang.NullCheckAsSwitchCase

Expand Down Expand Up @@ -142,6 +146,9 @@ description: >-
tags:
- java21
recipeList:
- org.openrewrite.java.migrate.lang.SwitchCaseAssignmentsToSwitchExpression
- org.openrewrite.java.migrate.lang.SwitchCaseReturnsToSwitchExpression
- org.openrewrite.java.migrate.lang.SwitchExpressionYieldToArrow
- org.openrewrite.java.migrate.lang.IfElseIfConstructToSwitch
- org.openrewrite.java.migrate.lang.RefineSwitchCases
- org.openrewrite.java.migrate.lang.SwitchCaseEnumGuardToLabel
Loading