Search in sources :

Example 1 with IntentionListStep

use of com.intellij.codeInsight.intention.impl.IntentionListStep in project intellij-community by JetBrains.

the class CodeInsightTestFixtureImpl method doGetAvailableIntentions.

@NotNull
private static List<IntentionAction> doGetAvailableIntentions(@NotNull Editor editor, @NotNull PsiFile file) {
    ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
    ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);
    List<IntentionAction> result = new ArrayList<>();
    IntentionListStep intentionListStep = new IntentionListStep(null, intentions, editor, file, file.getProject());
    for (Map.Entry<IntentionAction, List<IntentionAction>> entry : intentionListStep.getActionsWithSubActions().entrySet()) {
        result.add(entry.getKey());
        result.addAll(entry.getValue());
    }
    List<HighlightInfo> infos = DaemonCodeAnalyzerEx.getInstanceEx(file.getProject()).getFileLevelHighlights(file.getProject(), file);
    for (HighlightInfo info : infos) {
        for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
            HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
            if (actionInGroup.getAction().isAvailable(file.getProject(), editor, file)) {
                result.add(actionInGroup.getAction());
                List<IntentionAction> options = actionInGroup.getOptions(file, editor);
                if (options != null) {
                    for (IntentionAction subAction : options) {
                        if (subAction.isAvailable(file.getProject(), editor, file)) {
                            result.add(subAction);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : IntentionListStep(com.intellij.codeInsight.intention.impl.IntentionListStep) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with IntentionListStep

use of com.intellij.codeInsight.intention.impl.IntentionListStep in project intellij-community by JetBrains.

the class ResourceBundleEditorShowQuickFixesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ResourceBundleEditor editor = getEditor(e);
    LOG.assertTrue(editor != null);
    final ResourceBundlePropertyStructureViewElement element = (ResourceBundlePropertyStructureViewElement) editor.getSelectedElementIfOnlyOne();
    LOG.assertTrue(element != null);
    final PsiFile file = editor.getResourceBundle().getDefaultPropertiesFile().getContainingFile();
    final ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
    boolean isQuickFixListEmpty = true;
    Pair<ResourceBundleEditorProblemDescriptor, HighlightDisplayKey>[] descriptorsAndSources = element.getProblemDescriptors();
    for (Pair<ResourceBundleEditorProblemDescriptor, HighlightDisplayKey> p : descriptorsAndSources) {
        final ResourceBundleEditorProblemDescriptor d = p.getFirst();
        final HighlightDisplayKey sourceKey = p.getSecond();
        QuickFix[] fixes = d.getFixes();
        if (fixes != null) {
            for (int i = 0; i < fixes.length; i++) {
                intentions.inspectionFixesToShow.add(new HighlightInfo.IntentionActionDescriptor(new RBEQuickFixWrapper(d, i), null, null, AllIcons.Actions.IntentionBulb, sourceKey, null, null));
                isQuickFixListEmpty = false;
            }
        }
    }
    if (isQuickFixListEmpty) {
        return;
    }
    final Project project = e.getProject();
    LOG.assertTrue(project != null);
    JBPopupFactory.getInstance().createListPopup(new IntentionListStep(null, intentions, null, file, project)).showInBestPositionFor(e.getDataContext());
}
Also used : QuickFix(com.intellij.codeInspection.QuickFix) IntentionListStep(com.intellij.codeInsight.intention.impl.IntentionListStep) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) ResourceBundleEditorProblemDescriptor(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) Project(com.intellij.openapi.project.Project) ShowIntentionsPass(com.intellij.codeInsight.daemon.impl.ShowIntentionsPass) PsiFile(com.intellij.psi.PsiFile) Pair(com.intellij.openapi.util.Pair)

Aggregations

IntentionListStep (com.intellij.codeInsight.intention.impl.IntentionListStep)2 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)1 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 ShowIntentionsPass (com.intellij.codeInsight.daemon.impl.ShowIntentionsPass)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 QuickFix (com.intellij.codeInspection.QuickFix)1 ResourceBundleEditorProblemDescriptor (com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor)1 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 PsiFile (com.intellij.psi.PsiFile)1 NotNull (org.jetbrains.annotations.NotNull)1