mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
annotators: do not propagate all intentions available in editor to the batch mode as they can show dialogs, etc (IDEA-90380)
This commit is contained in:
+1
-1
@@ -68,7 +68,7 @@ public class FixAllAnnotatorQuickfixTest extends LightQuickFixTestCase {
|
||||
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
|
||||
if (element instanceof PsiMethod) {
|
||||
Annotation annotation = holder.createErrorAnnotation(((PsiMethod)element).getNameIdentifier(), null);
|
||||
annotation.registerFix(new MyFix());
|
||||
annotation.registerUniversalFix(new MyFix(), null, null);
|
||||
annotation.setTextAttributes(CodeInsightColors.DOC_COMMENT_TAG_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.lang.annotation;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.openapi.editor.HighlighterColors;
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
@@ -57,6 +58,7 @@ public final class Annotation implements Segment {
|
||||
private GutterIconRenderer myGutterIconRenderer;
|
||||
@Nullable
|
||||
private String myProblemGroup;
|
||||
private List<QuickFixInfo> myBatchFixes;
|
||||
|
||||
public static class QuickFixInfo {
|
||||
public final IntentionAction quickFix;
|
||||
@@ -155,6 +157,28 @@ public final class Annotation implements Segment {
|
||||
myQuickFixes.add(new QuickFixInfo(fix, range, key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a quickfix which would be available during batch mode only,
|
||||
* in particular during com.intellij.codeInspection.DefaultHighlightVisitorBasedInspection run
|
||||
*/
|
||||
public <T extends IntentionAction & LocalQuickFix> void registerBatchFix(final T fix, @Nullable TextRange range, @Nullable final HighlightDisplayKey key) {
|
||||
if (range == null) {
|
||||
range = new TextRange(myStartOffset, myEndOffset);
|
||||
}
|
||||
|
||||
if (myBatchFixes == null) {
|
||||
myBatchFixes = new ArrayList<QuickFixInfo>();
|
||||
}
|
||||
myBatchFixes.add(new QuickFixInfo(fix, range, key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a quickfix which would be available onTheFly and in the batch mode. Should implement both IntentionAction and LocalQuickFix.
|
||||
*/
|
||||
public <T extends IntentionAction & LocalQuickFix> void registerUniversalFix(final T fix, @Nullable TextRange range, @Nullable final HighlightDisplayKey key) {
|
||||
registerBatchFix(fix, range, key);
|
||||
registerFix(fix, range, key);
|
||||
}
|
||||
/**
|
||||
* Sets a flag indicating what happens with the annotation when the user starts typing.
|
||||
* If the parameter is true, the annotation is removed as soon as the user starts typing
|
||||
@@ -277,6 +301,11 @@ public final class Annotation implements Segment {
|
||||
public List<QuickFixInfo> getQuickFixes() {
|
||||
return myQuickFixes;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<QuickFixInfo> getBatchFixes() {
|
||||
return myBatchFixes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the annotation (shown in the status bar or by "View | Error Description" action).
|
||||
|
||||
@@ -179,4 +179,6 @@ public interface AnnotationHolder {
|
||||
|
||||
|
||||
AnnotationSession getCurrentAnnotationSession();
|
||||
|
||||
boolean isBatchMode();
|
||||
}
|
||||
|
||||
@@ -40,8 +40,20 @@ public class AnnotationHolderImpl extends SmartList<Annotation> implements Annot
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl");
|
||||
private final AnnotationSession myAnnotationSession;
|
||||
|
||||
private final boolean myBatchMode;
|
||||
|
||||
public AnnotationHolderImpl(@NotNull AnnotationSession session) {
|
||||
this(session, false);
|
||||
}
|
||||
|
||||
public AnnotationHolderImpl(@NotNull AnnotationSession session, boolean batchMode) {
|
||||
myAnnotationSession = session;
|
||||
myBatchMode = batchMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatchMode() {
|
||||
return myBatchMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-5
@@ -56,17 +56,19 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware {
|
||||
private final boolean myRunAnnotators;
|
||||
private final DumbService myDumbService;
|
||||
private HighlightInfoHolder myHolder;
|
||||
private boolean myBatchMode;
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public DefaultHighlightVisitor(@NotNull Project project) {
|
||||
this(project, true, true);
|
||||
this(project, true, true, false);
|
||||
}
|
||||
public DefaultHighlightVisitor(@NotNull Project project, boolean highlightErrorElements, boolean runAnnotators) {
|
||||
public DefaultHighlightVisitor(@NotNull Project project, boolean highlightErrorElements, boolean runAnnotators, boolean batchMode) {
|
||||
myProject = project;
|
||||
myHighlightErrorElements = highlightErrorElements;
|
||||
myRunAnnotators = runAnnotators;
|
||||
myErrorFilters = Extensions.getExtensions(FILTER_EP_NAME, project);
|
||||
myDumbService = DumbService.getInstance(project);
|
||||
myBatchMode = batchMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,7 +82,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware {
|
||||
@NotNull final HighlightInfoHolder holder,
|
||||
@NotNull final Runnable action) {
|
||||
myHolder = holder;
|
||||
myAnnotationHolder = new AnnotationHolderImpl(holder.getAnnotationSession());
|
||||
myAnnotationHolder = new AnnotationHolderImpl(holder.getAnnotationSession(), myBatchMode);
|
||||
try {
|
||||
action.run();
|
||||
}
|
||||
@@ -102,7 +104,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware {
|
||||
}
|
||||
if (myAnnotationHolder.hasAnnotations()) {
|
||||
for (Annotation annotation : myAnnotationHolder) {
|
||||
myHolder.add(HighlightInfo.fromAnnotation(annotation));
|
||||
myHolder.add(HighlightInfo.fromAnnotation(annotation, null, myBatchMode));
|
||||
}
|
||||
myAnnotationHolder.clear();
|
||||
}
|
||||
@@ -111,7 +113,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware {
|
||||
@Override
|
||||
@NotNull
|
||||
public HighlightVisitor clone() {
|
||||
return new DefaultHighlightVisitor(myProject, myHighlightErrorElements, myRunAnnotators);
|
||||
return new DefaultHighlightVisitor(myProject, myHighlightErrorElements, myRunAnnotators, myBatchMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -395,10 +395,10 @@ public class HighlightInfo implements Segment {
|
||||
|
||||
|
||||
public static HighlightInfo fromAnnotation(@NotNull Annotation annotation) {
|
||||
return fromAnnotation(annotation, null);
|
||||
return fromAnnotation(annotation, null, false);
|
||||
}
|
||||
|
||||
public static HighlightInfo fromAnnotation(@NotNull Annotation annotation, @Nullable TextRange fixedRange) {
|
||||
public static HighlightInfo fromAnnotation(@NotNull Annotation annotation, @Nullable TextRange fixedRange, boolean batchMode) {
|
||||
final TextAttributes forcedAttributes = annotation.getEnforcedTextAttributes();
|
||||
final TextAttributesKey forcedAttributesKey = forcedAttributes == null ? annotation.getTextAttributes() : null;
|
||||
|
||||
@@ -409,14 +409,21 @@ public class HighlightInfo implements Segment {
|
||||
annotation.getSeverity(), annotation.isAfterEndOfLine(), annotation.needsUpdateOnTyping(), annotation.isFileLevelAnnotation());
|
||||
info.setGutterIconRenderer(annotation.getGutterIconRenderer());
|
||||
info.setProblemGroup(annotation.getProblemGroup());
|
||||
List<Annotation.QuickFixInfo> fixes = annotation.getQuickFixes();
|
||||
if (batchMode) {
|
||||
appendFixes(fixedRange, info, annotation.getBatchFixes());
|
||||
} else {
|
||||
appendFixes(fixedRange, info, annotation.getQuickFixes());
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
private static void appendFixes(TextRange fixedRange, HighlightInfo info, List<Annotation.QuickFixInfo> fixes) {
|
||||
if (fixes != null) {
|
||||
for (final Annotation.QuickFixInfo quickFixInfo : fixes) {
|
||||
QuickFixAction.registerQuickFixAction(info, fixedRange != null ? fixedRange : quickFixInfo.textRange, quickFixInfo.quickFix,
|
||||
quickFixInfo.key != null ? quickFixInfo.key : HighlightDisplayKey.find(DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection.ANNOTATOR_SHORT_NAME));
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public static HighlightInfoType convertType(Annotation annotation) {
|
||||
|
||||
+1
-1
@@ -167,7 +167,7 @@ public abstract class DefaultHighlightVisitorBasedInspection extends GlobalSimpl
|
||||
@NotNull
|
||||
@Override
|
||||
protected HighlightVisitor[] createHighlightVisitors() {
|
||||
return new HighlightVisitor[]{new DefaultHighlightVisitor(project, highlightErrorElements, runAnnotators)};
|
||||
return new HighlightVisitor[]{new DefaultHighlightVisitor(project, highlightErrorElements, runAnnotators, true)};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user