Search in sources :

Example 6 with QuickFixWrapper

use of com.intellij.codeInspection.ex.QuickFixWrapper in project intellij-plugins by JetBrains.

the class CucumberJavaCreateStepTest method doTest.

private void doTest(boolean createAll) {
    CucumberStepsIndex.getInstance(getProject()).reset();
    myFixture.enableInspections(new CucumberStepInspection());
    myFixture.copyDirectoryToProject("createStep/" + getTestName(true), "");
    myFixture.configureByFile("createStep/" + getTestName(true) + "/test.feature");
    myFixture.checkHighlighting(true, false, false);
    final String fixName = createAll ? "Create All" : "Create step";
    final IntentionAction quickFix = ContainerUtil.find(myFixture.getAvailableIntentions(), intentionAction -> intentionAction instanceof QuickFixWrapper && intentionAction.getText().contains(fixName));
    if (quickFix != null) {
        myFixture.launchAction(quickFix);
        VirtualFile expectedFile = myFixture.findFileInTempDir("StepDefs.java");
        myFixture.openFileInEditor(expectedFile);
        myFixture.checkResultByFile("createStep/" + getTestName(true) + "/StepDefs_fixed.txt");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) CucumberStepInspection(org.jetbrains.plugins.cucumber.inspections.CucumberStepInspection) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper)

Example 7 with QuickFixWrapper

use of com.intellij.codeInspection.ex.QuickFixWrapper in project intellij-community by JetBrains.

the class MigrateAssertToMatcherAssertTest method testAll.

public void testAll() {
    myFixture.configureByFile(getTestName(true) + ".java");
    myFixture.enableInspections(new MigrateAssertToMatcherAssertInspection());
    for (IntentionAction wrapper : myFixture.getAllQuickFixes()) {
        if (wrapper instanceof QuickFixWrapper) {
            final LocalQuickFix fix = ((QuickFixWrapper) wrapper).getFix();
            if (fix instanceof MigrateAssertToMatcherAssertInspection.MyQuickFix) {
                myFixture.launchAction(wrapper);
            }
        }
    }
    myFixture.checkResultByFile(getTestName(true) + "_after.java");
}
Also used : MigrateAssertToMatcherAssertInspection(com.intellij.refactoring.typeMigration.inspections.MigrateAssertToMatcherAssertInspection) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper)

Example 8 with QuickFixWrapper

use of com.intellij.codeInspection.ex.QuickFixWrapper in project intellij-community by JetBrains.

the class SuperClassHasFrequentlyUsedInheritorsInspectionTest method doTest.

private void doTest(final Pair<String, Integer>... expectedResults) {
    myFixture.configureByFile(getTestName(false) + ".java");
    myFixture.enableInspections(SuperClassHasFrequentlyUsedInheritorsInspection.class);
    final Set<Pair<String, Integer>> actualSet = new HashSet<Pair<String, Integer>>();
    for (IntentionAction intentionAction : myFixture.getAvailableIntentions()) {
        if (intentionAction instanceof QuickFixWrapper) {
            ChangeSuperClassFix changeSuperClassFix = getQuickFixFromWrapper((QuickFixWrapper) intentionAction);
            if (changeSuperClassFix != null) {
                actualSet.add(Pair.create(changeSuperClassFix.getNewSuperClass().getQualifiedName(), changeSuperClassFix.getPercent()));
            }
        }
    }
    final Set<Pair<String, Integer>> expectedSet = ContainerUtil.newHashSet(expectedResults);
    assertEquals(actualSet, expectedSet);
}
Also used : ChangeSuperClassFix(com.intellij.codeInspection.inheritance.ChangeSuperClassFix) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper) HashSet(com.intellij.util.containers.HashSet) Pair(com.intellij.openapi.util.Pair)

Example 9 with QuickFixWrapper

use of com.intellij.codeInspection.ex.QuickFixWrapper in project intellij-community by JetBrains.

the class AddImportQuickFixTest method doMultiFileAutoImportTest.

private void doMultiFileAutoImportTest(@NotNull String hintPrefix, @Nullable Processor<AutoImportQuickFix> checkQuickfix) {
    myFixture.copyDirectoryToProject(getTestName(true), "");
    myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
    final String entryPoint = "main";
    myFixture.configureByFile(entryPoint + ".py");
    myFixture.checkHighlighting(true, false, false);
    final List<IntentionAction> intentions = myFixture.filterAvailableIntentions(hintPrefix);
    final IntentionAction intention = ContainerUtil.find(intentions, action -> {
        return action instanceof QuickFixWrapper && ((QuickFixWrapper) action).getFix() instanceof AutoImportQuickFix;
    });
    assertNotNull("Auto import quick fix starting with '" + hintPrefix + "' wasn't found", intention);
    final AutoImportQuickFix quickfix = (AutoImportQuickFix) ((QuickFixWrapper) intention).getFix();
    boolean applyFix = true;
    if (checkQuickfix != null) {
        applyFix = checkQuickfix.process(quickfix);
    }
    if (applyFix) {
        myFixture.launchAction(intention);
        myFixture.checkResultByFile(getTestName(true) + "/" + entryPoint + "_after.py", true);
    }
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper) AutoImportQuickFix(com.jetbrains.python.codeInsight.imports.AutoImportQuickFix)

Aggregations

QuickFixWrapper (com.intellij.codeInspection.ex.QuickFixWrapper)9 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)8 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)4 ChangeSuperClassFix (com.intellij.codeInspection.inheritance.ChangeSuperClassFix)2 Pair (com.intellij.openapi.util.Pair)2 HashSet (com.intellij.util.containers.HashSet)2 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 IntentionActionWrapper (com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper)1 IntentionWrapper (com.intellij.codeInspection.IntentionWrapper)1 SuppressIntentionActionFromFix (com.intellij.codeInspection.SuppressIntentionActionFromFix)1 StaticPseudoFunctionalStyleMethodInspection (com.intellij.codeInspection.java18StreamApi.StaticPseudoFunctionalStyleMethodInspection)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 MigrateAssertToMatcherAssertInspection (com.intellij.refactoring.typeMigration.inspections.MigrateAssertToMatcherAssertInspection)1 SpellCheckerQuickFix (com.intellij.spellchecker.quickfixes.SpellCheckerQuickFix)1 AutoImportQuickFix (com.jetbrains.python.codeInsight.imports.AutoImportQuickFix)1 Nullable (org.jetbrains.annotations.Nullable)1 CucumberStepInspection (org.jetbrains.plugins.cucumber.inspections.CucumberStepInspection)1