From 189184cec0a0619e82b5026249bf97c0b91e91a8 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 24 Sep 2013 14:17:34 +0400 Subject: [PATCH] hide overexposed details --- .../daemon/impl/GeneralHighlightingPass.java | 36 ------------- .../daemon/impl/HighlightInfo.java | 53 ++++++++----------- .../daemon/impl/HighlightInfoComposite.java | 4 +- .../impl/InjectedGeneralHighlightingPass.java | 5 +- .../daemon/impl/LocalInspectionsPass.java | 22 ++++---- 5 files changed, 38 insertions(+), 82 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java index 059ae47df5d3..fd9e6dfe0ad6 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java @@ -16,7 +16,6 @@ package com.intellij.codeInsight.daemon.impl; -import com.intellij.codeHighlighting.Pass; import com.intellij.codeHighlighting.TextEditorHighlightingPass; import com.intellij.codeInsight.daemon.DaemonBundle; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; @@ -31,7 +30,6 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; -import com.intellij.openapi.editor.ex.RangeHighlighterEx; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.progress.ProcessCanceledException; @@ -51,14 +49,12 @@ import com.intellij.psi.PsiManager; import com.intellij.psi.search.PsiTodoSearchHelper; import com.intellij.psi.search.TodoItem; import com.intellij.util.NotNullProducer; -import com.intellij.util.Processor; import com.intellij.util.SmartList; import com.intellij.util.containers.Stack; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -378,38 +374,6 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP analyzeByVisitors(progress, visitors, holder, 0, action); } - protected void killAbandonedHighlightsUnder(@NotNull final TextRange range, - @Nullable final List holder, - @NotNull final ProgressIndicator progress) { - DaemonCodeAnalyzerEx - .processHighlights(getDocument(), myProject, null, range.getStartOffset(), range.getEndOffset(), new Processor() { - @Override - public boolean process(final HighlightInfo existing) { - if (existing.isBijective() && - existing.getGroup() == Pass.UPDATE_ALL && - range.equalsToRange(existing.getActualStartOffset(), existing.getActualEndOffset())) { - if (holder != null) { - for (HighlightInfo created : holder) { - if (existing.equalsByActualOffset(created)) return true; - } - } - // seems that highlight info "existing" is going to disappear - // remove it earlier - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - RangeHighlighterEx highlighter = existing.highlighter; - if (!progress.isCanceled() && highlighter != null) { - highlighter.dispose(); - } - } - }); - } - return true; - } - }); - } - private void analyzeByVisitors(@NotNull final ProgressIndicator progress, @NotNull final HighlightVisitor[] visitors, @NotNull final HighlightInfoHolder holder, diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java index 54c007cc0cdf..c1a46556bcb4 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java @@ -89,7 +89,7 @@ public class HighlightInfo implements Segment { public List> quickFixActionMarkers; private GutterMark gutterIconRenderer; - private ProblemGroup myProblemGroup; + private final ProblemGroup myProblemGroup; private volatile byte myFlags; // bit packed flags below: private static final int BIJECTIVE_FLAG = 0; @@ -104,7 +104,7 @@ public class HighlightInfo implements Segment { return new ProperTextRange(fixStartOffset, fixEndOffset); } - public void setFromInjection(boolean fromInjection) { + void setFromInjection(boolean fromInjection) { setFlag(FROM_INJECTION_FLAG, fromInjection); } @@ -149,15 +149,15 @@ public class HighlightInfo implements Segment { myFlags = (byte)(myFlags & ~(1 << flag) | state << flag); } - public boolean isFileLevelAnnotation() { + boolean isFileLevelAnnotation() { return isFlagSet(FILE_LEVEL_ANNOTATION_FLAG); } - public boolean isBijective() { + boolean isBijective() { return isFlagSet(BIJECTIVE_FLAG); } - public void setBijective(boolean bijective) { + void setBijective(boolean bijective) { setFlag(BIJECTIVE_FLAG, bijective); } @@ -275,7 +275,9 @@ public class HighlightInfo implements Segment { boolean afterEndOfLine, @Nullable Boolean needsUpdateOnTyping, boolean isFileLevelAnnotation, - int navigationShift) { + int navigationShift, + ProblemGroup problemGroup, + GutterMark gutterIconRenderer) { if (startOffset < 0 || startOffset > endOffset) { LOG.error("Incorrect highlightInfo bounds. description="+escapedDescription+"; startOffset="+startOffset+"; endOffset="+endOffset+";type="+type); } @@ -294,6 +296,8 @@ public class HighlightInfo implements Segment { setFlag(NEEDS_UPDATE_ON_TYPING_FLAG, calcNeedUpdateOnTyping(needsUpdateOnTyping, type)); setFlag(FILE_LEVEL_ANNOTATION_FLAG, isFileLevelAnnotation); this.navigationShift = navigationShift; + myProblemGroup = problemGroup; + this.gutterIconRenderer = gutterIconRenderer; } private static boolean calcNeedUpdateOnTyping(@Nullable Boolean needsUpdateOnTyping, HighlightInfoType type) { @@ -381,7 +385,7 @@ public class HighlightInfo implements Segment { return new B(type); } - public void setGroup(int group) { + void setGroup(int group) { this.group = group; } @@ -394,7 +398,7 @@ public class HighlightInfo implements Segment { @NotNull Builder range(int start, int end); @NotNull Builder gutterIconRenderer(@NotNull GutterIconRenderer gutterIconRenderer); - @NotNull Builder problemGroup(@NotNull String problemGroup); + @NotNull Builder problemGroup(@NotNull ProblemGroup problemGroup); // only one allowed @NotNull Builder description(@NotNull String description); @@ -421,7 +425,7 @@ public class HighlightInfo implements Segment { HighlightInfo createUnconditionally(); } - public static boolean isAcceptedByFilters(@NotNull HighlightInfo info, @Nullable PsiElement psiElement) { + private static boolean isAcceptedByFilters(@NotNull HighlightInfo info, @Nullable PsiElement psiElement) { PsiFile file = psiElement == null ? null : psiElement.getContainingFile(); for (HighlightInfoFilter filter : FILTERS) { if (!filter.accept(info, file)) { @@ -449,7 +453,7 @@ public class HighlightInfo implements Segment { private int navigationShift = 0; private GutterIconRenderer gutterIconRenderer; - private String problemGroup; + private ProblemGroup problemGroup; private PsiElement psiElement; public B(@NotNull HighlightInfoType type) { @@ -466,7 +470,7 @@ public class HighlightInfo implements Segment { @NotNull @Override - public Builder problemGroup(@NotNull String problemGroup) { + public Builder problemGroup(@NotNull ProblemGroup problemGroup) { assert this.problemGroup == null : "problemGroup already set"; this.problemGroup = problemGroup; return this; @@ -601,7 +605,7 @@ public class HighlightInfo implements Segment { public HighlightInfo create() { HighlightInfo info = createUnconditionally(); LOG.assertTrue(psiElement != null || severity == HighlightInfoType.SYMBOL_TYPE_SEVERITY || severity == HighlightInfoType.INJECTED_FRAGMENT_SEVERITY || ArrayUtilRt.find(HighlightSeverity.DEFAULT_SEVERITIES, severity) != -1, - "Custom type demands element to detect its text attributes"); + "Custom type requires not-null element to detect its text attributes"); if (!isAcceptedByFilters(info, psiElement)) return null; @@ -616,7 +620,8 @@ public class HighlightInfo implements Segment { } return new HighlightInfo(forcedTextAttributes, forcedTextAttributesKey, type, startOffset, endOffset, escapedDescription, - escapedToolTip, severity, isAfterEndOfLine, myNeedsUpdateOnTyping, isFileLevelAnnotation, navigationShift); + escapedToolTip, severity, isAfterEndOfLine, myNeedsUpdateOnTyping, isFileLevelAnnotation, navigationShift, + problemGroup, gutterIconRenderer); } } @@ -624,19 +629,11 @@ public class HighlightInfo implements Segment { return gutterIconRenderer; } - public void setGutterIconRenderer(final GutterMark gutterIconRenderer) { - this.gutterIconRenderer = gutterIconRenderer; - } - @Nullable public ProblemGroup getProblemGroup() { return myProblemGroup; } - public void setProblemGroup(@Nullable ProblemGroup problemGroup) { - myProblemGroup = problemGroup; - } - @NotNull public static HighlightInfo fromAnnotation(@NotNull Annotation annotation) { return fromAnnotation(annotation, null, false); @@ -652,9 +649,7 @@ public class HighlightInfo implements Segment { fixedRange != null? fixedRange.getEndOffset() : annotation.getEndOffset(), annotation.getMessage(), annotation.getTooltip(), annotation.getSeverity(), annotation.isAfterEndOfLine(), annotation.needsUpdateOnTyping(), annotation.isFileLevelAnnotation(), - 0); - info.setGutterIconRenderer(annotation.getGutterIconRenderer()); - info.setProblemGroup(annotation.getProblemGroup()); + 0, annotation.getProblemGroup(), annotation.getGutterIconRenderer()); appendFixes(fixedRange, info, batchMode ? annotation.getBatchFixes() : annotation.getQuickFixes()); return info; } @@ -710,7 +705,7 @@ public class HighlightInfo implements Segment { return isFlagSet(HAS_HINT_FLAG); } - public void setHint(final boolean hasHint) { + void setHint(final boolean hasHint) { setFlag(HAS_HINT_FLAG, hasHint); } @@ -723,10 +718,6 @@ public class HighlightInfo implements Segment { return h == null || !h.isValid() ? endOffset : h.getEndOffset(); } - //public void setCustomColorScheme(@Nullable final EditorColorsScheme customColorScheme) { - // myCustomColorScheme = customColorScheme; - //} - public static class IntentionActionDescriptor { private final IntentionAction myAction; private volatile List myOptions; @@ -882,11 +873,11 @@ public class HighlightInfo implements Segment { return getActualEndOffset(); } - public int getGroup() { + int getGroup() { return group; } - public boolean isFromInjection() { + boolean isFromInjection() { return isFlagSet(FROM_INJECTION_FLAG); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoComposite.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoComposite.java index bb25859de6fb..9e61d0708db1 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoComposite.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoComposite.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -36,7 +36,7 @@ public class HighlightInfoComposite extends HighlightInfo { public HighlightInfoComposite(@NotNull List infos) { super(null, null, infos.get(0).type, infos.get(0).startOffset, infos.get(0).endOffset, createCompositeDescription(infos), - createCompositeTooltip(infos), infos.get(0).type.getSeverity(null), false, null, false, 0); + createCompositeTooltip(infos), infos.get(0).type.getSeverity(null), false, null, false, 0, infos.get(0).getProblemGroup(), infos.get(0).getGutterIconRenderer()); highlighter = infos.get(0).highlighter; setGroup(infos.get(0).getGroup()); List EMPTY = ContainerUtil.emptyList(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InjectedGeneralHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InjectedGeneralHighlightingPass.java index ae1d56b69467..f41ce7dd693d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InjectedGeneralHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InjectedGeneralHighlightingPass.java @@ -253,7 +253,7 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass imp info.type, fixedTextRange.getStartOffset(), fixedTextRange.getEndOffset(), info.getDescription(), info.getToolTip(), info.type.getSeverity(null), - info.isAfterEndOfLine(), null, false, 0); + info.isAfterEndOfLine(), null, false, 0, info.getProblemGroup(), info.getGutterIconRenderer()); patched.setFromInjection(true); outInfos.add(patched); } @@ -315,9 +315,8 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass imp HighlightInfo patched = new HighlightInfo(info.forcedTextAttributes, info.forcedTextAttributesKey, info.type, hostRange.getStartOffset(), hostRange.getEndOffset(), - info.getDescription(), info.getToolTip(), info.type.getSeverity(null), isAfterEndOfLine, null, false, 0); + info.getDescription(), info.getToolTip(), info.type.getSeverity(null), isAfterEndOfLine, null, false, 0, info.getProblemGroup(), info.getGutterIconRenderer()); patched.setHint(info.hasHint()); - patched.setGutterIconRenderer(info.getGutterIconRenderer()); if (info.quickFixActionRanges != null) { for (Pair pair : info.quickFixActionRanges) { 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 295c177a6be6..5de93879636a 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 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -35,9 +35,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.RangeMarker; -import com.intellij.openapi.editor.colors.CodeInsightColors; import com.intellij.openapi.editor.colors.EditorColorsScheme; -import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.keymap.Keymap; import com.intellij.openapi.keymap.KeymapManager; @@ -437,13 +435,17 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass final HighlightSeverity severity = highlightInfoType.getSeverity(psiElement); TextAttributes attributes = mySeverityRegistrar.getTextAttributesBySeverity(severity); - HighlightInfo highlightInfo = new HighlightInfo(attributes, null, highlightInfoType, textRange.getStartOffset(), textRange.getEndOffset(), message, toolTip, - severity, problemDescriptor.isAfterEndOfLine(), null, isFileLevel, 0); - if (!HighlightInfo.isAcceptedByFilters(highlightInfo, psiElement)) { - return null; - } - highlightInfo.setProblemGroup(problemDescriptor.getProblemGroup()); - return highlightInfo; + HighlightInfo.Builder b = HighlightInfo.newHighlightInfo(highlightInfoType) + .range(psiElement, textRange.getStartOffset(), textRange.getEndOffset()) + .description(message) + .severity(severity); + if (toolTip != null) b.escapedToolTip(toolTip); + if (attributes != null) b.textAttributes(attributes); + if (problemDescriptor.isAfterEndOfLine()) b.endOfLine(); + if (isFileLevel) b.fileLevelAnnotation(); + if (problemDescriptor.getProblemGroup() != null) b.problemGroup(problemDescriptor.getProblemGroup()); + + return b.create(); } private final Map ranges2markersCache = new THashMap();