Skip to content

Commit

Permalink
Disable for C# as the reasoning for changing to switch is different (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurens-W authored Dec 9, 2024
1 parent b412e1d commit b9917c0
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.Value;
import lombok.With;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.ListUtils;
Expand All @@ -29,6 +30,7 @@
import org.openrewrite.java.tree.*;
import org.openrewrite.marker.Marker;
import org.openrewrite.marker.Markers;
import org.openrewrite.staticanalysis.csharp.CSharpFileChecker;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -58,7 +60,7 @@ public Set<String> getTags() {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new JavaVisitor<ExecutionContext>() {
return Preconditions.check(Preconditions.not(new CSharpFileChecker<>()), new JavaVisitor<ExecutionContext>() {
final JavaTemplate ifElseIfPrimitive = JavaTemplate.builder("" +
"if(#{any()} == #{any()}) {\n" +
"} else if(#{any()} == #{any()}) {\n" +
Expand Down Expand Up @@ -222,7 +224,7 @@ private boolean doRewrite(J.Switch switch_) {
return false;
}
return switch_.getCases().getStatements().stream()
.reduce(0, (a, b) -> a + ((J.Case) b).getExpressions().size(), Integer::sum) < 3;
.reduce(0, (a, b) -> a + ((J.Case) b).getExpressions().size(), Integer::sum) < 3;
}

private List<Statement> getStatements(J.Case aCase) {
Expand All @@ -247,7 +249,7 @@ private boolean switchesOnEnum(J.Switch switch_) {
((JavaType.Class) selectorType).getKind() == JavaType.Class.Kind.Enum;
}

};
});
}

private static J.If createIfForEnum(Expression expression, Expression enumTree) {
Expand Down

0 comments on commit b9917c0

Please sign in to comment.