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 3a613776b2af..c08d7098670f 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,6 +16,7 @@ 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; @@ -291,6 +292,16 @@ 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)); + } + return result; + } + @Override public boolean hasSubstep(final IntentionActionWithTextCaching action) { return action.getOptionIntentions().size() + action.getOptionErrorFixes().size() > 0; diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 7d48e82d6143..2bd3161e69e7 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -27,6 +27,7 @@ import com.intellij.codeInsight.daemon.impl.*; import com.intellij.codeInsight.folding.CodeFoldingManager; import com.intellij.codeInsight.highlighting.actions.HighlightUsagesAction; import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.codeInsight.intention.impl.IntentionListStep; import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler; import com.intellij.codeInsight.lookup.Lookup; import com.intellij.codeInsight.lookup.LookupElement; @@ -296,56 +297,26 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig private static List doGetAvailableIntentions(@NotNull Editor editor, @NotNull PsiFile file) { ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo(); ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1); - List descriptors = new ArrayList(); - descriptors.addAll(intentions.intentionsToShow); - descriptors.addAll(intentions.errorFixesToShow); - descriptors.addAll(intentions.inspectionFixesToShow); - descriptors.addAll(intentions.guttersToShow); - - final int fileOffset = editor.getCaretModel().getOffset(); - PsiElement hostElement = file.getViewProvider().findElementAt(fileOffset, file.getLanguage()); - PsiElement injectedElement = InjectedLanguageUtil.findElementAtNoCommit(file, fileOffset); - - PsiFile injectedFile = injectedElement != null ? injectedElement.getContainingFile() : null; - Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile); List result = new ArrayList(); + IntentionListStep intentionListStep = new IntentionListStep(null, intentions, editor, file, file.getProject()); + for (Map.Entry> entry : intentionListStep.getActionsWithSubActions().entrySet()) { + result.add(entry.getKey()); + result.addAll(entry.getValue()); + } List infos = DaemonCodeAnalyzerEx.getInstanceEx(file.getProject()).getFileLevelHighlights(file.getProject(), file); for (HighlightInfo info : infos) { for (Pair pair : info.quickFixActionRanges) { HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first; - final IntentionAction action = actionInGroup.getAction(); - - if (ShowIntentionActionsHandler.availableFor(file, editor, action) - || - injectedElement != null && hostElement != injectedElement && ShowIntentionActionsHandler.availableFor(injectedFile, injectedEditor, action)) { - descriptors.add(actionInGroup); - } - } - } - - // add all intention options for simplicity - for (HighlightInfo.IntentionActionDescriptor descriptor : descriptors) { - result.add(descriptor.getAction()); - - if (injectedElement != null && injectedElement != hostElement) { - List options = descriptor.getOptions(injectedElement, injectedEditor); - if (options != null) { - for (IntentionAction option : options) { - if (ShowIntentionActionsHandler.availableFor(injectedFile, injectedEditor, option)) { - result.add(option); - } - } - } - } - - if (hostElement != null) { - List options = descriptor.getOptions(hostElement, editor); - if (options != null) { - for (IntentionAction option : options) { - if (ShowIntentionActionsHandler.availableFor(file, editor, option)) { - result.add(option); + if (actionInGroup.getAction().isAvailable(file.getProject(), editor, file)) { + result.add(actionInGroup.getAction()); + List options = actionInGroup.getOptions(file, editor); + if (options != null) { + for (IntentionAction subAction : options) { + if (subAction.isAvailable(file.getProject(), editor, file)) { + result.add(subAction); + } } } } @@ -1315,7 +1286,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig PlatformTestCase.synchronizeTempDirVfs(tempDir); myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject()); - configureInspections(LocalInspectionTool.EMPTY_ARRAY, getProject(), Collections.emptyList(), getTestRootDisposable()); + configureInspections(LocalInspectionTool.EMPTY_ARRAY, getProject(), Collections.emptyList(), getTestRootDisposable()); DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject()); daemonCodeAnalyzer.prepareForTest();