Search in sources :

Example 1 with SuppressIntentionAction

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

the class SuppressableInspectionTreeNode method getOnlyAvailableSuppressActions.

@NotNull
private Set<SuppressIntentionAction> getOnlyAvailableSuppressActions(@NotNull Project project) {
    final Set<SuppressIntentionAction> actions = getSuppressActions();
    if (actions.isEmpty()) {
        return Collections.emptySet();
    }
    final Pair<PsiElement, CommonProblemDescriptor> suppress = getSuppressContent();
    final PsiElement suppressElement = suppress.getFirst();
    if (suppressElement == null) {
        return actions;
    }
    Set<SuppressIntentionAction> availableActions = null;
    for (SuppressIntentionAction action : actions) {
        if (action.isAvailable(project, null, suppressElement)) {
            if (availableActions == null) {
                availableActions = ContainerUtil.newConcurrentSet(TObjectHashingStrategy.IDENTITY);
            }
            availableActions.add(action);
        }
    }
    return availableActions == null ? Collections.emptySet() : availableActions;
}
Also used : CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) SuppressIntentionAction(com.intellij.codeInspection.SuppressIntentionAction) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SuppressIntentionAction

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

the class SuppressActionWrapper method getChildren.

@Override
@NotNull
public AnAction[] getChildren(@Nullable final AnActionEvent e) {
    final InspectionResultsView view = getView(e);
    if (view == null)
        return AnAction.EMPTY_ARRAY;
    final InspectionToolWrapper wrapper = view.getTree().getSelectedToolWrapper(true);
    if (wrapper == null)
        return AnAction.EMPTY_ARRAY;
    final Set<SuppressIntentionAction> suppressActions = view.getSuppressActions(wrapper);
    if (suppressActions.isEmpty())
        return AnAction.EMPTY_ARRAY;
    final AnAction[] actions = new AnAction[suppressActions.size() + 1];
    int i = 0;
    for (SuppressIntentionAction action : suppressActions) {
        actions[i++] = new SuppressTreeAction(action);
    }
    actions[suppressActions.size()] = Separator.getInstance();
    Arrays.sort(actions, new Comparator<AnAction>() {

        @Override
        public int compare(AnAction a1, AnAction a2) {
            return getWeight(a1) - getWeight(a2);
        }

        public int getWeight(AnAction a) {
            return a instanceof Separator ? 0 : ((SuppressTreeAction) a).isSuppressAll() ? 1 : -1;
        }
    });
    return actions;
}
Also used : SuppressIntentionAction(com.intellij.codeInspection.SuppressIntentionAction) InspectionResultsView(com.intellij.codeInspection.ui.InspectionResultsView) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SuppressIntentionAction

use of com.intellij.codeInspection.SuppressIntentionAction in project kotlin by JetBrains.

the class AbstractQuickFixTest method findActionWithText.

@Override
protected IntentionAction findActionWithText(String text) {
    IntentionAction intention = super.findActionWithText(text);
    if (intention != null)
        return intention;
    // Support warning suppression
    int caretOffset = myEditor.getCaretModel().getOffset();
    for (HighlightInfo highlight : doHighlighting()) {
        if (highlight.startOffset <= caretOffset && caretOffset <= highlight.endOffset) {
            ProblemGroup group = highlight.getProblemGroup();
            if (group instanceof SuppressableProblemGroup) {
                SuppressableProblemGroup problemGroup = (SuppressableProblemGroup) group;
                PsiElement at = getFile().findElementAt(highlight.getActualStartOffset());
                SuppressIntentionAction[] actions = problemGroup.getSuppressActions(at);
                for (SuppressIntentionAction action : actions) {
                    if (action.getText().equals(text)) {
                        return action;
                    }
                }
            }
        }
    }
    return null;
}
Also used : SuppressableProblemGroup(com.intellij.codeInspection.SuppressableProblemGroup) SuppressIntentionAction(com.intellij.codeInspection.SuppressIntentionAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) SuppressableProblemGroup(com.intellij.codeInspection.SuppressableProblemGroup) ProblemGroup(com.intellij.lang.annotation.ProblemGroup) SuppressIntentionAction(com.intellij.codeInspection.SuppressIntentionAction) PsiElement(com.intellij.psi.PsiElement)

Aggregations

SuppressIntentionAction (com.intellij.codeInspection.SuppressIntentionAction)3 PsiElement (com.intellij.psi.PsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 CommonProblemDescriptor (com.intellij.codeInspection.CommonProblemDescriptor)1 SuppressableProblemGroup (com.intellij.codeInspection.SuppressableProblemGroup)1 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)1 InspectionResultsView (com.intellij.codeInspection.ui.InspectionResultsView)1 ProblemGroup (com.intellij.lang.annotation.ProblemGroup)1