From 08d46f1cfd79573c941af798dd3384f830915ff4 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 27 Aug 2013 13:36:27 +0400 Subject: [PATCH] highlightVisitor moves and cleanup --- .../codeInspection/SuppressManagerImpl.java | 3 +- .../daemon/impl/GeneralHighlightingPass.java | 8 +- .../daemon/impl/HighlightInfo.java | 54 ++++++-- .../daemon/impl/LocalInspectionsPass.java | 2 +- .../daemon/impl/ShowIntentionsPass.java | 63 +++++++++- .../daemon/impl/UpdateHighlightersUtil.java | 4 +- .../daemon/impl/quickfix/QuickFixAction.java | 118 ++---------------- .../quickfix/QuickFixActionRegistrarImpl.java | 2 +- .../SuppressIntentionActionFromFix.java | 68 ++++++++++ .../GrUnresolvedAccessInspection.java | 2 +- .../actions/SpellingPopupActionGroup.java | 4 +- 11 files changed, 193 insertions(+), 135 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java diff --git a/java/java-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java b/java/java-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java index 18ba50a4675f..c67f925d6c09 100644 --- a/java/java-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java @@ -21,7 +21,6 @@ package com.intellij.codeInspection; import com.intellij.codeInsight.daemon.HighlightDisplayKey; -import com.intellij.codeInspection.ex.InspectionManagerEx; import com.intellij.psi.PsiDocCommentOwner; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiModifierListOwner; @@ -45,7 +44,7 @@ public class SuppressManagerImpl extends SuppressManager { return ContainerUtil.map2Array(actions, SuppressIntentionAction.class, new Function() { @Override public SuppressIntentionAction fun(SuppressQuickFix fix) { - return InspectionManagerEx.convertBatchToSuppressIntentionAction(fix); + return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction(fix); } }); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java index f704286cdc21..013db8f5c931 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java @@ -120,7 +120,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP boolean updateAll) { this(project, file, document, startOffset, endOffset, updateAll, new ProperTextRange(0,document.getTextLength()), null); } - public GeneralHighlightingPass(@NotNull Project project, + GeneralHighlightingPass(@NotNull Project project, @NotNull PsiFile file, @NotNull Document document, int startOffset, @@ -385,9 +385,9 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP final TextRange fixedTextRange = getFixedTextRange(documentWindow, startOffset); addPatchedInfos(info, injectedPsi, documentWindow, injectedLanguageManager, fixedTextRange, outInfos); } - holder.clear(); + int injectedStart = holder.size(); highlightInjectedSyntax(injectedPsi, holder); - for (int i = 0; i < holder.size(); i++) { + for (int i = injectedStart; i < holder.size(); i++) { HighlightInfo info = holder.get(i); final int startOffset = info.startOffset; final TextRange fixedTextRange = getFixedTextRange(documentWindow, startOffset); @@ -523,7 +523,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP } } - private void highlightInjectedSyntax(final PsiFile injectedPsi, HighlightInfoHolder holder) { + private void highlightInjectedSyntax(@NotNull PsiFile injectedPsi, @NotNull HighlightInfoHolder holder) { List, TextRange>> tokens = InjectedLanguageUtil .getHighlightTokens(injectedPsi); if (tokens == null) return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java index 1c6166657bef..5ce6e13e5a95 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java @@ -17,7 +17,6 @@ package com.intellij.codeInsight.daemon.impl; import com.intellij.codeInsight.daemon.HighlightDisplayKey; -import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.intention.IntentionManager; import com.intellij.codeInspection.*; @@ -36,10 +35,7 @@ import com.intellij.openapi.editor.ex.RangeHighlighterEx; import com.intellij.openapi.editor.markup.GutterIconRenderer; import com.intellij.codeInsight.daemon.GutterMark; import com.intellij.openapi.editor.markup.TextAttributes; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.Segment; -import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.psi.PsiElement; @@ -55,6 +51,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.Iterator; import java.util.List; public class HighlightInfo implements Segment { @@ -73,8 +70,8 @@ public class HighlightInfo implements Segment { public final int startOffset; public final int endOffset; - public int fixStartOffset; - public int fixEndOffset; + private int fixStartOffset; + private int fixEndOffset; RangeMarker fixMarker; // null means it the same as highlighter private final String description; @@ -84,7 +81,7 @@ public class HighlightInfo implements Segment { final int navigationShift; - RangeHighlighterEx highlighter; + volatile RangeHighlighterEx highlighter; // modified in EDT only public List> quickFixActionRanges; public List> quickFixActionMarkers; @@ -100,6 +97,11 @@ public class HighlightInfo implements Segment { private static final int FILE_LEVEL_ANNOTATION_FLAG = 4; private static final int NEEDS_UPDATE_ON_TYPING_FLAG = 5; + @NotNull + ProperTextRange getFixTextRange() { + return new ProperTextRange(fixStartOffset, fixEndOffset); + } + public void setFromInjection(boolean fromInjection) { setFlag(FROM_INJECTION_FLAG, fromInjection); } @@ -652,14 +654,16 @@ public class HighlightInfo implements Segment { return info; } + public static final String ANNOTATOR_INSPECTION_SHORT_NAME = "Annotator"; + private static void appendFixes(@Nullable TextRange fixedRange, @NotNull HighlightInfo info, List fixes) { if (fixes != null) { for (final Annotation.QuickFixInfo quickFixInfo : fixes) { TextRange range = fixedRange != null ? fixedRange : quickFixInfo.textRange; HighlightDisplayKey key = quickFixInfo.key != null ? quickFixInfo.key - : HighlightDisplayKey.find(DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection.ANNOTATOR_SHORT_NAME); - QuickFixAction.registerQuickFixAction(info, range, quickFixInfo.quickFix, key); + : HighlightDisplayKey.find(ANNOTATOR_INSPECTION_SHORT_NAME); + info.registerFix(quickFixInfo.quickFix, null, HighlightDisplayKey.getDisplayNameByKey(key), range, key); } } } @@ -821,7 +825,7 @@ public class HighlightInfo implements Segment { ContainerUtil.addAll(newOptions, ContainerUtil.map(suppressActions, new Function() { @Override public IntentionAction fun(SuppressQuickFix fix) { - return InspectionManagerEx.convertBatchToSuppressIntentionAction(fix); + return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction(fix); } })); } @@ -888,4 +892,32 @@ public class HighlightInfo implements Segment { if (!highlighter.isValid()) return ""; return highlighter.getDocument().getText(TextRange.create(highlighter)); } + + public void registerFix(@Nullable IntentionAction action, + @Nullable List options, + @Nullable String displayName, + @Nullable TextRange fixRange, + @Nullable HighlightDisplayKey key) { + if (action == null) return; + if (fixRange == null) fixRange = new TextRange(startOffset, endOffset); + if (quickFixActionRanges == null) { + quickFixActionRanges = ContainerUtil.createLockFreeCopyOnWriteList(); + } + IntentionActionDescriptor desc = new IntentionActionDescriptor(action, options, displayName, null, key, getProblemGroup()); + quickFixActionRanges.add(Pair.create(desc, fixRange)); + fixStartOffset = Math.min (fixStartOffset, fixRange.getStartOffset()); + fixEndOffset = Math.max (fixEndOffset, fixRange.getEndOffset()); + if (action instanceof HintAction) { + setHint(true); + } + } + + public void unregisterQuickFix(@NotNull Condition condition) { + for (Iterator> it = quickFixActionRanges.iterator(); it.hasNext();) { + Pair pair = it.next(); + if (condition.value(pair.first.getAction())) { + it.remove(); + } + } + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java index 9cc91a372649..2470e0dd0748 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java @@ -681,7 +681,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass if (((ProblemDescriptorBase)descriptor).getEnforcedTextAttributes() != null) { needEmptyAction = false; } - if (needEmptyAction && emptyActionRegistered.add(Pair.create(new TextRange(highlightInfo.fixStartOffset, highlightInfo.fixEndOffset), tool.getShortName()))) { + if (needEmptyAction && emptyActionRegistered.add(Pair.create(highlightInfo.getFixTextRange(), tool.getShortName()))) { EmptyIntentionAction emptyIntentionAction = new EmptyIntentionAction(tool.getDisplayName()); QuickFixAction.registerQuickFixAction(highlightInfo, emptyIntentionAction, key); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java index e30b8e0acd15..6484893c6dcb 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ShowIntentionsPass.java @@ -18,7 +18,6 @@ package com.intellij.codeInsight.daemon.impl; import com.intellij.codeHighlighting.TextEditorHighlightingPass; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; -import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction; import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.intention.AbstractIntentionAction; import com.intellij.codeInsight.intention.IntentionAction; @@ -40,6 +39,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.LogicalPosition; +import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.markup.GutterIconRenderer; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.ProgressIndicator; @@ -50,6 +50,7 @@ import com.intellij.psi.IntentionFilterOwner; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.IncorrectOperationException; import com.intellij.util.PairProcessor; @@ -74,6 +75,62 @@ public class ShowIntentionsPass extends TextEditorHighlightingPass { private volatile boolean myShowBulb; private volatile boolean myHasToRecreate; + @NotNull + public static List getAvailableActions(@NotNull final Editor editor, @NotNull final PsiFile file, final int passId) { + final int offset = editor.getCaretModel().getOffset(); + final Project project = file.getProject(); + + final List result = new ArrayList(); + DaemonCodeAnalyzerImpl.processHighlightsNearOffset(editor.getDocument(), project, HighlightSeverity.INFORMATION, offset, true, new Processor() { + @Override + public boolean process(HighlightInfo info) { + addAvailableActionsForGroups(info, editor, file, result, passId, offset); + return true; + } + }); + return result; + } + + private static void addAvailableActionsForGroups(@NotNull HighlightInfo info, + @NotNull Editor editor, + @NotNull PsiFile file, + @NotNull List outList, + int group, + int offset) { + if (info.quickFixActionMarkers == null) return; + if (group != -1 && group != info.getGroup()) return; + Editor injectedEditor = null; + PsiFile injectedFile = null; + for (Pair pair : info.quickFixActionMarkers) { + HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first; + RangeMarker range = pair.second; + if (!range.isValid()) continue; + int start = range.getStartOffset(); + int end = range.getEndOffset(); + final Project project = file.getProject(); + if (start > offset || offset > end) { + continue; + } + Editor editorToUse; + PsiFile fileToUse; + if (info.isFromInjection()) { + if (injectedEditor == null) { + injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(file, offset); + injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile); + } + editorToUse = injectedEditor; + fileToUse = injectedFile; + } + else { + editorToUse = editor; + fileToUse = file; + } + if (actionInGroup.getAction().isAvailable(project, editorToUse, fileToUse)) { + outList.add(actionInGroup); + } + } + } + public static class IntentionsInfo { public final List intentionsToShow = new ArrayList(); public final List errorFixesToShow = new ArrayList(); @@ -114,7 +171,7 @@ public class ShowIntentionsPass extends TextEditorHighlightingPass { myEditor = editor; PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project); - + myFile = documentManager.getPsiFile(myEditor.getDocument()); assert myFile != null : FileDocumentManager.getInstance().getFile(myEditor.getDocument()); } @@ -202,7 +259,7 @@ public class ShowIntentionsPass extends TextEditorHighlightingPass { int offset = hostEditor.getCaretModel().getOffset(); Project project = hostFile.getProject(); - List fixes = QuickFixAction.getAvailableActions(hostEditor, hostFile, passIdToShowIntentionsFor); + List fixes = getAvailableActions(hostEditor, hostFile, passIdToShowIntentionsFor); final DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(project); final Document hostDocument = hostEditor.getDocument(); HighlightInfo infoAtCursor = ((DaemonCodeAnalyzerImpl)codeAnalyzer).findHighlightByOffset(hostDocument, offset, true); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java index 4e41c37b0883..e2d5df0b12c2 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java @@ -449,11 +449,11 @@ public class UpdateHighlightersUtil { } info.quickFixActionMarkers = ContainerUtil.createLockFreeCopyOnWriteList(list); } - if (finalInfoRange.equalsToRange(info.fixStartOffset, info.fixEndOffset)) { + ProperTextRange fixRange = info.getFixTextRange(); + if (finalInfoRange.equals(fixRange)) { info.fixMarker = null; // null means it the same as highlighter' } else { - TextRange fixRange = new TextRange(info.fixStartOffset, info.fixEndOffset); info.fixMarker = getOrCreate(document, ranges2markersCache, fixRange); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java index 6525bea436df..671f58b27456 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixAction.java @@ -17,25 +17,14 @@ package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.daemon.HighlightDisplayKey; -import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInspection.HintAction; -import com.intellij.lang.annotation.HighlightSeverity; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.RangeMarker; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiFile; -import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; -import com.intellij.util.Processor; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -54,114 +43,27 @@ public final class QuickFixAction { registerQuickFixAction(info, null, action); } - public static void registerQuickFixActions(@Nullable final HighlightInfo info, @NotNull final Collection actions) { - for (IntentionAction action : actions) { - registerQuickFixAction(info, action); - } - } - /** This is used by TeamCity plugin */ @Deprecated - public static void registerQuickFixAction(@Nullable HighlightInfo info, @Nullable IntentionAction action, @Nullable List options, @Nullable String displayName) { - doRegister(info, action, options, displayName, null, null); + public static void registerQuickFixAction(@Nullable HighlightInfo info, + @Nullable IntentionAction action, + @Nullable List options, + @Nullable String displayName) { + if (info == null) return; + info.registerFix(action, options, displayName, null, null); } - private static void doRegister(@Nullable HighlightInfo info, - @Nullable IntentionAction action, - @Nullable List options, - @Nullable String displayName, - @Nullable TextRange fixRange, - @Nullable HighlightDisplayKey key) { - if (info == null || action == null) return; - if (fixRange == null) fixRange = new TextRange(info.startOffset, info.endOffset); - if (info.quickFixActionRanges == null) { - info.quickFixActionRanges = ContainerUtil.createLockFreeCopyOnWriteList(); - } - HighlightInfo.IntentionActionDescriptor desc = new HighlightInfo.IntentionActionDescriptor(action, options, displayName, null, key, info.getProblemGroup()); - info.quickFixActionRanges.add(Pair.create(desc, fixRange)); - info.fixStartOffset = Math.min (info.fixStartOffset, fixRange.getStartOffset()); - info.fixEndOffset = Math.max (info.fixEndOffset, fixRange.getEndOffset()); - if (action instanceof HintAction) { - info.setHint(true); - } - } public static void registerQuickFixAction(@Nullable HighlightInfo info, @Nullable TextRange fixRange, @Nullable IntentionAction action, @Nullable final HighlightDisplayKey key) { - doRegister(info, action, null, HighlightDisplayKey.getDisplayNameByKey(key), fixRange, key); + if (info == null) return; + info.registerFix(action, null, HighlightDisplayKey.getDisplayNameByKey(key), fixRange, key); } public static void registerQuickFixAction(@Nullable HighlightInfo info, @Nullable TextRange fixRange, @Nullable IntentionAction action) { - doRegister(info, action, null, null, fixRange, null); - } - - public static void unregisterQuickFixAction(@NotNull HighlightInfo info, Condition condition) { - for (Iterator> it = info.quickFixActionRanges.iterator(); it.hasNext();) { - Pair pair = it.next(); - if (condition.value(pair.first.getAction())) { - it.remove(); - } - } - } - - /** - * Is invoked inside atomic action. - */ - @NotNull - public static List getAvailableActions(@NotNull final Editor editor, @NotNull final PsiFile file, final int passId) { - final int offset = editor.getCaretModel().getOffset(); - final Project project = file.getProject(); - - final List result = new ArrayList(); - DaemonCodeAnalyzerImpl.processHighlightsNearOffset(editor.getDocument(), project, HighlightSeverity.INFORMATION, offset, true, new Processor() { - @Override - public boolean process(HighlightInfo info) { - addAvailableActionsForGroups(info, editor, file, result, passId, offset); - return true; - } - }); - return result; - } - - private static void addAvailableActionsForGroups(@NotNull HighlightInfo info, - @NotNull Editor editor, - @NotNull PsiFile file, - @NotNull List outList, - int group, - int offset) { - if (info.quickFixActionMarkers == null) return; - if (group != -1 && group != info.getGroup()) return; - Editor injectedEditor = null; - PsiFile injectedFile = null; - for (Pair pair : info.quickFixActionMarkers) { - HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first; - RangeMarker range = pair.second; - if (!range.isValid()) continue; - int start = range.getStartOffset(); - int end = range.getEndOffset(); - final Project project = file.getProject(); - if (start > offset || offset > end) { - continue; - } - Editor editorToUse; - PsiFile fileToUse; - if (info.isFromInjection()) { - if (injectedEditor == null) { - injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(file, offset); - injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile); - } - editorToUse = injectedEditor; - fileToUse = injectedFile; - } - else { - editorToUse = editor; - fileToUse = file; - } - if (actionInGroup.getAction().isAvailable(project, editorToUse, fileToUse)) { - outList.add(actionInGroup); - } - } + if (info == null) return; + info.registerFix(action, null, null, fixRange, null); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixActionRegistrarImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixActionRegistrarImpl.java index 3890dd45bbd2..3a44379f8901 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixActionRegistrarImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/QuickFixActionRegistrarImpl.java @@ -45,7 +45,7 @@ public class QuickFixActionRegistrarImpl implements QuickFixActionRegistrar { @Override public void unregister(@NotNull Condition condition) { if (myInfo != null) { - QuickFixAction.unregisterQuickFixAction(myInfo, condition); + myInfo.unregisterQuickFix(condition); } } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java b/platform/lang-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java new file mode 100644 index 000000000000..d90efd796555 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInspection/SuppressIntentionActionFromFix.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection; + +import com.intellij.codeInsight.daemon.impl.actions.AbstractBatchSuppressByNoInspectionCommentFix; +import com.intellij.codeInspection.*; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; + +public class SuppressIntentionActionFromFix extends SuppressIntentionAction { + private final SuppressQuickFix myFix; + + private SuppressIntentionActionFromFix(@NotNull SuppressQuickFix fix) { + myFix = fix; + } + + @NotNull + public static SuppressIntentionAction convertBatchToSuppressIntentionAction(@NotNull final SuppressQuickFix fix) { + return new SuppressIntentionActionFromFix(fix); + } + + @Override + public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { + PsiElement container = myFix instanceof AbstractBatchSuppressByNoInspectionCommentFix + ? ((AbstractBatchSuppressByNoInspectionCommentFix )myFix).getContainer(element) : null; + boolean caretWasBeforeStatement = editor != null && container != null && editor.getCaretModel().getOffset() == container.getTextRange().getStartOffset(); + InspectionManager inspectionManager = InspectionManager.getInstance(project); + ProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(element, element, "", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false); + myFix.applyFix(project, descriptor); + + if (caretWasBeforeStatement) { + editor.getCaretModel().moveToOffset(container.getTextRange().getStartOffset()); + } + } + + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { + return myFix.isAvailable(project, element); + } + + @NotNull + @Override + public String getText() { + return myFix.getName(); + } + + @NotNull + @Override + public String getFamilyName() { + return myFix.getFamilyName(); + } +} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java index 985632ad27fb..3bc8412fad48 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/untypedUnresolvedAccess/GrUnresolvedAccessInspection.java @@ -695,7 +695,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo @Override public void unregister(@NotNull Condition condition) { if (myInfo != null) { - QuickFixAction.unregisterQuickFixAction(myInfo, condition); + myInfo.unregisterQuickFix(condition); } } } diff --git a/spellchecker/src/com/intellij/spellchecker/actions/SpellingPopupActionGroup.java b/spellchecker/src/com/intellij/spellchecker/actions/SpellingPopupActionGroup.java index 96eea9a6d60e..a3639c9e2014 100644 --- a/spellchecker/src/com/intellij/spellchecker/actions/SpellingPopupActionGroup.java +++ b/spellchecker/src/com/intellij/spellchecker/actions/SpellingPopupActionGroup.java @@ -16,7 +16,7 @@ package com.intellij.spellchecker.actions; import com.intellij.codeInsight.daemon.impl.HighlightInfo; -import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction; +import com.intellij.codeInsight.daemon.impl.ShowIntentionsPass; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.LocalQuickFix; import com.intellij.codeInspection.ex.QuickFixWrapper; @@ -67,7 +67,7 @@ public final class SpellingPopupActionGroup extends ActionGroup { Project project = e.getData(LangDataKeys.PROJECT); Editor editor = e.getData(LangDataKeys.EDITOR); if (psiFile != null && project != null && editor != null) { - List quickFixes = QuickFixAction.getAvailableActions(editor, psiFile, -1); + List quickFixes = ShowIntentionsPass.getAvailableActions(editor, psiFile, -1); Map> children = new HashMap>(); ArrayList first = new ArrayList(); children.put(Anchor.FIRST, first);