Search in sources :

Example 1 with QuickFixWrapper

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

the class PyTestCase method findQuickFixByClassInIntentions.

/**
   * Searches for quickfix itetion by its class
   *
   * @param clazz quick fix class
   * @param <T>   quick fix class
   * @return quick fix or null if nothing found
   */
@Nullable
public <T extends LocalQuickFix> T findQuickFixByClassInIntentions(@NotNull final Class<T> clazz) {
    for (final IntentionAction action : myFixture.getAvailableIntentions()) {
        if ((action instanceof QuickFixWrapper)) {
            final QuickFixWrapper quickFixWrapper = (QuickFixWrapper) action;
            final LocalQuickFix fix = quickFixWrapper.getFix();
            if (clazz.isInstance(fix)) {
                @SuppressWarnings("unchecked") final T result = (T) fix;
                return result;
            }
        }
    }
    return null;
}
Also used : IntentionAction(com.intellij.codeInsight.intention.IntentionAction) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with QuickFixWrapper

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

the class SpellingPopupActionGroup method extractActions.

private static void extractActions(List<HighlightInfo.IntentionActionDescriptor> descriptors, Map<Anchor, List<AnAction>> actions) {
    for (HighlightInfo.IntentionActionDescriptor actionDescriptor : descriptors) {
        IntentionAction action = actionDescriptor.getAction();
        if (action instanceof QuickFixWrapper) {
            QuickFixWrapper wrapper = (QuickFixWrapper) action;
            LocalQuickFix localQuickFix = wrapper.getFix();
            if (localQuickFix instanceof SpellCheckerQuickFix) {
                SpellCheckerQuickFix spellCheckerQuickFix = (SpellCheckerQuickFix) localQuickFix;
                Anchor anchor = spellCheckerQuickFix.getPopupActionAnchor();
                SpellCheckerIntentionAction popupAction = new SpellCheckerIntentionAction(action);
                List<AnAction> list = actions.get(anchor);
                if (list != null) {
                    list.add(popupAction);
                }
            }
        }
    }
}
Also used : SpellCheckerQuickFix(com.intellij.spellchecker.quickfixes.SpellCheckerQuickFix) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper)

Example 3 with QuickFixWrapper

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

the class StaticPseudoFunctionalStyleMethodTest method doTest.

private void doTest() {
    myFixture.configureByFile(getTestName(true) + "/test.java");
    myFixture.enableInspections(new StaticPseudoFunctionalStyleMethodInspection());
    boolean isQuickFixFound = false;
    for (IntentionAction action : myFixture.getAvailableIntentions()) {
        if (action instanceof QuickFixWrapper) {
            final LocalQuickFix fix = ((QuickFixWrapper) action).getFix();
            if (fix instanceof StaticPseudoFunctionalStyleMethodInspection.ReplacePseudoLambdaWithLambda) {
                myFixture.launchAction(action);
                isQuickFixFound = true;
                break;
            }
        }
    }
    assertTrue("Quick fix isn't found", isQuickFixFound);
    myFixture.checkResultByFile(getTestName(true) + "/test_after.java");
}
Also used : StaticPseudoFunctionalStyleMethodInspection(com.intellij.codeInspection.java18StreamApi.StaticPseudoFunctionalStyleMethodInspection) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper)

Example 4 with QuickFixWrapper

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

the class SuperClassHasFrequentlyUsedInheritorsInspectionTest method doTest.

private void doTest(final int expectedSize) {
    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()));
            }
        }
    }
    assertSize(expectedSize, actualSet);
}
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 5 with QuickFixWrapper

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

the class IntentionListStep method getWeight.

private int getWeight(IntentionActionWithTextCaching action) {
    IntentionAction a = action.getAction();
    int group = getGroup(action);
    if (a instanceof IntentionActionWrapper) {
        a = ((IntentionActionWrapper) a).getDelegate();
    }
    if (a instanceof IntentionWrapper) {
        a = ((IntentionWrapper) a).getAction();
    }
    if (a instanceof HighPriorityAction) {
        return group + 3;
    }
    if (a instanceof LowPriorityAction) {
        return group - 3;
    }
    if (a instanceof SuppressIntentionActionFromFix) {
        if (((SuppressIntentionActionFromFix) a).isShouldBeAppliedToInjectionHost() == ThreeState.NO) {
            return group - 1;
        }
    }
    if (a instanceof QuickFixWrapper) {
        final LocalQuickFix quickFix = ((QuickFixWrapper) a).getFix();
        if (quickFix instanceof HighPriorityAction) {
            return group + 3;
        }
        if (quickFix instanceof LowPriorityAction) {
            return group - 3;
        }
    }
    return group;
}
Also used : SuppressIntentionActionFromFix(com.intellij.codeInspection.SuppressIntentionActionFromFix) IntentionWrapper(com.intellij.codeInspection.IntentionWrapper) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) IntentionActionWrapper(com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper)

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