From be5d58bf05b8e420702dd4d219201aa654564f8e Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 25 May 2012 18:28:53 +0400 Subject: [PATCH 1/6] cleanup & notnull --- .../impl/analysis/HighlightNamesUtil.java | 10 +- .../daemon/impl/DefaultHighlightVisitor.java | 10 +- .../daemon/impl/GeneralHighlightingPass.java | 157 +++--------------- .../daemon/impl/HighlightInfo.java | 104 ++++++------ .../daemon/impl/LocalInspectionsPass.java | 3 +- .../codeInsight/problems/ProblemImpl.java | 4 +- .../problems/WolfTheProblemSolverImpl.java | 46 ++++- .../ChangeSignaturePassFactory.java | 9 +- .../XmlTagTreeHighlightingPass.java | 2 +- 9 files changed, 140 insertions(+), 205 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java index 0f0c0932f84b..7eaa8c8889ae 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightNamesUtil.java @@ -47,7 +47,7 @@ public class HighlightNamesUtil { public static HighlightInfo highlightMethodName(final PsiMethod method, final PsiElement elementToHighlight, final boolean isDeclaration, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { HighlightInfoType type = getMethodNameHighlightType(method, isDeclaration); if (type != null && elementToHighlight != null) { TextAttributes attributes = mergeWithScopeAttributes(method, type, colorsScheme); @@ -59,7 +59,7 @@ public class HighlightNamesUtil { private static TextAttributes mergeWithScopeAttributes(final PsiElement element, final HighlightInfoType type, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { TextAttributes regularAttributes = HighlightInfo.getAttributesByType(element, type, colorsScheme); if (element == null) return regularAttributes; TextAttributes scopeAttributes = getScopeAttributes(element, colorsScheme); @@ -67,7 +67,7 @@ public class HighlightNamesUtil { } @Nullable - public static HighlightInfo highlightClassName(PsiClass aClass, PsiElement elementToHighlight, final EditorColorsScheme colorsScheme) { + public static HighlightInfo highlightClassName(PsiClass aClass, PsiElement elementToHighlight, @NotNull EditorColorsScheme colorsScheme) { HighlightInfoType type = getClassNameHighlightType(aClass, elementToHighlight); if (elementToHighlight != null) { TextAttributes attributes = mergeWithScopeAttributes(aClass, type, colorsScheme); @@ -98,7 +98,7 @@ public class HighlightNamesUtil { @Nullable public static HighlightInfo highlightVariableName(final PsiVariable variable, final PsiElement elementToHighlight, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { HighlightInfoType varType = getVariableNameHighlightType(variable); if (varType != null) { if (variable instanceof PsiField) { @@ -112,7 +112,7 @@ public class HighlightNamesUtil { @Nullable public static HighlightInfo highlightClassNameInQualifier(final PsiJavaCodeReferenceElement element, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { PsiExpression qualifierExpression = null; if (element instanceof PsiReferenceExpression) { qualifierExpression = ((PsiReferenceExpression)element).getQualifierExpression(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitor.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitor.java index fdb1b94119a6..3d527a50f1ea 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitor.java @@ -57,6 +57,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware { private final DumbService myDumbService; private HighlightInfoHolder myHolder; + @SuppressWarnings("UnusedDeclaration") public DefaultHighlightVisitor(@NotNull Project project) { this(project, true, true); } @@ -166,10 +167,11 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware { myHolder.add(info); } - private static HighlightInfo createErrorElementInfo(final PsiErrorElement element) { + private static HighlightInfo createErrorElementInfo(@NotNull PsiErrorElement element) { TextRange range = element.getTextRange(); + String errorDescription = element.getErrorDescription(); if (!range.isEmpty()) { - final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, range, element.getErrorDescription()); + final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, range, errorDescription); for(ErrorQuickFixProvider provider: Extensions.getExtensions(ErrorQuickFixProvider.EP_NAME)) { provider.registerErrorQuickFix(element, highlightInfo); } @@ -183,7 +185,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware { String text = elementAtOffset == null ? null : elementAtOffset.getText(); HighlightInfo info; if (offset < fileLength && text != null && !StringUtil.startsWithChar(text, '\n') && !StringUtil.startsWithChar(text, '\r')) { - info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, offset, offset + 1, element.getErrorDescription()); + info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, offset, offset + 1, errorDescription); } else { int start; @@ -196,7 +198,7 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware { start = offset; end = offset < fileLength ? offset + 1 : offset; } - info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, element, start, end, element.getErrorDescription(),element.getErrorDescription(), true, null); + info = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, element, start, end, errorDescription, errorDescription, true, null); } return info; } 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 9c8af680b995..5b449a89a6b5 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 @@ -185,10 +185,10 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP DaemonCodeAnalyzer daemonCodeAnalyzer = DaemonCodeAnalyzer.getInstance(myProject); HighlightVisitor[] highlightVisitors = getHighlightVisitors(); - final HighlightVisitor[] filteredVisitors = filterVisitors(highlightVisitors, myFile); final List inside = new ArrayList(); final List outside = new ArrayList(); try { + final HighlightVisitor[] filteredVisitors = filterVisitors(highlightVisitors, myFile); Divider.divideInsideAndOutside(myFile, myStartOffset, myEndOffset, myPriorityRange, inside, outside, HighlightLevelUtil.AnalysisLevel.HIGHLIGHT,false); @@ -570,6 +570,26 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP final int chunkSize = Math.max(1, (elements1.size()+elements2.size()) / 100); // one percent precision is enough + final Map ranges2markersCache = new THashMap(); + final TransferToEDTQueue myTransferToEDTQueue + = new TransferToEDTQueue("Apply highlighting results", new Processor() { + @Override + public boolean process(HighlightInfo info) { + ApplicationManager.getApplication().assertIsDispatchThread(); + final EditorColorsScheme colorsScheme = getColorsScheme(); + UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, myFile, myStartOffset, myEndOffset, + info, colorsScheme, Pass.UPDATE_ALL, ranges2markersCache); + + return true; + } + }, new Condition() { + @Override + public boolean value(Object o) { + return myProject.isDisposed() || progress.isCanceled(); + } + }, 200); + + final Runnable action = new Runnable() { @Override public void run() { @@ -630,7 +650,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP } myErrorFound = true; } - myTransferToEDTQueue.offer(Pair.create(info, progress)); + myTransferToEDTQueue.offer(info); } } advanceProgress(elements.size() - (nextLimit-chunkSize)); @@ -642,130 +662,6 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP analyzeByVisitors(progress, visitors, holder, 0, action); } - //private void collectHighlights(@NotNull final List elements1, - // @NotNull final Runnable after1, - // @NotNull final List elements2, - // @NotNull final ProgressIndicator progress, - // @NotNull final HighlightVisitor[] visitors, - // @NotNull final Set gotHighlights, - // final boolean forceHighlightParents) { - // final HighlightInfoHolder holder = createInfoHolder(myFile); - // - // final int chunkSize = Math.max(1, (elements1.size()+elements2.size()) / 100); // one percent precision is enough - // - // final Runnable action = new Runnable() { - // public void run() { - // //noinspection unchecked - // boolean failed = false; - // PsiNodeTask task = createPsiTask(myFile); - // JobSchedulerImpl.submitTask(task); - // - // for (List elements : new List[]{elements1, elements2}) { - // int nextLimit = chunkSize; - // for (int i = 0; i < elements.size(); i++) { - // PsiElement element = elements.get(i); - // progress.checkCanceled(); - // - // if (element != myFile && !skipParentsSet.isEmpty() && element.getFirstChild() != null && skipParentsSet.contains(element)) { - // skipParentsSet.add(element.getParent()); - // continue; - // } - // - // if (element instanceof PsiErrorElement) { - // myHasErrorElement = true; - // } - // kjlhkjh - // if (i == nextLimit) { - // advanceProgress(chunkSize); - // nextLimit = i + chunkSize; - // } - // - // } - // advanceProgress(elements.size() - (nextLimit-chunkSize)); - // if (elements == elements1) after1.run(); - // } - // } - // - // private PsiNodeTask createPsiTask(@NotNull PsiElement root) { - // return new PsiNodeTask(root) { - // @Override - // public void onEnter(@NotNull PsiElement element) { - // if (element instanceof PsiErrorElement) { - // myHasErrorElement = true; - // } - // super.onEnter(element); - // } - // - // @Override - // protected PsiNodeTask forkNode(@NotNull PsiElement child) { - // return createPsiTask(child); - // } - // - // @Override - // protected boolean highlight(PsiElement element) { - // holder.clear(); - // - // for (final HighlightVisitor visitor : visitors) { - // try { - // visitor.visit(element); - // } - // catch (ProcessCanceledException e) { - // throw e; - // } - // catch (IndexNotReadyException e) { - // throw e; - // } - // catch (WolfTheProblemSolverImpl.HaveGotErrorException e) { - // throw e; - // } - // catch (Exception e) { - // LOG.error(e); - // } - // } - // - // //noinspection ForLoopReplaceableByForEach - // for (int j = 0; j < holder.size(); j++) { - // final HighlightInfo info = holder.get(j); - // assert info != null; - // // have to filter out already obtained highlights - // if (!gotHighlights.add(info)) continue; - // boolean isError = info.getSeverity() == HighlightSeverity.ERROR; - // if (isError) { - // if (!forceHighlightParents) { - // skipParentsSet.add(element.getParent()); - // } - // myErrorFound = true; - // } - // myTransferToEDTQueue.offer(Pair.create(info, progress)); - // } - // return true; - // } - // }; - // } - // }; - // - // analyzeByVisitors(progress, visitors, holder, 0, action); - //} - - private final Map ranges2markersCache = new THashMap(); - private final TransferToEDTQueue> myTransferToEDTQueue - = new TransferToEDTQueue>("Apply highlighting results", new Processor>() { - @Override - public boolean process(Pair pair) { - ApplicationManager.getApplication().assertIsDispatchThread(); - ProgressIndicator indicator = pair.getSecond(); - if (indicator.isCanceled()) { - return false; - } - HighlightInfo info = pair.getFirst(); - final EditorColorsScheme colorsScheme = getColorsScheme(); - UpdateHighlightersUtil.addHighlighterToEditorIncrementally(myProject, myDocument, myFile, myStartOffset, myEndOffset, - info, colorsScheme, Pass.UPDATE_ALL, ranges2markersCache); - - return true; - } - }, myProject.getDisposed(), 200); - private void analyzeByVisitors(@NotNull final ProgressIndicator progress, @NotNull final HighlightVisitor[] visitors, @NotNull final HighlightInfoHolder holder, @@ -785,7 +681,8 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP } } - private static HighlightVisitor[] filterVisitors(HighlightVisitor[] highlightVisitors, final PsiFile file) { + @NotNull + private static HighlightVisitor[] filterVisitors(@NotNull HighlightVisitor[] highlightVisitors, @NotNull PsiFile file) { final List visitors = new ArrayList(highlightVisitors.length); List list = Arrays.asList(highlightVisitors); for (HighlightVisitor visitor : DumbService.getInstance(file.getProject()).filterByDumbAwareness(list)) { @@ -798,7 +695,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP return visitorArray; } - static Void cancelAndRestartDaemonLater(ProgressIndicator progress, final Project project, TextEditorHighlightingPass pass) { + static void cancelAndRestartDaemonLater(ProgressIndicator progress, final Project project, TextEditorHighlightingPass pass) { PassExecutorService.log(progress, pass, "Cancel and restart"); progress.cancel(); ApplicationManager.getApplication().invokeLater(new Runnable() { @@ -885,8 +782,8 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP return myUpdateAll ? super.getProgress() : -1; } - private static List convertToProblems(final Collection infos, - final VirtualFile file, + private static List convertToProblems(@NotNull Collection infos, + @NotNull VirtualFile file, final boolean hasErrorElement) { List problems = new SmartList(); for (HighlightInfo info : infos) { 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 30915b710bd7..4f0cc0719f27 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 @@ -20,7 +20,10 @@ 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.*; +import com.intellij.codeInspection.CustomSuppressableInspectionTool; +import com.intellij.codeInspection.InspectionProfile; +import com.intellij.codeInspection.InspectionProfileEntry; +import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.actions.CleanupInspectionIntention; import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; @@ -46,7 +49,6 @@ import com.intellij.openapi.util.TextRange; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.xml.util.XmlStringUtil; @@ -67,13 +69,41 @@ public class HighlightInfo implements Segment { public final TextAttributes forcedTextAttributes; public final TextAttributesKey forcedTextAttributesKey; + public final HighlightInfoType type; + public int group; + public final int startOffset; + public final int endOffset; + + public int fixStartOffset; + public int fixEndOffset; + public RangeMarker fixMarker; // null means it the same as highlighter + + public final String description; + public final String toolTip; + public final HighlightSeverity severity; + + public final boolean isAfterEndOfLine; + public final boolean isFileLevelAnnotation; + public int navigationShift = 0; + + public RangeHighlighterEx highlighter; + public String text; + + public List> quickFixActionRanges; + public List> quickFixActionMarkers; + private boolean hasHint; + public boolean fromInjection; + + private GutterIconRenderer gutterIconRenderer; + private String myProblemGroup; + public boolean bijective; + public HighlightSeverity getSeverity() { return severity; } @Nullable - public TextAttributes getTextAttributes(@Nullable final PsiElement element, - @Nullable final EditorColorsScheme editorColorsScheme) { + public TextAttributes getTextAttributes(@Nullable final PsiElement element, @Nullable final EditorColorsScheme editorColorsScheme) { if (forcedTextAttributes != null) { return forcedTextAttributes; } @@ -92,7 +122,7 @@ public class HighlightInfo implements Segment { public static TextAttributes getAttributesByType(@Nullable final PsiElement element, @NotNull HighlightInfoType type, - final EditorColorsScheme colorsScheme) { + @NotNull EditorColorsScheme colorsScheme) { final SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(element != null ? element.getProject() : null); final TextAttributes textAttributes = severityRegistrar.getTextAttributesBySeverity(type.getSeverity(element)); if (textAttributes != null) { @@ -103,7 +133,7 @@ public class HighlightInfo implements Segment { } @Nullable - public Color getErrorStripeMarkColor(final PsiElement element, + public Color getErrorStripeMarkColor(@NotNull PsiElement element, @Nullable final EditorColorsScheme colorsScheme) { // if null global scheme will be used if (forcedTextAttributes != null && forcedTextAttributes.getErrorStripeColor() != null) { return forcedTextAttributes.getErrorStripeColor(); @@ -174,7 +204,8 @@ public class HighlightInfo implements Segment { boolean isEndOfLine, TextAttributes forcedAttributes) { LOG.assertTrue(element != null || ArrayUtil.find(HighlightSeverity.DEFAULT_SEVERITIES, type.getSeverity(element)) != -1, "Custom type demands element to detect its text attributes"); - HighlightInfo highlightInfo = new HighlightInfo(forcedAttributes, type, start, end, description, toolTip, type.getSeverity(element), isEndOfLine, null, false); + HighlightInfo highlightInfo = new HighlightInfo(forcedAttributes, null, type, start, end, description, toolTip, + type.getSeverity(element), isEndOfLine, null, false); PsiFile file = element == null ? null : element.getContainingFile(); for (HighlightInfoFilter filter : getFilters()) { if (!filter.accept(highlightInfo, file)) { @@ -201,57 +232,19 @@ public class HighlightInfo implements Segment { public static HighlightInfo createHighlightInfo(@NotNull HighlightInfoType type, @NotNull TextRange textRange, String description, String toolTip, TextAttributes textAttributes) { // do not use HighlightInfoFilter - return new HighlightInfo(textAttributes, type, textRange.getStartOffset(), textRange.getEndOffset(), description, htmlEscapeToolTip(toolTip),type.getSeverity(null), false, null, - false); + return new HighlightInfo(textAttributes, null, type, textRange.getStartOffset(), textRange.getEndOffset(), description, + htmlEscapeToolTip(toolTip), type.getSeverity(null), false, null, false); } public boolean needUpdateOnTyping() { return myNeedsUpdateOnTyping; } - public final HighlightInfoType type; - public int group; - public final int startOffset; - public final int endOffset; - - public int fixStartOffset; - public int fixEndOffset; - public RangeMarker fixMarker; - - public final String description; - public final String toolTip; - public final HighlightSeverity severity; - - public final boolean isAfterEndOfLine; - public final boolean isFileLevelAnnotation; - public int navigationShift = 0; - - public RangeHighlighterEx highlighter; - public String text; - - public List> quickFixActionRanges; - public List> quickFixActionMarkers; - private boolean hasHint; - public boolean fromInjection; - - private GutterIconRenderer gutterIconRenderer; - private String myProblemGroup; - - public HighlightInfo(HighlightInfoType type, int startOffset, int endOffset, String description, String toolTip) { - this(null, type, startOffset, endOffset, description, toolTip, type.getSeverity(null), false, null, false); + public HighlightInfo(@NotNull HighlightInfoType type, int startOffset, int endOffset, String description, String toolTip) { + this(null, null, type, startOffset, endOffset, description, toolTip, type.getSeverity(null), false, null, false); } - public HighlightInfo(@Nullable TextAttributes forcedTextAttributes, - @NotNull HighlightInfoType type, - int startOffset, - int endOffset, - @Nullable String description, - @Nullable String toolTip, - @NotNull HighlightSeverity severity, - boolean afterEndOfLine, - @Nullable Boolean needsUpdateOnTyping, boolean isFileLevelAnnotation) { - this(forcedTextAttributes, null, type, startOffset, endOffset, description, toolTip, severity, afterEndOfLine, needsUpdateOnTyping, isFileLevelAnnotation); - } + //primary public HighlightInfo(@Nullable TextAttributes forcedTextAttributes, @Nullable TextAttributesKey forcedTextAttributesKey, @NotNull HighlightInfoType type, @@ -261,7 +254,8 @@ public class HighlightInfo implements Segment { @Nullable String toolTip, @NotNull HighlightSeverity severity, boolean afterEndOfLine, - @Nullable Boolean needsUpdateOnTyping, boolean isFileLevelAnnotation) { + @Nullable Boolean needsUpdateOnTyping, + boolean isFileLevelAnnotation) { if (startOffset < 0 || startOffset > endOffset) { LOG.error("Incorrect highlightInfo bounds. description="+description+"; startOffset="+startOffset+"; endOffset="+endOffset+";type="+type); } @@ -353,7 +347,7 @@ public class HighlightInfo implements Segment { } public static HighlightInfo createHighlightInfo(@NotNull HighlightInfoType type, @NotNull ASTNode childByRole, String localizedMessage) { - return createHighlightInfo(type, SourceTreeToPsiMap.treeElementToPsi(childByRole), localizedMessage); + return createHighlightInfo(type, childByRole.getPsi(), localizedMessage); } public GutterIconRenderer getGutterIconRenderer() { @@ -379,8 +373,8 @@ public class HighlightInfo implements Segment { final TextAttributes attributes) { TextRange textRange = element.getTextRange(); // do not use HighlightInfoFilter - return new HighlightInfo(attributes, type, textRange.getStartOffset(), textRange.getEndOffset(), message, htmlEscapeToolTip(message), - type.getSeverity(element), false, Boolean.FALSE, false); + return new HighlightInfo(attributes, null, type, textRange.getStartOffset(), textRange.getEndOffset(), message, + htmlEscapeToolTip(message), type.getSeverity(element), false, Boolean.FALSE, false); } @@ -548,7 +542,7 @@ public class HighlightInfo implements Segment { @NonNls public String toString() { String text = getAction().getText(); - return "descriptor: " + (text.length()==0 ? getAction().getClass() : text); + return "descriptor: " + (text.isEmpty() ? getAction().getClass() : text); } public Icon getIcon() { 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 ed110d1bd749..52fb9139dc94 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 @@ -436,8 +436,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass final HighlightSeverity severity = highlightInfoType.getSeverity(psiElement); TextAttributes attributes = mySeverityRegistrar.getTextAttributesBySeverity(severity); - return new HighlightInfo(attributes, highlightInfoType, textRange.getStartOffset(), - textRange.getEndOffset(), message, toolTip, + return new HighlightInfo(attributes, null, highlightInfoType, textRange.getStartOffset(), textRange.getEndOffset(), message, toolTip, severity, problemDescriptor.isAfterEndOfLine(), null, isFileLevel); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/problems/ProblemImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/problems/ProblemImpl.java index 9d04290132f0..bc877859793d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/problems/ProblemImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/problems/ProblemImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.problems.Problem; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; /** * @author cdr @@ -29,12 +30,13 @@ public class ProblemImpl implements Problem { private final HighlightInfo highlightInfo; private final boolean isSyntax; - public ProblemImpl(final VirtualFile virtualFile, final HighlightInfo highlightInfo, final boolean isSyntax) { + public ProblemImpl(@NotNull VirtualFile virtualFile, @NotNull HighlightInfo highlightInfo, final boolean isSyntax) { this.isSyntax = isSyntax; this.virtualFile = virtualFile; this.highlightInfo = highlightInfo; } + @Override public VirtualFile getVirtualFile() { return virtualFile; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java index a61cc16648c6..db77ad23abb5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java @@ -66,18 +66,21 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { private final List> myFilters = ContainerUtil.createEmptyCOWList(); private boolean myFiltersLoaded = false; private final ProblemListener fireProblemListeners = new ProblemListener() { + @Override public void problemsAppeared(VirtualFile file) { for (final ProblemListener problemListener : myProblemListeners) { problemListener.problemsAppeared(file); } } + @Override public void problemsChanged(VirtualFile file) { for (final ProblemListener problemListener : myProblemListeners) { problemListener.problemsChanged(file); } } + @Override public void problemsDisappeared(VirtualFile file) { for (final ProblemListener problemListener : myProblemListeners) { problemListener.problemsDisappeared(file); @@ -122,36 +125,44 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { public WolfTheProblemSolverImpl(Project project, PsiManager psiManager, VirtualFileManager virtualFileManager) { myProject = project; PsiTreeChangeListener changeListener = new PsiTreeChangeAdapter() { + @Override public void childAdded(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void childRemoved(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void childReplaced(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void childMoved(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void propertyChanged(@NotNull PsiTreeChangeEvent event) { childrenChanged(event); } + @Override public void childrenChanged(@NotNull PsiTreeChangeEvent event) { clearSyntaxErrorFlag(event); } }; psiManager.addPsiTreeChangeListener(changeListener); VirtualFileListener virtualFileListener = new VirtualFileAdapter() { + @Override public void fileDeleted(final VirtualFileEvent event) { onDeleted(event.getFile()); } + @Override public void fileMoved(final VirtualFileMoveEvent event) { onDeleted(event.getFile()); } @@ -169,10 +180,12 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject); if (fileStatusManager != null) { //tests? fileStatusManager.addFileStatusListener(new FileStatusListener() { + @Override public void fileStatusesChanged() { clearInvalidFiles(); } + @Override public void fileStatusChanged(@NotNull VirtualFile virtualFile) { fileStatusesChanged(); } @@ -204,22 +217,27 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public void projectOpened() { } + @Override public void projectClosed() { } + @Override @NotNull @NonNls public String getComponentName() { return "Problems"; } + @Override public void initComponent() { } + @Override public void disposeComponent() { } @@ -257,14 +275,16 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { private final HighlightInfo myHighlightInfo; private final boolean myHasErrorElement; - private HaveGotErrorException(HighlightInfo info, final boolean hasErrorElement) { + private HaveGotErrorException(@NotNull HighlightInfo info, final boolean hasErrorElement) { myHighlightInfo = info; myHasErrorElement = hasErrorElement; } } // returns true if car has been cleaned - private boolean orderVincentToCleanTheCar(final VirtualFile file, final ProgressIndicator progressIndicator, final StatusBar statusBar) throws ProcessCanceledException { + private boolean orderVincentToCleanTheCar(@NotNull final VirtualFile file, + @NotNull final ProgressIndicator progressIndicator, + @NotNull final StatusBar statusBar) throws ProcessCanceledException { if (!isToBeHighlighted(file)) { clearProblems(file); return true; // file is going to be red waved no more @@ -282,8 +302,10 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { try { GeneralHighlightingPass pass = new GeneralHighlightingPass(myProject, psiFile, document, 0, document.getTextLength(), false) { + @Override protected HighlightInfoHolder createInfoHolder(final PsiFile file) { return new HighlightInfoHolder(file, HighlightInfoFilter.EMPTY_ARRAY) { + @Override public boolean add(HighlightInfo info) { if (info != null && info.getSeverity() == HighlightSeverity.ERROR) { throw new HaveGotErrorException(info, myHasErrorElement); @@ -294,6 +316,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } }; ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override public void run() { if (progressIndicator.isCanceled()) return; statusBar.setInfo("Checking '" + file.getPresentableUrl() + "'"); @@ -323,6 +346,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { private static void restoreStatusBarInfo(final StatusBar statusBar, final Pair oldInfo) { if (statusBar instanceof StatusBarEx) { LaterInvocator.invokeLater(new Runnable() { + @Override public void run() { statusBar.setInfo(oldInfo.first, oldInfo.second); } @@ -330,6 +354,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public boolean hasSyntaxErrors(final VirtualFile file) { synchronized (myProblems) { ProblemFileInfo info = myProblems.get(file); @@ -350,6 +375,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return false; } + @Override public boolean hasProblemFilesBeneath(Condition condition) { if (!myProject.isOpen()) return false; synchronized (myProblems) { @@ -363,34 +389,42 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public boolean hasProblemFilesBeneath(final Module scope) { return hasProblemFilesBeneath(new Condition() { + @Override public boolean value(final VirtualFile virtualFile) { return ModuleUtil.moduleContainsFile(scope, virtualFile, false); } }); } + @Override public void addProblemListener(ProblemListener listener) { myProblemListeners.add(listener); } + @Override public void addProblemListener(final ProblemListener listener, Disposable parentDisposable) { addProblemListener(listener); Disposer.register(parentDisposable, new Disposable() { + @Override public void dispose() { removeProblemListener(listener); } }); } + @Override public void removeProblemListener(ProblemListener listener) { myProblemListeners.remove(listener); } + @Override public void registerFileHighlightFilter(final Condition filter, Disposable parentDisposable) { myFilters.add(filter); Disposer.register(parentDisposable, new Disposable() { + @Override public void dispose() { myFilters.remove(filter); } @@ -405,6 +439,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public boolean isProblemFile(VirtualFile virtualFile) { synchronized (myProblems) { return myProblems.containsKey(virtualFile); @@ -430,6 +465,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return false; } + @Override public void weHaveGotProblems(@NotNull final VirtualFile virtualFile, @NotNull List problems) { if (problems.isEmpty()) return; if (!isToBeHighlighted(virtualFile)) return; @@ -452,14 +488,17 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } + @Override public void clearProblems(@NotNull VirtualFile virtualFile) { doRemove(virtualFile); } + @Override public Problem convertToProblem(final VirtualFile virtualFile, final HighlightSeverity severity, final TextRange textRange, final String messageText) { if (virtualFile == null || textRange.getStartOffset() < 0 || textRange.getLength() < 0 ) return null; HighlightInfo info = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override public HighlightInfo compute() { return HighlightInfo.createHighlightInfo(HighlightInfo.convertSeverity(severity), textRange, messageText); } @@ -467,9 +506,11 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return new ProblemImpl(virtualFile, info, false); } + @Override public Problem convertToProblem(final VirtualFile virtualFile, final int line, final int column, final String[] message) { if (virtualFile == null || virtualFile.isDirectory() || virtualFile.getFileType().isBinary()) return null; HighlightInfo info = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override public HighlightInfo compute() { TextRange textRange = getTextRange(virtualFile, line, column); return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, StringUtil.join(message, "\n")); @@ -479,6 +520,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return new ProblemImpl(virtualFile, info, false); } + @Override public void reportProblems(final VirtualFile file, Collection problems) { if (problems.isEmpty()) { clearProblems(file); diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignaturePassFactory.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignaturePassFactory.java index c599b8b6e752..069fa045c2bc 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignaturePassFactory.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignaturePassFactory.java @@ -96,11 +96,10 @@ public class ChangeSignaturePassFactory extends AbstractProjectComponent impleme HighlightInfo info = null; if (myRange != null) { info = new HighlightInfo(new TextAttributes(null, null, - myEditor.getColorsScheme().getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES).getEffectColor(), - null, Font.PLAIN), - HighlightInfoType.INFORMATION, myRange.getStartOffset(), myRange.getEndOffset(), - SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED, SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED, - HighlightSeverity.INFORMATION, false, true, false); + myEditor.getColorsScheme().getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES).getEffectColor(), + null, Font.PLAIN), null, HighlightInfoType.INFORMATION, + myRange.getStartOffset(), myRange.getEndOffset(), SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED, + SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED, HighlightSeverity.INFORMATION, false, true, false); final ArrayList options = new ArrayList(); options.add(new DismissNewSignatureIntentionAction()); QuickFixAction.registerQuickFixAction(info, new ChangeSignatureDetectorAction(), options, null); diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java index 082e009a7150..9e3aedfa4525 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java @@ -220,7 +220,7 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass { @NotNull private static HighlightInfo createHighlightInfo(Color color, @NotNull TextRange range) { - return new HighlightInfo(new TextAttributes(null, color, null, null, Font.PLAIN), TYPE, range.getStartOffset(), + return new HighlightInfo(new TextAttributes(null, color, null, null, Font.PLAIN), null, TYPE, range.getStartOffset(), range.getEndOffset(), null, null, HighlightSeverity.INFORMATION, false, null, false); } From ce8786fdfb8d67538fb53d8e65b08fdc7e034758 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 29 May 2012 12:45:38 +0400 Subject: [PATCH 2/6] more correct preloading tools --- .../daemon/impl/DaemonCodeAnalyzerImpl.java | 19 ----------- .../daemon/impl/DaemonListeners.java | 32 ++++++++++++++++++- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java index 7dc5955bc4d9..278856c59083 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java @@ -757,25 +757,6 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx runnable.run(); } else { - final InspectionProfileWrapper profile = InspectionProjectProfileManager.getInstance(myProject).getProfileWrapper(); - final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(activeEditor.getDocument()); - if (psiFile != null && profile != null && !profile.areToolsInstantiated()) { - // optimization: do expensive classloading outside readaction - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - @Override - public void run() { - try { - if (!psiFile.getManager().isDisposed() && !profile.areToolsInstantiated()) { - profile.preInstantiateTools(psiFile); - } - } - catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - } - ((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(myProject)).cancelAndRunWhenAllCommitted( "start daemon when all committed", runnable); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index 94a57927ce54..8bfaabded0ea 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -20,6 +20,7 @@ import com.intellij.ProjectTopics; import com.intellij.codeHighlighting.Pass; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.hint.TooltipController; +import com.intellij.codeInspection.ex.InspectionProfileWrapper; import com.intellij.ide.PowerSaveMode; import com.intellij.ide.todo.TodoConfiguration; import com.intellij.openapi.Disposable; @@ -130,7 +131,7 @@ class DaemonListeners implements Disposable { @Override public void caretPositionChanged(CaretEvent e) { Editor editor = e.getEditor(); - if ((!editor.getComponent().isShowing() && !ApplicationManager.getApplication().isUnitTestMode()) || + if (!editor.getComponent().isShowing() && !ApplicationManager.getApplication().isUnitTestMode() || !worthBothering(editor.getDocument(), editor.getProject())) { return; //no need to stop daemon if something happened in the console } @@ -158,6 +159,7 @@ class DaemonListeners implements Disposable { // editor appear in modal context, re-enable the daemon myDaemonCodeAnalyzer.setUpdateByTimerEnabled(true); } + preInstantiateTools(); } }; myEditorTracker.addEditorTrackerListener(editorTrackerListener, this); @@ -294,6 +296,33 @@ class DaemonListeners implements Disposable { LaterInvocator.addModalityStateListener(modalityStateListener,this); } + private void preInstantiateTools() { + final InspectionProfileWrapper profile = InspectionProjectProfileManager.getInstance(myProject).getProfileWrapper(); + if (profile == null || profile.areToolsInstantiated()) return; + Collection editors = getSelectedEditors(); + for (FileEditor fe : editors) { + if (!(fe instanceof TextEditor)) continue; + Editor editor = ((TextEditor)fe).getEditor(); + final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument()); + if (psiFile == null) continue; + // optimization: do expensive classloading outside readaction + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + @Override + public void run() { + if (!psiFile.getManager().isDisposed() && !profile.areToolsInstantiated()) { + try { + profile.preInstantiateTools(psiFile); + } + catch (Throwable ignored) { + // app still can be disposed in the middle, ignore + } + } + } + }); + break; + } + } + static boolean isUnderIgnoredAction(@Nullable Object action) { return action instanceof DocumentRunnable.IgnoreDocumentRunnable || ApplicationManager.getApplication().hasWriteAction(DocumentRunnable.IgnoreDocumentRunnable.class); @@ -532,6 +561,7 @@ class DaemonListeners implements Disposable { myDaemonCodeAnalyzer.restart(); } + @NotNull Collection getSelectedEditors() { // Editors in modal context List editors = getActiveEditors(); From f13edd92aadcfa670e84842248246401909f9c4d Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 29 May 2012 16:36:07 +0400 Subject: [PATCH 3/6] do not blink status bar --- .../problems/WolfTheProblemSolver.java | 12 +- .../problems/MockWolfTheProblemSolver.java | 12 +- .../problems/WolfTheProblemSolverImpl.java | 103 ++++++------------ 3 files changed, 46 insertions(+), 81 deletions(-) diff --git a/platform/lang-api/src/com/intellij/problems/WolfTheProblemSolver.java b/platform/lang-api/src/com/intellij/problems/WolfTheProblemSolver.java index 664d2c6eb9ac..64679da42adb 100644 --- a/platform/lang-api/src/com/intellij/problems/WolfTheProblemSolver.java +++ b/platform/lang-api/src/com/intellij/problems/WolfTheProblemSolver.java @@ -46,9 +46,9 @@ public abstract class WolfTheProblemSolver implements ProjectComponent { public abstract void weHaveGotProblems(@NotNull VirtualFile virtualFile, @NotNull List problems); public abstract void clearProblems(@NotNull VirtualFile virtualFile); - public abstract boolean hasProblemFilesBeneath(Condition condition); + public abstract boolean hasProblemFilesBeneath(@NotNull Condition condition); - public abstract boolean hasProblemFilesBeneath(Module scope); + public abstract boolean hasProblemFilesBeneath(@NotNull Module scope); @Nullable public abstract Problem convertToProblem(final VirtualFile virtualFile, final HighlightSeverity severity, @@ -66,13 +66,13 @@ public abstract class WolfTheProblemSolver implements ProjectComponent { public void problemsDisappeared(VirtualFile file) {} } - public abstract void addProblemListener(ProblemListener listener); - public abstract void addProblemListener(ProblemListener listener, Disposable parentDisposable); - public abstract void removeProblemListener(ProblemListener listener); + public abstract void addProblemListener(@NotNull ProblemListener listener); + public abstract void addProblemListener(@NotNull ProblemListener listener, @NotNull Disposable parentDisposable); + public abstract void removeProblemListener(@NotNull ProblemListener listener); /** * @deprecated register extensions to {@link #FILTER_EP_NAME} instead */ - public abstract void registerFileHighlightFilter(Condition filter, Disposable parentDisposable); + public abstract void registerFileHighlightFilter(@NotNull Condition filter, @NotNull Disposable parentDisposable); public abstract void queue(VirtualFile suspiciousFile); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/problems/MockWolfTheProblemSolver.java b/platform/lang-impl/src/com/intellij/codeInsight/problems/MockWolfTheProblemSolver.java index 55d2365f2728..ab743ce1ed00 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/problems/MockWolfTheProblemSolver.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/problems/MockWolfTheProblemSolver.java @@ -44,7 +44,7 @@ public class MockWolfTheProblemSolver extends WolfTheProblemSolver { if (myDelegate != null) myDelegate.weHaveGotProblems(virtualFile, problems); } - public boolean hasProblemFilesBeneath(final Condition condition) { + public boolean hasProblemFilesBeneath(@NotNull final Condition condition) { return false; } @@ -52,23 +52,23 @@ public class MockWolfTheProblemSolver extends WolfTheProblemSolver { return myDelegate != null && myDelegate.hasSyntaxErrors(file); } - public boolean hasProblemFilesBeneath(Module scope) { + public boolean hasProblemFilesBeneath(@NotNull Module scope) { return false; } - public void addProblemListener(ProblemListener listener) { + public void addProblemListener(@NotNull ProblemListener listener) { if (myDelegate != null) myDelegate.addProblemListener(listener); } - public void addProblemListener(ProblemListener listener, Disposable parentDisposable) { + public void addProblemListener(@NotNull ProblemListener listener, @NotNull Disposable parentDisposable) { if (myDelegate != null) myDelegate.addProblemListener(listener, parentDisposable); } - public void removeProblemListener(ProblemListener listener) { + public void removeProblemListener(@NotNull ProblemListener listener) { if (myDelegate != null) myDelegate.removeProblemListener(listener); } - public void registerFileHighlightFilter(Condition filter, Disposable parentDisposable) { + public void registerFileHighlightFilter(@NotNull Condition filter, @NotNull Disposable parentDisposable) { } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java index db77ad23abb5..d505f8af1210 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/problems/WolfTheProblemSolverImpl.java @@ -21,7 +21,6 @@ import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder; import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.impl.LaterInvocator; import com.intellij.openapi.editor.Document; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -34,14 +33,14 @@ import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.FileStatusListener; import com.intellij.openapi.vcs.FileStatusManager; import com.intellij.openapi.vfs.*; -import com.intellij.openapi.wm.StatusBar; -import com.intellij.openapi.wm.WindowManager; -import com.intellij.openapi.wm.ex.StatusBarEx; import com.intellij.problems.Problem; import com.intellij.problems.WolfTheProblemSolver; import com.intellij.psi.*; @@ -106,7 +105,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { private final Collection problems = new THashSet(); private boolean hasSyntaxErrors; - public boolean equals(final Object o) { + public boolean equals(@Nullable final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; @@ -122,7 +121,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } - public WolfTheProblemSolverImpl(Project project, PsiManager psiManager, VirtualFileManager virtualFileManager) { + public WolfTheProblemSolverImpl(@NotNull Project project, @NotNull PsiManager psiManager, @NotNull VirtualFileManager virtualFileManager) { myProject = project; PsiTreeChangeListener changeListener = new PsiTreeChangeAdapter() { @Override @@ -158,16 +157,16 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { psiManager.addPsiTreeChangeListener(changeListener); VirtualFileListener virtualFileListener = new VirtualFileAdapter() { @Override - public void fileDeleted(final VirtualFileEvent event) { + public void fileDeleted(@NotNull final VirtualFileEvent event) { onDeleted(event.getFile()); } @Override - public void fileMoved(final VirtualFileMoveEvent event) { + public void fileMoved(@NotNull final VirtualFileMoveEvent event) { onDeleted(event.getFile()); } - private void onDeleted(final VirtualFile file) { + private void onDeleted(@NotNull final VirtualFile file) { if (file.isDirectory()) { clearInvalidFiles(); } @@ -205,7 +204,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } - private void clearSyntaxErrorFlag(final PsiTreeChangeEvent event) { + private void clearSyntaxErrorFlag(@NotNull final PsiTreeChangeEvent event) { PsiFile file = event.getFile(); if (file == null) return; VirtualFile virtualFile = file.getVirtualFile(); @@ -254,25 +253,18 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { if (file.isValid()) progressLimit += file.getLength(); // (rough approx number of PSI elements = file length/2) * (visitor count = 2 usually) } pass.setProgressLimit(progressLimit); - final StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject); - Pair oldInfo = saveStatusBarInfo(statusBar); - try { - for (final VirtualFile virtualFile : files) { - progress.checkCanceled(); - if (virtualFile == null) break; - if (!virtualFile.isValid() || orderVincentToCleanTheCar(virtualFile, progress, statusBar)) { - doRemove(virtualFile); - } - if (virtualFile.isValid()) pass.advanceProgress(virtualFile.getLength()); + for (final VirtualFile virtualFile : files) { + progress.checkCanceled(); + if (virtualFile == null) break; + if (!virtualFile.isValid() || orderVincentToCleanTheCar(virtualFile, progress)) { + doRemove(virtualFile); } - } - finally { - restoreStatusBarInfo(statusBar, oldInfo); + if (virtualFile.isValid()) pass.advanceProgress(virtualFile.getLength()); } } public static class HaveGotErrorException extends RuntimeException { - private final HighlightInfo myHighlightInfo; + @NotNull private final HighlightInfo myHighlightInfo; private final boolean myHasErrorElement; private HaveGotErrorException(@NotNull HighlightInfo info, final boolean hasErrorElement) { @@ -283,8 +275,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { // returns true if car has been cleaned private boolean orderVincentToCleanTheCar(@NotNull final VirtualFile file, - @NotNull final ProgressIndicator progressIndicator, - @NotNull final StatusBar statusBar) throws ProcessCanceledException { + @NotNull final ProgressIndicator progressIndicator) throws ProcessCanceledException { if (!isToBeHighlighted(file)) { clearProblems(file); return true; // file is going to be red waved no more @@ -303,10 +294,10 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { try { GeneralHighlightingPass pass = new GeneralHighlightingPass(myProject, psiFile, document, 0, document.getTextLength(), false) { @Override - protected HighlightInfoHolder createInfoHolder(final PsiFile file) { + protected HighlightInfoHolder createInfoHolder(@NotNull final PsiFile file) { return new HighlightInfoHolder(file, HighlightInfoFilter.EMPTY_ARRAY) { @Override - public boolean add(HighlightInfo info) { + public boolean add(@Nullable HighlightInfo info) { if (info != null && info.getSeverity() == HighlightSeverity.ERROR) { throw new HaveGotErrorException(info, myHasErrorElement); } @@ -315,13 +306,6 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { }; } }; - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - if (progressIndicator.isCanceled()) return; - statusBar.setInfo("Checking '" + file.getPresentableUrl() + "'"); - } - }); pass.collectInformation(progressIndicator); } catch (HaveGotErrorException e) { @@ -333,27 +317,6 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { return true; } - @Nullable - private static Pair saveStatusBarInfo(final StatusBar statusBar) { - Pair oldInfo = null; - if (statusBar instanceof StatusBarEx) { - oldInfo = Pair.create(statusBar.getInfo(), ((StatusBarEx)statusBar).getInfoRequestor()); - } - - return oldInfo; - } - - private static void restoreStatusBarInfo(final StatusBar statusBar, final Pair oldInfo) { - if (statusBar instanceof StatusBarEx) { - LaterInvocator.invokeLater(new Runnable() { - @Override - public void run() { - statusBar.setInfo(oldInfo.first, oldInfo.second); - } - }); - } - } - @Override public boolean hasSyntaxErrors(final VirtualFile file) { synchronized (myProblems) { @@ -376,7 +339,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } @Override - public boolean hasProblemFilesBeneath(Condition condition) { + public boolean hasProblemFilesBeneath(@NotNull Condition condition) { if (!myProject.isOpen()) return false; synchronized (myProblems) { if (!myProblems.isEmpty()) { @@ -390,7 +353,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } @Override - public boolean hasProblemFilesBeneath(final Module scope) { + public boolean hasProblemFilesBeneath(@NotNull final Module scope) { return hasProblemFilesBeneath(new Condition() { @Override public boolean value(final VirtualFile virtualFile) { @@ -400,12 +363,12 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } @Override - public void addProblemListener(ProblemListener listener) { + public void addProblemListener(@NotNull ProblemListener listener) { myProblemListeners.add(listener); } @Override - public void addProblemListener(final ProblemListener listener, Disposable parentDisposable) { + public void addProblemListener(@NotNull final ProblemListener listener, @NotNull Disposable parentDisposable) { addProblemListener(listener); Disposer.register(parentDisposable, new Disposable() { @Override @@ -416,12 +379,12 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } @Override - public void removeProblemListener(ProblemListener listener) { + public void removeProblemListener(@NotNull ProblemListener listener) { myProblemListeners.remove(listener); } @Override - public void registerFileHighlightFilter(final Condition filter, Disposable parentDisposable) { + public void registerFileHighlightFilter(@NotNull final Condition filter, @NotNull Disposable parentDisposable) { myFilters.add(filter); Disposer.register(parentDisposable, new Disposable() { @Override @@ -446,7 +409,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } } - private boolean isToBeHighlighted(VirtualFile virtualFile) { + private boolean isToBeHighlighted(@Nullable VirtualFile virtualFile) { if (virtualFile == null) return false; synchronized (myFilters) { @@ -494,8 +457,10 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } @Override - public Problem convertToProblem(final VirtualFile virtualFile, final HighlightSeverity severity, - final TextRange textRange, final String messageText) { + public Problem convertToProblem(@Nullable final VirtualFile virtualFile, + final HighlightSeverity severity, + @NotNull final TextRange textRange, + final String messageText) { if (virtualFile == null || textRange.getStartOffset() < 0 || textRange.getLength() < 0 ) return null; HighlightInfo info = ApplicationManager.getApplication().runReadAction(new Computable() { @Override @@ -507,7 +472,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } @Override - public Problem convertToProblem(final VirtualFile virtualFile, final int line, final int column, final String[] message) { + public Problem convertToProblem(@Nullable final VirtualFile virtualFile, final int line, final int column, @NotNull final String[] message) { if (virtualFile == null || virtualFile.isDirectory() || virtualFile.getFileType().isBinary()) return null; HighlightInfo info = ApplicationManager.getApplication().runReadAction(new Computable() { @Override @@ -521,7 +486,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } @Override - public void reportProblems(final VirtualFile file, Collection problems) { + public void reportProblems(@NotNull final VirtualFile file, @NotNull Collection problems) { if (problems.isEmpty()) { clearProblems(file); return; @@ -552,7 +517,7 @@ public class WolfTheProblemSolverImpl extends WolfTheProblemSolver { } @NotNull - private static TextRange getTextRange(final VirtualFile virtualFile, int line, final int column) { + private static TextRange getTextRange(@NotNull final VirtualFile virtualFile, int line, final int column) { Document document = FileDocumentManager.getInstance().getDocument(virtualFile); if (line > document.getLineCount()) line = document.getLineCount(); line = line <= 0 ? 0 : line - 1; From 5068a5e453ca541543a6653e6ebd0255fe6703c3 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 29 May 2012 16:36:19 +0400 Subject: [PATCH 4/6] notnull --- .../src/com/intellij/openapi/module/ModuleUtil.java | 4 ++-- .../src/com/intellij/openapi/roots/ModuleFileIndex.java | 4 ++-- .../intellij/openapi/roots/impl/ModuleFileIndexImpl.java | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java b/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java index d45baeb40dec..67090a96a471 100644 --- a/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java +++ b/platform/lang-api/src/com/intellij/openapi/module/ModuleUtil.java @@ -213,7 +213,7 @@ public class ModuleUtil { return list; } - public static boolean visitMeAndDependentModules(final @NotNull Module module, final ModuleVisitor visitor) { + public static boolean visitMeAndDependentModules(@NotNull final Module module, final ModuleVisitor visitor) { if (!visitor.visit(module)) { return false; } @@ -226,7 +226,7 @@ public class ModuleUtil { return true; } - public static boolean moduleContainsFile(final Module module, VirtualFile file, boolean isLibraryElement) { + public static boolean moduleContainsFile(@NotNull final Module module, VirtualFile file, boolean isLibraryElement) { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); if (isLibraryElement) { OrderEntry orderEntry = moduleRootManager.getFileIndex().getOrderEntryForFile(file); diff --git a/platform/projectModel-api/src/com/intellij/openapi/roots/ModuleFileIndex.java b/platform/projectModel-api/src/com/intellij/openapi/roots/ModuleFileIndex.java index 965223bfee0f..439c8ccfdeee 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/roots/ModuleFileIndex.java +++ b/platform/projectModel-api/src/com/intellij/openapi/roots/ModuleFileIndex.java @@ -36,7 +36,7 @@ public interface ModuleFileIndex extends FileIndex { * it does not belong to any order entry. */ @Nullable - OrderEntry getOrderEntryForFile(VirtualFile fileOrDir); + OrderEntry getOrderEntryForFile(@NotNull VirtualFile fileOrDir); /** * Returns the list of all order entries to which the specified file or directory @@ -45,5 +45,5 @@ public interface ModuleFileIndex extends FileIndex { * @param fileOrDir the file or directory to check. * @return the list of order entries to which the file or directory belongs. */ - @NotNull List getOrderEntriesForFile(VirtualFile fileOrDir); + @NotNull List getOrderEntriesForFile(@NotNull VirtualFile fileOrDir); } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleFileIndexImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleFileIndexImpl.java index 9e7a6a1ddb59..1697af20ac88 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleFileIndexImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/ModuleFileIndexImpl.java @@ -47,6 +47,7 @@ public class ModuleFileIndexImpl implements ModuleFileIndex { myExclusionManager = ProjectFileExclusionManager.SERVICE.getInstance(module.getProject()); } + @Override public boolean iterateContent(@NotNull ContentIterator iterator) { VirtualFile[] contentRoots = ModuleRootManager.getInstance(myModule).getContentRoots(); for (VirtualFile contentRoot : contentRoots) { @@ -63,16 +64,19 @@ public class ModuleFileIndexImpl implements ModuleFileIndex { return true; } + @Override public boolean iterateContentUnderDirectory(@NotNull VirtualFile dir, @NotNull ContentIterator iterator) { return FileIndexImplUtil.iterateRecursively(dir, myContentFilter, iterator); } + @Override public boolean isContentSourceFile(@NotNull VirtualFile file) { return !file.isDirectory() && !myFileTypeRegistry.isFileIgnored(file) && isInSourceContent(file); } + @Override public boolean isInContent(@NotNull VirtualFile fileOrDir) { if (fileOrDir.isDirectory()) { DirectoryInfo info = myDirectoryIndex.getInfoForDirectory(fileOrDir); @@ -84,6 +88,7 @@ public class ModuleFileIndexImpl implements ModuleFileIndex { } } + @Override public boolean isInSourceContent(@NotNull VirtualFile fileOrDir) { if (fileOrDir.isDirectory()) { DirectoryInfo info = myDirectoryIndex.getInfoForDirectory(fileOrDir); @@ -95,6 +100,7 @@ public class ModuleFileIndexImpl implements ModuleFileIndex { } } + @Override @NotNull public List getOrderEntriesForFile(@NotNull VirtualFile fileOrDir) { VirtualFile dir = fileOrDir.isDirectory() ? fileOrDir : fileOrDir.getParent(); @@ -122,6 +128,7 @@ public class ModuleFileIndexImpl implements ModuleFileIndex { return answer == null ? Collections.emptyList() : answer; } + @Override public OrderEntry getOrderEntryForFile(@NotNull VirtualFile fileOrDir) { VirtualFile dir = fileOrDir.isDirectory() ? fileOrDir : fileOrDir.getParent(); if (dir == null) return null; @@ -136,6 +143,7 @@ public class ModuleFileIndexImpl implements ModuleFileIndex { return null; } + @Override public boolean isInTestSourceContent(@NotNull VirtualFile fileOrDir) { if (fileOrDir.isDirectory()) { DirectoryInfo info = myDirectoryIndex.getInfoForDirectory(fileOrDir); @@ -148,6 +156,7 @@ public class ModuleFileIndexImpl implements ModuleFileIndex { } private class ContentFilter implements VirtualFileFilter { + @Override public boolean accept(@NotNull VirtualFile file) { if (file.isDirectory()) { DirectoryInfo info = myDirectoryIndex.getInfoForDirectory(file); From a27975d8d785298b8eb54d7575fc6801589e18f7 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 29 May 2012 16:53:38 +0400 Subject: [PATCH 5/6] correct condition --- .../src/com/intellij/openapi/editor/impl/CaretModelImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index 1fff716c5b36..0f63981e6a38 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -110,7 +110,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, DocumentBulkUpdateListener bulkUpdateListener = new DocumentBulkUpdateListener() { @Override public void updateStarted(@NotNull Document doc) { - if (doc != myEditor.getDocument() && myOffset >= doc.getTextLength() || savedBeforeBulkCaretMarker != null) return; + if (doc != myEditor.getDocument() || myOffset >= doc.getTextLength() || savedBeforeBulkCaretMarker != null) return; savedBeforeBulkCaretMarker = doc.createRangeMarker(myOffset, myOffset); } @Override From 34c5ec9680cb42762eb144b08df5134ee8e88757 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 29 May 2012 18:49:46 +0400 Subject: [PATCH 6/6] cleanup --- .../impl/analysis/HighlightVisitorImpl.java | 2 +- .../openapi/editor/ex/DisposableIterator.java | 3 ++ .../openapi/editor/impl/IntervalTreeImpl.java | 52 ++++++++++++------- .../daemon/impl/DaemonCodeAnalyzerImpl.java | 4 +- .../daemon/impl/PassExecutorService.java | 10 ++-- .../editor/impl/RangeHighlighterTree.java | 5 +- 6 files changed, 47 insertions(+), 29 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 23d6ccbfc79b..445f04be73e3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -770,7 +770,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh doVisitReferenceElement(ref); } - private JavaResolveResult doVisitReferenceElement(PsiJavaCodeReferenceElement ref) { + private JavaResolveResult doVisitReferenceElement(@NotNull PsiJavaCodeReferenceElement ref) { JavaResolveResult result; try { result = ref.advancedResolve(true); diff --git a/platform/core-impl/src/com/intellij/openapi/editor/ex/DisposableIterator.java b/platform/core-impl/src/com/intellij/openapi/editor/ex/DisposableIterator.java index 2684ecadaae1..e2faf2415307 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/ex/DisposableIterator.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/ex/DisposableIterator.java @@ -18,6 +18,9 @@ package com.intellij.openapi.editor.ex; import java.util.Iterator; import java.util.NoSuchElementException; +/** + * An iterator you must to {@link #dispose()} after use + */ public interface DisposableIterator extends Iterator { void dispose(); DisposableIterator EMPTY = new DisposableIterator() { diff --git a/platform/core-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java b/platform/core-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java index bdf9b68045fc..73f8d26038d7 100644 --- a/platform/core-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java +++ b/platform/core-impl/src/com/intellij/openapi/editor/impl/IntervalTreeImpl.java @@ -317,6 +317,40 @@ public abstract class IntervalTreeImpl extends RedBla return (int)(packedOffsets >> 33); } + // finds previous in the in-order traversal + IntervalNode previous() { + IntervalNode left = getLeft(); + if (left != null) { + while (left.getRight() != null) { + left = left.getRight(); + } + return left; + } + IntervalNode parent = getParent(); + while (parent != null) { + if (parent.getRight() == this) break; + parent = parent.getParent(); + } + return parent; + } + + // finds next node in the in-order traversal + IntervalNode next() { + IntervalNode right = getRight(); + if (right != null) { + while (right.getLeft() != null) { + right = right.getLeft(); + } + return right; + } + IntervalNode parent = getParent(); + while (parent != null) { + if (parent.getLeft() == this) break; + parent = parent.getParent(); + } + return parent; + } + @NonNls @Override public String toString() { @@ -642,24 +676,6 @@ public abstract class IntervalTreeImpl extends RedBla return Math.max(start, startOffset) <= Math.min(end, endOffset); } - // finds previous in the in-order traversal - private IntervalNode previous(@NotNull IntervalNode node) { - IntervalNode left = node.getLeft(); - if (left != null) { - while (left.getRight() != null) { - left = left.getRight(); - } - return left; - } - IntervalNode parent = node.getParent(); - while (parent != null) { - if (parent.getRight() == node) break; - node = parent; - parent = parent.getParent(); - } - return parent; - } - protected IntervalNode findOrInsert(@NotNull IntervalNode node) { assertUnderWriteLock(); node.color = Color.RED; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java index 278856c59083..97ecca5aee4a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java @@ -26,7 +26,6 @@ import com.intellij.codeInsight.daemon.LineMarkerInfo; import com.intellij.codeInsight.daemon.ReferenceImporter; import com.intellij.codeInsight.hint.HintManager; import com.intellij.codeInsight.intention.impl.IntentionHintComponent; -import com.intellij.codeInspection.ex.InspectionProfileWrapper; import com.intellij.concurrency.Job; import com.intellij.ide.PowerSaveMode; import com.intellij.lang.annotation.HighlightSeverity; @@ -54,7 +53,6 @@ import com.intellij.openapi.util.*; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.packageDependencies.DependencyValidationManager; -import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.psi.PsiCompiledElement; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; @@ -234,7 +232,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx if (callbackWhileWaiting != null) { callbackWhileWaiting.run(); } - progress.waitFor(100); + progress.waitFor(50); UIUtil.dispatchAllInvocationEvents(); Throwable savedException = PassExecutorService.getSavedException(progress); if (savedException != null) throw savedException; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java index 2c4a5719db55..92ff1f1579f8 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java @@ -384,7 +384,7 @@ public abstract class PassExecutorService implements Disposable { log(myUpdateProgress, myPass, "Finished. "); if (!myUpdateProgress.isCanceled()) { - applyInformationToEditors(myFileEditors, myPass, myUpdateProgress, myThreadsToStartCountdown); + applyInformationToEditorsLater(myFileEditors, myPass, myUpdateProgress, myThreadsToStartCountdown); for (ScheduledPass successor : mySuccessorsOnCompletion) { int predecessorsToRun = successor.myRunningPredecessorsCount.decrementAndGet(); if (predecessorsToRun == 0) { @@ -401,10 +401,10 @@ public abstract class PassExecutorService implements Disposable { } } - private void applyInformationToEditors(@NotNull final List fileEditors, - @NotNull final TextEditorHighlightingPass pass, - @NotNull final DaemonProgressIndicator updateProgress, - @NotNull final AtomicInteger threadsToStartCountdown) { + private void applyInformationToEditorsLater(@NotNull final List fileEditors, + @NotNull final TextEditorHighlightingPass pass, + @NotNull final DaemonProgressIndicator updateProgress, + @NotNull final AtomicInteger threadsToStartCountdown) { final boolean testMode = ApplicationManager.getApplication().isUnitTestMode(); ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() { @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeHighlighterTree.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeHighlighterTree.java index cd0947bc871f..e6bb73d4e028 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeHighlighterTree.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/RangeHighlighterTree.java @@ -35,8 +35,9 @@ public class RangeHighlighterTree extends RangeMarkerTree { protected int compareEqualStartIntervals(@NotNull IntervalNode i1, @NotNull IntervalNode i2) { RHNode o1 = (RHNode)i1; RHNode o2 = (RHNode)i2; - if (o1.myLayer != o2.myLayer) { - return o2.myLayer - o1.myLayer; + int d = o2.myLayer - o1.myLayer; + if (d != 0) { + return d; } return super.compareEqualStartIntervals(i1, i2); }