Search in sources :

Example 1 with SuppressIntentionActionFromFix

use of com.intellij.codeInspection.SuppressIntentionActionFromFix 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)

Example 2 with SuppressIntentionActionFromFix

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

the class IntentionHintComponent method recreateMyPopup.

private void recreateMyPopup(@NotNull ListPopupStep step) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (myPopup != null) {
        Disposer.dispose(myPopup);
    }
    myPopup = JBPopupFactory.getInstance().createListPopup(step);
    if (myPopup instanceof WizardPopup) {
        Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_INTENTION_ACTIONS);
        for (Shortcut shortcut : shortcuts) {
            if (shortcut instanceof KeyboardShortcut) {
                KeyboardShortcut keyboardShortcut = (KeyboardShortcut) shortcut;
                if (keyboardShortcut.getSecondKeyStroke() == null) {
                    ((WizardPopup) myPopup).registerAction("activateSelectedElement", keyboardShortcut.getFirstKeyStroke(), new AbstractAction() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            myPopup.handleSelect(true);
                        }
                    });
                }
            }
        }
    }
    boolean committed = PsiDocumentManager.getInstance(myFile.getProject()).isCommitted(myEditor.getDocument());
    final PsiFile injectedFile = committed ? InjectedLanguageUtil.findInjectedPsiNoCommit(myFile, myEditor.getCaretModel().getOffset()) : null;
    final Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(myEditor, injectedFile);
    final ScopeHighlighter highlighter = new ScopeHighlighter(myEditor);
    final ScopeHighlighter injectionHighlighter = new ScopeHighlighter(injectedEditor);
    myPopup.addListener(new JBPopupListener.Adapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            highlighter.dropHighlight();
            injectionHighlighter.dropHighlight();
            myPopupShown = false;
        }
    });
    myPopup.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(@NotNull ListSelectionEvent e) {
            final Object source = e.getSource();
            highlighter.dropHighlight();
            injectionHighlighter.dropHighlight();
            if (source instanceof DataProvider) {
                final Object selectedItem = PlatformDataKeys.SELECTED_ITEM.getData((DataProvider) source);
                if (selectedItem instanceof IntentionActionWithTextCaching) {
                    final IntentionAction action = ((IntentionActionWithTextCaching) selectedItem).getAction();
                    if (action instanceof SuppressIntentionActionFromFix) {
                        if (injectedFile != null && ((SuppressIntentionActionFromFix) action).isShouldBeAppliedToInjectionHost() == ThreeState.NO) {
                            final PsiElement at = injectedFile.findElementAt(injectedEditor.getCaretModel().getOffset());
                            final PsiElement container = ((SuppressIntentionActionFromFix) action).getContainer(at);
                            if (container != null) {
                                injectionHighlighter.highlight(container, Collections.singletonList(container));
                            }
                        } else {
                            final PsiElement at = myFile.findElementAt(myEditor.getCaretModel().getOffset());
                            final PsiElement container = ((SuppressIntentionActionFromFix) action).getContainer(at);
                            if (container != null) {
                                highlighter.highlight(container, Collections.singletonList(container));
                            }
                        }
                    }
                }
            }
        }
    });
    if (myEditor.isOneLineMode()) {
        // hide popup on combobox popup show
        final Container ancestor = SwingUtilities.getAncestorOfClass(JComboBox.class, myEditor.getContentComponent());
        if (ancestor != null) {
            final JComboBox comboBox = (JComboBox) ancestor;
            myOuterComboboxPopupListener = new PopupMenuListenerAdapter() {

                @Override
                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    hide();
                }
            };
            comboBox.addPopupMenuListener(myOuterComboboxPopupListener);
        }
    }
    Disposer.register(this, myPopup);
    Disposer.register(myPopup, new Disposable() {

        @Override
        public void dispose() {
            ApplicationManager.getApplication().assertIsDispatchThread();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) PopupMenuEvent(javax.swing.event.PopupMenuEvent) PsiFile(com.intellij.psi.PsiFile) ScopeHighlighter(com.intellij.codeInsight.unwrap.ScopeHighlighter) PsiElement(com.intellij.psi.PsiElement) Disposable(com.intellij.openapi.Disposable) SuppressIntentionActionFromFix(com.intellij.codeInspection.SuppressIntentionActionFromFix) PopupMenuListenerAdapter(com.intellij.ui.PopupMenuListenerAdapter) WizardPopup(com.intellij.ui.popup.WizardPopup) ListSelectionListener(javax.swing.event.ListSelectionListener) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) BaseRefactoringIntentionAction(com.intellij.refactoring.BaseRefactoringIntentionAction) Editor(com.intellij.openapi.editor.Editor)

Example 3 with SuppressIntentionActionFromFix

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

the class ShowIntentionActionsHandler method availableFor.

public static boolean availableFor(@NotNull PsiFile psiFile, @NotNull Editor editor, @NotNull IntentionAction action) {
    if (!psiFile.isValid())
        return false;
    int offset = editor.getCaretModel().getOffset();
    PsiElement psiElement = psiFile.findElementAt(offset);
    boolean inProject = psiFile.getManager().isInProject(psiFile);
    try {
        Project project = psiFile.getProject();
        if (action instanceof SuppressIntentionActionFromFix) {
            final ThreeState shouldBeAppliedToInjectionHost = ((SuppressIntentionActionFromFix) action).isShouldBeAppliedToInjectionHost();
            if (editor instanceof EditorWindow && shouldBeAppliedToInjectionHost == ThreeState.YES) {
                return false;
            }
            if (!(editor instanceof EditorWindow) && shouldBeAppliedToInjectionHost == ThreeState.NO) {
                return false;
            }
        }
        if (action instanceof PsiElementBaseIntentionAction) {
            if (!inProject || psiElement == null || !((PsiElementBaseIntentionAction) action).isAvailable(project, editor, psiElement))
                return false;
        } else if (!action.isAvailable(project, editor, psiFile)) {
            return false;
        }
    } catch (IndexNotReadyException e) {
        return false;
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) SuppressIntentionActionFromFix(com.intellij.codeInspection.SuppressIntentionActionFromFix) ThreeState(com.intellij.util.ThreeState) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiElementBaseIntentionAction(com.intellij.codeInsight.intention.PsiElementBaseIntentionAction) PsiElement(com.intellij.psi.PsiElement) EditorWindow(com.intellij.injected.editor.EditorWindow)

Aggregations

SuppressIntentionActionFromFix (com.intellij.codeInspection.SuppressIntentionActionFromFix)3 PsiElement (com.intellij.psi.PsiElement)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 PsiElementBaseIntentionAction (com.intellij.codeInsight.intention.PsiElementBaseIntentionAction)1 IntentionActionWrapper (com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper)1 ScopeHighlighter (com.intellij.codeInsight.unwrap.ScopeHighlighter)1 IntentionWrapper (com.intellij.codeInspection.IntentionWrapper)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 QuickFixWrapper (com.intellij.codeInspection.ex.QuickFixWrapper)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 Disposable (com.intellij.openapi.Disposable)1 Editor (com.intellij.openapi.editor.Editor)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Project (com.intellij.openapi.project.Project)1 PsiFile (com.intellij.psi.PsiFile)1 BaseRefactoringIntentionAction (com.intellij.refactoring.BaseRefactoringIntentionAction)1 PopupMenuListenerAdapter (com.intellij.ui.PopupMenuListenerAdapter)1 WizardPopup (com.intellij.ui.popup.WizardPopup)1 ThreeState (com.intellij.util.ThreeState)1 ActionEvent (java.awt.event.ActionEvent)1