From f3ff9a02c3ae095bf058da625edcee70e9d81097 Mon Sep 17 00:00:00 2001 From: "Roman.Ivanov" Date: Fri, 14 Dec 2018 16:17:05 +0700 Subject: [PATCH] suppress inspection for switch backward migration when not -> used: IDEA-204207 --- .../EnhancedSwitchBackwardMigrationInspection.java | 3 ++- .../beforeSwitchOldStyle.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/inspection/switchExpressionBackwardMigration/beforeSwitchOldStyle.java diff --git a/java/java-impl/src/com/intellij/codeInspection/EnhancedSwitchBackwardMigrationInspection.java b/java/java-impl/src/com/intellij/codeInspection/EnhancedSwitchBackwardMigrationInspection.java index b224aed5ff70..1468f0d7351c 100644 --- a/java/java-impl/src/com/intellij/codeInspection/EnhancedSwitchBackwardMigrationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/EnhancedSwitchBackwardMigrationInspection.java @@ -34,6 +34,7 @@ public class EnhancedSwitchBackwardMigrationInspection extends AbstractBaseJavaL return new JavaElementVisitor() { @Override public void visitSwitchExpression(PsiSwitchExpression expression) { + if (!SwitchUtils.isRuleFormatSwitch(expression)) return; if (findReplacer(expression) == null) return; String message = InspectionsBundle.message("inspection.switch.expression.backward.expression.migration.inspection.name"); holder.registerProblem(expression.getFirstChild(), message, new ReplaceWithOldStyleSwitchFix()); @@ -41,8 +42,8 @@ public class EnhancedSwitchBackwardMigrationInspection extends AbstractBaseJavaL @Override public void visitSwitchStatement(PsiSwitchStatement statement) { - if (findReplacer(statement) == null) return; if (!SwitchUtils.isRuleFormatSwitch(statement)) return; + if (findReplacer(statement) == null) return; String message = InspectionsBundle.message("inspection.switch.expression.backward.statement.migration.inspection.name"); holder.registerProblem(statement.getFirstChild(), message, new ReplaceWithOldStyleSwitchFix()); } diff --git a/java/java-tests/testData/inspection/switchExpressionBackwardMigration/beforeSwitchOldStyle.java b/java/java-tests/testData/inspection/switchExpressionBackwardMigration/beforeSwitchOldStyle.java new file mode 100644 index 000000000000..0af635869d83 --- /dev/null +++ b/java/java-tests/testData/inspection/switchExpressionBackwardMigration/beforeSwitchOldStyle.java @@ -0,0 +1,13 @@ +// "Replace with old style 'switch' statement" "false" +import java.util.*; + +class SwitchExpressionMigration { + int foo(int n) { + return switch (n) { + case 1: + break 1; + default: + break 0; + }; + } +} \ No newline at end of file