From a961fa6ae83a864f2d3eb4e1afde410b4d7c1650 Mon Sep 17 00:00:00 2001 From: Nikita Eshkeev Date: Wed, 30 Jun 2021 19:48:26 +0000 Subject: [PATCH] [property tests] IDEA-271659 Property test for pattern matching for switch Add a new action on file for invoking IfCanBeSwitchInspection GitOrigin-RevId: 0673fca2d4583e6909ecab6716a998c257785f99 --- .../IfCanBeSwitchActionOnFile.java | 23 +++++++++++++++++++ .../JavaCodeInsightSanityTest.java | 8 ++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testSrc/com/intellij/java/propertyBased/IfCanBeSwitchActionOnFile.java diff --git a/java/java-tests/testSrc/com/intellij/java/propertyBased/IfCanBeSwitchActionOnFile.java b/java/java-tests/testSrc/com/intellij/java/propertyBased/IfCanBeSwitchActionOnFile.java new file mode 100644 index 000000000000..127818a265b7 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/java/propertyBased/IfCanBeSwitchActionOnFile.java @@ -0,0 +1,23 @@ +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.java.propertyBased; + +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiIfStatement; +import com.siyeh.InspectionGadgetsBundle; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Function; + +public final class IfCanBeSwitchActionOnFile extends InvokeIntentionAtElement { + + public IfCanBeSwitchActionOnFile(@NotNull PsiFile file) { + super(file, new IfCanBeSwitchPolicy(), PsiIfStatement.class, Function.identity()); + } + + private static final class IfCanBeSwitchPolicy extends JavaIntentionPolicy { + @Override + protected boolean shouldSkipIntention(@NotNull String actionText) { + return !actionText.equals(InspectionGadgetsBundle.message("if.can.be.switch.problem.descriptor")); + } + } +} diff --git a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java index 11afa5066208..377692f31c99 100644 --- a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java +++ b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.propertyBased; import com.intellij.application.options.CodeStyle; @@ -55,7 +55,7 @@ public class JavaCodeInsightSanityTest extends LightJavaCodeInsightFixtureTestCa @Override protected @NotNull LightProjectDescriptor getProjectDescriptor() { - return JAVA_15; + return JAVA_17; } public void testRandomActivity() { @@ -65,7 +65,9 @@ public class JavaCodeInsightSanityTest extends LightJavaCodeInsightFixtureTestCa new InvokeCompletion(file, new JavaCompletionPolicy()), new StripTestDataMarkup(file), new DeleteRange(file), - new IntroduceVariableActionOnFile(file)); + new IntroduceVariableActionOnFile(file), + new IfCanBeSwitchActionOnFile(file) + ); PropertyChecker .checkScenarios(actionsOnJavaFiles(fileActions)); }