From 99f5e2bde99dd250a5e3495736b8482e53124e11 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 18 Nov 2016 15:13:11 +0300 Subject: [PATCH] call isAvailable() for DO_NOT_SHOW fixes in tests --- .../intention/impl/IntentionListStep.java | 43 +++++++++++-------- .../impl/ShowIntentionActionsHandler.java | 11 ++++- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java index dc5b215b045e..08b781cb3197 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java @@ -16,7 +16,6 @@ package com.intellij.codeInsight.intention.impl; -import com.google.common.annotations.VisibleForTesting; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.daemon.impl.ShowIntentionsPass; import com.intellij.codeInsight.hint.HintManager; @@ -43,9 +42,11 @@ import gnu.trove.THashSet; import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import javax.swing.*; import java.util.*; +import java.util.stream.Collectors; /** * @author cdr @@ -53,10 +54,8 @@ import java.util.*; public class IntentionListStep implements ListPopupStep, SpeedSearchFilter { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.IntentionListStep"); - private final Set myCachedIntentions = - ContainerUtil.newConcurrentSet(ACTION_TEXT_AND_CLASS_EQUALS); - private final Set myCachedErrorFixes = - ContainerUtil.newConcurrentSet(ACTION_TEXT_AND_CLASS_EQUALS); + private final Set myCachedIntentions = ContainerUtil.newConcurrentSet(ACTION_TEXT_AND_CLASS_EQUALS); + private final Set myCachedErrorFixes = ContainerUtil.newConcurrentSet(ACTION_TEXT_AND_CLASS_EQUALS); private final Set myCachedInspectionFixes = ContainerUtil.newConcurrentSet(ACTION_TEXT_AND_CLASS_EQUALS); private final Set myCachedGutters = ContainerUtil.newConcurrentSet(ACTION_TEXT_AND_CLASS_EQUALS); private final Set myCachedNotifications = ContainerUtil.newConcurrentSet(ACTION_TEXT_AND_CLASS_EQUALS); @@ -81,10 +80,10 @@ public class IntentionListStep implements ListPopupStep> getActionsWithSubActions() { Map> result = ContainerUtil.newLinkedHashMap(); - for (IntentionActionWithTextCaching action : getValues()) { - List subActions = getSubStep(action, action.getToolName()).getValues(); - result.put(action.getAction(), ContainerUtil.map(subActions, IntentionActionWithTextCaching::getAction)); + + for (IntentionActionWithTextCaching cached : getValues()) { + IntentionAction action = cached.getAction(); + if (ShowIntentionActionsHandler.chooseFileForAction(myFile, myEditor, action) == null) continue; + + List subActions = getSubStep(cached, cached.getToolName()).getValues(); + List options = subActions.stream() + .map(IntentionActionWithTextCaching::getAction) + .filter(option -> ShowIntentionActionsHandler.chooseFileForAction(myFile, myEditor, option) != null) + .collect(Collectors.toList()); + result.put(action, options); } return result; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java index 6c63d2332fe7..9924badcc318 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java @@ -178,8 +178,7 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler { FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.quickFix"); ((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getFixesStats().registerInvocation(); - final Pair pair = hostEditor != null ? chooseBetweenHostAndInjected(hostFile, hostEditor, - (psiFile, editor) -> availableFor(psiFile, editor, action)) : Pair.create(hostFile, null); + final Pair pair = chooseFileForAction(hostFile, hostEditor, action); if (pair == null) return false; CommandProcessor.getInstance().executeCommand(project, () -> TransactionGuard.getInstance().submitTransactionAndWait(() -> { @@ -200,4 +199,12 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler { }), text, null); return true; } + + + static Pair chooseFileForAction(@NotNull PsiFile hostFile, + @Nullable Editor hostEditor, + @NotNull IntentionAction action) { + return hostEditor == null ? Pair.create(hostFile, null) : + chooseBetweenHostAndInjected(hostFile, hostEditor, (psiFile, editor) -> availableFor(psiFile, editor, action)); + } }