Search in sources :

Example 1 with PsiElementBaseIntentionAction

use of com.intellij.codeInsight.intention.PsiElementBaseIntentionAction 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

PsiElementBaseIntentionAction (com.intellij.codeInsight.intention.PsiElementBaseIntentionAction)1 SuppressIntentionActionFromFix (com.intellij.codeInspection.SuppressIntentionActionFromFix)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 ThreeState (com.intellij.util.ThreeState)1