From 4ae4833f605e17c7461d326e387cfecf2b62759e Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Fri, 30 Jan 2015 14:43:53 +0300 Subject: [PATCH] Consider injection while retrieving intentions and their options in tests --- .../impl/CodeInsightTestFixtureImpl.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) 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 9f3fbc17f8e8..42f40fbfd265 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -1701,14 +1701,23 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig descriptors.addAll(intentions.inspectionFixesToShow); descriptors.addAll(intentions.guttersToShow); - PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); + 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(); List infos = DaemonCodeAnalyzerEx.getInstanceEx(file.getProject()).getFileLevelHighlights(file.getProject(), file); for (HighlightInfo info : infos) { for (Pair pair : info.quickFixActionRanges) { HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first; - if (actionInGroup.getAction().isAvailable(file.getProject(), editor, file)) { + final IntentionAction action = actionInGroup.getAction(); + + if (ShowIntentionActionsHandler.availableFor(file, editor, action) + || (injectedElement != null && hostElement != injectedElement && ShowIntentionActionsHandler.availableFor(injectedFile, injectedEditor, action))) { descriptors.add(actionInGroup); } } @@ -1717,11 +1726,25 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig // add all intention options for simplicity for (HighlightInfo.IntentionActionDescriptor descriptor : descriptors) { result.add(descriptor.getAction()); - List options = descriptor.getOptions(element,editor); - if (options != null) { - for (IntentionAction option : options) { - if (option.isAvailable(file.getProject(), editor, file)) { - result.add(option); + + 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); + } } } }