mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlightVisitor moves and cleanup
This commit is contained in:
@@ -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<SuppressQuickFix, SuppressIntentionAction>() {
|
||||
@Override
|
||||
public SuppressIntentionAction fun(SuppressQuickFix fix) {
|
||||
return InspectionManagerEx.convertBatchToSuppressIntentionAction(fix);
|
||||
return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction(fix);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+4
-4
@@ -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<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>> tokens = InjectedLanguageUtil
|
||||
.getHighlightTokens(injectedPsi);
|
||||
if (tokens == null) return;
|
||||
|
||||
@@ -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<Pair<IntentionActionDescriptor, TextRange>> quickFixActionRanges;
|
||||
public List<Pair<IntentionActionDescriptor, RangeMarker>> 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<Annotation.QuickFixInfo> 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<SuppressQuickFix, IntentionAction>() {
|
||||
@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<IntentionAction> 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<IntentionAction> condition) {
|
||||
for (Iterator<Pair<IntentionActionDescriptor, TextRange>> it = quickFixActionRanges.iterator(); it.hasNext();) {
|
||||
Pair<IntentionActionDescriptor, TextRange> pair = it.next();
|
||||
if (condition.value(pair.first.getAction())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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.<TextRange, String>create(highlightInfo.getFixTextRange(), tool.getShortName()))) {
|
||||
EmptyIntentionAction emptyIntentionAction = new EmptyIntentionAction(tool.getDisplayName());
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, emptyIntentionAction, key);
|
||||
}
|
||||
|
||||
+60
-3
@@ -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<HighlightInfo.IntentionActionDescriptor> 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<HighlightInfo.IntentionActionDescriptor> result = new ArrayList<HighlightInfo.IntentionActionDescriptor>();
|
||||
DaemonCodeAnalyzerImpl.processHighlightsNearOffset(editor.getDocument(), project, HighlightSeverity.INFORMATION, offset, true, new Processor<HighlightInfo>() {
|
||||
@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<HighlightInfo.IntentionActionDescriptor> 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<HighlightInfo.IntentionActionDescriptor, RangeMarker> 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<HighlightInfo.IntentionActionDescriptor> intentionsToShow = new ArrayList<HighlightInfo.IntentionActionDescriptor>();
|
||||
public final List<HighlightInfo.IntentionActionDescriptor> errorFixesToShow = new ArrayList<HighlightInfo.IntentionActionDescriptor>();
|
||||
@@ -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<HighlightInfo.IntentionActionDescriptor> fixes = QuickFixAction.getAvailableActions(hostEditor, hostFile, passIdToShowIntentionsFor);
|
||||
List<HighlightInfo.IntentionActionDescriptor> fixes = getAvailableActions(hostEditor, hostFile, passIdToShowIntentionsFor);
|
||||
final DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(project);
|
||||
final Document hostDocument = hostEditor.getDocument();
|
||||
HighlightInfo infoAtCursor = ((DaemonCodeAnalyzerImpl)codeAnalyzer).findHighlightByOffset(hostDocument, offset, true);
|
||||
|
||||
+2
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-108
@@ -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<? extends IntentionAction> 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<IntentionAction> options, @Nullable String displayName) {
|
||||
doRegister(info, action, options, displayName, null, null);
|
||||
public static void registerQuickFixAction(@Nullable HighlightInfo info,
|
||||
@Nullable IntentionAction action,
|
||||
@Nullable List<IntentionAction> 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<IntentionAction> 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<IntentionAction> condition) {
|
||||
for (Iterator<Pair<HighlightInfo.IntentionActionDescriptor, TextRange>> it = info.quickFixActionRanges.iterator(); it.hasNext();) {
|
||||
Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair = it.next();
|
||||
if (condition.value(pair.first.getAction())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is invoked inside atomic action.
|
||||
*/
|
||||
@NotNull
|
||||
public static List<HighlightInfo.IntentionActionDescriptor> 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<HighlightInfo.IntentionActionDescriptor> result = new ArrayList<HighlightInfo.IntentionActionDescriptor>();
|
||||
DaemonCodeAnalyzerImpl.processHighlightsNearOffset(editor.getDocument(), project, HighlightSeverity.INFORMATION, offset, true, new Processor<HighlightInfo>() {
|
||||
@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<HighlightInfo.IntentionActionDescriptor> 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<HighlightInfo.IntentionActionDescriptor, RangeMarker> 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);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class QuickFixActionRegistrarImpl implements QuickFixActionRegistrar {
|
||||
@Override
|
||||
public void unregister(@NotNull Condition<IntentionAction> condition) {
|
||||
if (myInfo != null) {
|
||||
QuickFixAction.unregisterQuickFixAction(myInfo, condition);
|
||||
myInfo.unregisterQuickFix(condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+68
@@ -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();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -695,7 +695,7 @@ public class GrUnresolvedAccessInspection extends GroovySuppressableInspectionTo
|
||||
@Override
|
||||
public void unregister(@NotNull Condition<IntentionAction> condition) {
|
||||
if (myInfo != null) {
|
||||
QuickFixAction.unregisterQuickFixAction(myInfo, condition);
|
||||
myInfo.unregisterQuickFix(condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<HighlightInfo.IntentionActionDescriptor> quickFixes = QuickFixAction.getAvailableActions(editor, psiFile, -1);
|
||||
List<HighlightInfo.IntentionActionDescriptor> quickFixes = ShowIntentionsPass.getAvailableActions(editor, psiFile, -1);
|
||||
Map<Anchor, List<AnAction>> children = new HashMap<Anchor, List<AnAction>>();
|
||||
ArrayList<AnAction> first = new ArrayList<AnAction>();
|
||||
children.put(Anchor.FIRST, first);
|
||||
|
||||
Reference in New Issue
Block a user