From e7f246b594cbc83211de0c32f3742922de50fb9f Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Sun, 26 Apr 2020 23:52:25 +0300 Subject: [PATCH] Let general HighlightingPasses (i.e. not TextEditorHighlightingPass-derived) run in parallel to other passes since they are not dependent on anything. Make document notnull as by-product GitOrigin-RevId: 7f478ae9a7cf1396276888991a5c3d29d8a9c755 --- .../impl/JavaSoftKeywordHighlighting.kt | 2 +- .../hints/ElementProcessingHintPass.kt | 1 - .../impl/DaemonRespondToChangesTest.java | 2 +- .../TextEditorHighlightingPass.java | 26 ++- .../daemon/impl/GeneralHighlightingPass.java | 7 - ...rogressableTextEditorHighlightingPass.java | 8 +- .../daemon/impl/DaemonCodeAnalyzerImpl.java | 21 +-- .../impl/IdentifierHighlighterPass.java | 4 +- .../codeInsight/daemon/impl/IndentsPass.java | 6 - .../daemon/impl/LineMarkersPass.java | 7 - .../daemon/impl/LocalInspectionsPass.java | 2 +- .../impl/LocalInspectionsPassFactory.java | 2 +- .../daemon/impl/PassExecutorService.java | 153 ++++++------------ .../daemon/impl/TrafficLightRenderer.java | 51 +++--- .../daemon/impl/TrafficProgressPanel.java | 2 +- .../render/DocRenderPassFactory.java | 3 +- .../codeInsight/hints/ParameterHintsPass.java | 5 +- .../ex/GlobalInspectionContextImpl.java | 2 +- .../TestDataHighlightingPass.java | 29 ++-- .../TestDataHighlightingPassFactory.java | 7 +- .../annotator/GrReferenceHighlighter.java | 5 +- .../GrReferenceHighlighterFactory.java | 2 +- .../plugins/groovy/highlighter/util.kt | 2 +- .../highlighting/DomElementsErrorPanel.java | 3 +- .../XmlTagTreeHighlightingPass.java | 6 +- 25 files changed, 132 insertions(+), 226 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/JavaSoftKeywordHighlighting.kt b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/JavaSoftKeywordHighlighting.kt index ef9a3f0293d6..366b8bf9e804 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/JavaSoftKeywordHighlighting.kt +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/JavaSoftKeywordHighlighting.kt @@ -36,7 +36,7 @@ private class JavaSoftKeywordHighlightingPass(private val file: PsiJavaFile, doc } override fun doApplyInformationToEditor() { - UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument!!, 0, file.textLength, results, colorsScheme, id) + UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, file.textLength, results, colorsScheme, id) } } diff --git a/java/java-impl/src/com/intellij/codeInsight/hints/ElementProcessingHintPass.kt b/java/java-impl/src/com/intellij/codeInsight/hints/ElementProcessingHintPass.kt index 1d00c56215fc..8e92530df899 100644 --- a/java/java-impl/src/com/intellij/codeInsight/hints/ElementProcessingHintPass.kt +++ b/java/java-impl/src/com/intellij/codeInsight/hints/ElementProcessingHintPass.kt @@ -25,7 +25,6 @@ abstract class ElementProcessingHintPass( private val hints = TIntObjectHashMap>() override fun doCollectInformation(progress: ProgressIndicator) { - assert(myDocument != null) hints.clear() val virtualFile = rootElement.containingFile?.originalFile?.virtualFile ?: return diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java index 06f0bb92903a..72faf029ea6e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java @@ -1589,7 +1589,7 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase { if (errorDescription.equals(description)) { errorRemoved[0] = true; - List passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document); + List passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document); GeneralHighlightingPass ghp = null; for (TextEditorHighlightingPass pass : passes) { if (pass instanceof GeneralHighlightingPass && pass.getId() == Pass.UPDATE_ALL) { diff --git a/platform/analysis-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java b/platform/analysis-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java index 58a2330376a2..295bdc612d46 100644 --- a/platform/analysis-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java +++ b/platform/analysis-impl/src/com/intellij/codeHighlighting/TextEditorHighlightingPass.java @@ -22,8 +22,10 @@ import java.util.List; public abstract class TextEditorHighlightingPass implements HighlightingPass { public static final TextEditorHighlightingPass[] EMPTY_ARRAY = new TextEditorHighlightingPass[0]; - @Nullable protected final Document myDocument; - @NotNull protected final Project myProject; + @NotNull + protected final Document myDocument; + @NotNull + protected final Project myProject; private final boolean myRunIntentionPassAfter; private final long myInitialDocStamp; private final long myInitialPsiStamp; @@ -33,14 +35,14 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass { private volatile boolean myDumb; private EditorColorsScheme myColorsScheme; - protected TextEditorHighlightingPass(@NotNull final Project project, @Nullable final Document document, boolean runIntentionPassAfter) { + protected TextEditorHighlightingPass(@NotNull final Project project, @NotNull final Document document, boolean runIntentionPassAfter) { myDocument = document; myProject = project; myRunIntentionPassAfter = runIntentionPassAfter; - myInitialDocStamp = document == null ? 0 : document.getModificationStamp(); + myInitialDocStamp = document.getModificationStamp(); myInitialPsiStamp = PsiModificationTracker.SERVICE.getInstance(myProject).getModificationCount(); } - protected TextEditorHighlightingPass(@NotNull final Project project, @Nullable final Document document) { + protected TextEditorHighlightingPass(@NotNull final Project project, @NotNull Document document) { this(project, document, true); } @@ -74,13 +76,9 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass { return false; } - if (myDocument != null) { - if (myDocument.getModificationStamp() != myInitialDocStamp) return false; - PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); - return file != null && file.isValid(); - } - - return true; + if (myDocument.getModificationStamp() != myInitialDocStamp) return false; + PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument); + return file != null && file.isValid(); } @Override @@ -88,7 +86,7 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass { if (!isValid()) return; // Document has changed. if (DumbService.getInstance(myProject).isDumb() && !DumbService.isDumbAware(this)) { Document document = getDocument(); - PsiFile file = document == null ? null : PsiDocumentManager.getInstance(myProject).getPsiFile(document); + PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document); if (file != null) { DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap().markFileUpToDate(getDocument(), getId()); } @@ -121,7 +119,7 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass { myCompletionPredecessorIds = completionPredecessorIds; } - @Nullable + @NotNull public Document getDocument() { return myDocument; } 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 ddc9797e2ab4..18356ec16f97 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 @@ -100,13 +100,6 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP return myFile; } - @Override - public @NotNull Document getDocument() { - // this pass always get not-null document - //noinspection ConstantConditions - return super.getDocument(); - } - private static final Key HIGHLIGHT_VISITOR_INSTANCE_COUNT = new Key<>("HIGHLIGHT_VISITOR_INSTANCE_COUNT"); private HighlightVisitor @NotNull [] cloneHighlightVisitors() { int oldCount = incVisitorUsageCount(1); diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java index 481354eec45a..8cc4c371b5e3 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java @@ -48,7 +48,7 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH HighlightingSession myHighlightingSession; protected ProgressableTextEditorHighlightingPass(@NotNull Project project, - @Nullable final Document document, + @NotNull final Document document, @NotNull String presentableName, @Nullable PsiFile file, @Nullable Editor editor, @@ -77,8 +77,8 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH GlobalInspectionContextBase.assertUnderDaemonProgress(); myFinished = false; if (myFile != null) { - myHighlightingSession = - HighlightingSessionImpl.getOrCreateHighlightingSession(myFile, (DaemonProgressIndicator)ProgressWrapper.unwrapAll(progress), getColorsScheme()); + DaemonProgressIndicator daemonProgressIndicator = (DaemonProgressIndicator)ProgressWrapper.unwrapAll(progress); + myHighlightingSession = HighlightingSessionImpl.getOrCreateHighlightingSession(myFile, daemonProgressIndicator, getColorsScheme()); } try { collectInformationWithProgress(progress); @@ -161,7 +161,7 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH } static class EmptyPass extends TextEditorHighlightingPass { - EmptyPass(final Project project, @Nullable final Document document) { + EmptyPass(@NotNull Project project, @NotNull Document document) { super(project, document, false); } 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 bccf925f9c5e..4623ec694d5b 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 @@ -47,7 +47,10 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.RefreshQueueImpl; import com.intellij.packageDependencies.DependencyValidationManager; -import com.intellij.psi.*; +import com.intellij.psi.FileViewProvider; +import com.intellij.psi.PsiCompiledElement; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.*; @@ -546,15 +549,13 @@ public final class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implement } @NotNull - public List getPassesToShowProgressFor(Document document) { - List allPasses = myPassExecutorService.getAllSubmittedPasses(); - List result = new ArrayList<>(allPasses.size()); - for (TextEditorHighlightingPass pass : allPasses) { - if (pass.getDocument() == document || pass.getDocument() == null) { - result.add(pass); - } - } - return result; + public List getPassesToShowProgressFor(@NotNull Document document) { + List allPasses = myPassExecutorService.getAllSubmittedPasses(); + return allPasses.stream() + .map(p->p instanceof ProgressableTextEditorHighlightingPass ? (ProgressableTextEditorHighlightingPass)p : null) + .filter(p-> p != null && p.getDocument() == document) + .sorted(Comparator.comparingInt(p->p.getId())) + .collect(Collectors.toList()); } boolean isAllAnalysisFinished(@NotNull PsiFile file) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPass.java index 3dd55516751f..c68635df0175 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlighterPass.java @@ -328,9 +328,7 @@ public class IdentifierHighlighterPass extends TextEditorHighlightingPass { * In brace matching case this is done from {@link BraceHighlightingHandler#highlightBraces(com.intellij.openapi.util.TextRange, com.intellij.openapi.util.TextRange, boolean, boolean, com.intellij.openapi.fileTypes.FileType)} */ private void doAdditionalCodeBlockHighlighting() { - if (myCodeBlockMarkerRanges.size() < 2 || - myDocument == null || - !(myEditor instanceof EditorEx)) { + if (myCodeBlockMarkerRanges.size() < 2 || !(myEditor instanceof EditorEx)) { return; } ArrayList markers = new ArrayList<>(myCodeBlockMarkerRanges); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java index 728308995e8d..fffdb07be134 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IndentsPass.java @@ -183,7 +183,6 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware @Override public void doCollectInformation(@NotNull ProgressIndicator progress) { - assert myDocument != null; final Long stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT); if (stamp != null && stamp.longValue() == nowStamp()) return; @@ -203,7 +202,6 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware private long nowStamp() { if (!myEditor.getSettings().isIndentGuidesShown()) return -1; - assert myDocument != null; // include tab size into stamp to make sure indent guides are recalculated on tab size change return myDocument.getModificationStamp() ^ (((long)getTabSize()) << 24); } @@ -257,7 +255,6 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware } final int startRangeIndex = curRange; - assert myDocument != null; DocumentUtil.executeInBulk(myDocument, myRanges.size() > 10000, () -> { for (int i = startRangeIndex; i < myRanges.size(); i++) { newHighlighters.add(createHighlighter(mm, myRanges.get(i))); @@ -282,7 +279,6 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware lines.push(0); indents.push(0); - assert myDocument != null; List descriptors = new ArrayList<>(); for (int line = 1; line < lineIndents.length; line++) { ProgressManager.checkCanceled(); @@ -371,7 +367,6 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware @NotNull final CharSequence myChars; IndentsCalculator() { - assert myDocument != null; lineIndents = new int[myDocument.getLineCount()]; myChars = myDocument.getCharsSequence(); } @@ -380,7 +375,6 @@ public class IndentsPass extends TextEditorHighlightingPass implements DumbAware * Calculates line indents for the {@link #myDocument target document}. */ void calculate() { - assert myDocument != null; final FileType fileType = myFile.getFileType(); int tabSize = getTabSize(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPass.java index dd287424eeb4..6be6c03e8788 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPass.java @@ -63,13 +63,6 @@ public class LineMarkersPass extends TextEditorHighlightingPass { myRestrictRange = restrictRange; } - @NotNull - @Override - public Document getDocument() { - //noinspection ConstantConditions - return super.getDocument(); - } - @Override public void doApplyInformationToEditor() { try { 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 abb9d4810494..1d3b72e2dc53 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 @@ -72,7 +72,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass private final boolean myInspectInjectedPsi; public LocalInspectionsPass(@NotNull PsiFile file, - @Nullable Document document, + @NotNull Document document, int startOffset, int endOffset, @NotNull TextRange priorityRange, diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java index 8162cd183c3c..6f2ae4e78333 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java @@ -47,7 +47,7 @@ public final class LocalInspectionsPassFactory implements MainHighlightingPassFa private static class MyLocalInspectionsPass extends LocalInspectionsPass { private MyLocalInspectionsPass(@NotNull PsiFile file, - Document document, + @NotNull Document document, @NotNull TextRange textRange, @NotNull TextRange visibleRange, @NotNull HighlightInfoProcessor highlightInfoProcessor) { 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 e8593e60d4b7..1419b9785090 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 @@ -2,10 +2,12 @@ package com.intellij.codeInsight.daemon.impl; -import com.intellij.codeHighlighting.*; +import com.intellij.codeHighlighting.EditorBoundHighlightingPass; +import com.intellij.codeHighlighting.HighlightingPass; +import com.intellij.codeHighlighting.TextEditorHighlightingPass; +import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar; import com.intellij.concurrency.Job; import com.intellij.concurrency.JobLauncher; -import com.intellij.injected.editor.EditorWindow; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ex.ApplicationManagerEx; @@ -38,7 +40,6 @@ import gnu.trove.THashMap; import gnu.trove.TIntObjectHashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import java.util.*; @@ -95,34 +96,22 @@ final class PassExecutorService implements Disposable { void submitPasses(@NotNull Map passesMap, @NotNull DaemonProgressIndicator updateProgress) { if (isDisposed()) return; + ApplicationManager.getApplication().assertIsDispatchThread(); // null keys are ok MultiMap documentToEditors = MultiMap.createSet(); MultiMap documentBoundPasses = MultiMap.createSmart(); MultiMap editorBoundPasses = MultiMap.createSmart(); - List> passesWithNoDocuments = new ArrayList<>(); Map> id2Pass = new THashMap<>(); - Set vFiles = new HashSet<>(); + List freePasses = new ArrayList<>(documentToEditors.size() * 5); + AtomicInteger threadsToStartCountdown = new AtomicInteger(0); + for (Map.Entry entry : passesMap.entrySet()) { FileEditor fileEditor = entry.getKey(); HighlightingPass[] passes = entry.getValue(); - Document document; - if (fileEditor instanceof TextEditor) { - Editor editor = ((TextEditor)fileEditor).getEditor(); - LOG.assertTrue(!(editor instanceof EditorWindow)); - document = editor.getDocument(); - } - else { - VirtualFile virtualFile = ((FileEditorManagerEx)FileEditorManager.getInstance(myProject)).getFile(fileEditor); - document = virtualFile == null ? null : FileDocumentManager.getInstance().getDocument(virtualFile); - } - if (document != null) { - vFiles.add(FileDocumentManager.getInstance().getFile(document)); - } - int prevId = 0; - for (final HighlightingPass pass : passes) { + for (HighlightingPass pass : passes) { TIntObjectHashMap thisEditorId2Pass = id2Pass.computeIfAbsent(fileEditor, __ -> new TIntObjectHashMap<>(20)); if (pass instanceof EditorBoundHighlightingPass) { EditorBoundHighlightingPass editorPass = (EditorBoundHighlightingPass)pass; @@ -132,35 +121,26 @@ final class PassExecutorService implements Disposable { editorBoundPasses.putValue(fileEditor, editorPass); } else { - TextEditorHighlightingPass convertedPass; + TextEditorHighlightingPass tePass; if (pass instanceof TextEditorHighlightingPass) { - convertedPass = (TextEditorHighlightingPass)pass; + tePass = (TextEditorHighlightingPass)pass; + + checkUniquePassId(tePass.getId(), tePass, thisEditorId2Pass); + documentBoundPasses.putValue(fileEditor, tePass); + documentToEditors.putValue(tePass.getDocument(), fileEditor); } else { - // run all passes in sequence - convertedPass = convertToTextHighlightingPass(pass, document, prevId); - convertedPass.setId(nextAvailablePassId.incrementAndGet()); + // generic HighlightingPass, run all of them concurrently + freePasses.add(new ScheduledPass(fileEditor, pass, updateProgress, threadsToStartCountdown)); } - checkUniquePassId(convertedPass.getId(), convertedPass, thisEditorId2Pass); - document = convertedPass.getDocument(); - documentBoundPasses.putValue(fileEditor, convertedPass); - if (document == null) { - passesWithNoDocuments.add(Pair.create(fileEditor, convertedPass)); - } - else { - documentToEditors.putValue(document, fileEditor); - } - prevId = convertedPass.getId(); } } } - List freePasses = new ArrayList<>(documentToEditors.size() * 5); List dependentPasses = new ArrayList<>(documentToEditors.size() * 10); // fileEditor-> (passId -> created pass) Map> toBeSubmitted = new THashMap<>(passesMap.size()); - final AtomicInteger threadsToStartCountdown = new AtomicInteger(0); for (Map.Entry> entry : documentToEditors.entrySet()) { Collection fileEditors = entry.getValue(); Document document = entry.getKey(); @@ -183,17 +163,15 @@ final class PassExecutorService implements Disposable { } } - for (Pair pair : passesWithNoDocuments) { - FileEditor fileEditor = pair.first; - TextEditorHighlightingPass pass = pair.second; - createScheduledPass(fileEditor, pass, toBeSubmitted, id2Pass, freePasses, dependentPasses, updateProgress, threadsToStartCountdown); - } - if (CHECK_CONSISTENCY && !ApplicationInfoImpl.isInStressTest()) { assertConsistency(freePasses, toBeSubmitted, threadsToStartCountdown); } - log(updateProgress, null, vFiles + " ----- starting " + threadsToStartCountdown.get(), freePasses); + if (LOG.isDebugEnabled()) { + Set vFiles = ContainerUtil.map2Set(passesMap.keySet(), fe -> ((FileEditorManagerEx)FileEditorManager.getInstance(myProject)).getFile(fe)); + + log(updateProgress, null, vFiles + " ----- starting " + threadsToStartCountdown.get(), freePasses); + } for (ScheduledPass dependentPass : dependentPasses) { mySubmittedPasses.put(dependentPass, Job.nullJob()); @@ -218,8 +196,11 @@ final class PassExecutorService implements Disposable { assert threadsToStartCountdown.get() == toBeSubmitted.values().stream().mapToInt(m->m.size()).sum(); TIntObjectHashMap> id2Visits = new TIntObjectHashMap<>(); for (ScheduledPass freePass : freePasses) { - id2Visits.put(freePass.myPass.getId(), Pair.create(freePass, 0)); - checkConsistency(freePass, id2Visits); + HighlightingPass pass = freePass.myPass; + if (pass instanceof TextEditorHighlightingPass) { + id2Visits.put(((TextEditorHighlightingPass)pass).getId(), Pair.create(freePass, 0)); + checkConsistency(freePass, id2Visits); + } } id2Visits.forEachEntry((id, pair) -> { int count = pair.second; @@ -231,7 +212,7 @@ final class PassExecutorService implements Disposable { private void checkConsistency(@NotNull ScheduledPass pass, @NotNull TIntObjectHashMap> id2Visits) { for (ScheduledPass succ : ContainerUtil.concat(pass.mySuccessorsOnCompletion, pass.mySuccessorsOnSubmit)) { - int succId = succ.myPass.getId(); + int succId = ((TextEditorHighlightingPass)succ.myPass).getId(); Pair succPair = id2Visits.get(succId); if (succPair == null) { succPair = Pair.create(succ, succ.myRunningPredecessorsCount.get()); @@ -247,48 +228,17 @@ final class PassExecutorService implements Disposable { } @NotNull - private TextEditorHighlightingPass convertToTextHighlightingPass(@NotNull HighlightingPass pass, - @Nullable Document document, - int previousPassId) { - TextEditorHighlightingPass textEditorHighlightingPass; - textEditorHighlightingPass = new TextEditorHighlightingPass(myProject, document, true) { - @Override - public void doCollectInformation(@NotNull ProgressIndicator progress) { - pass.collectInformation(progress); - } - - @Override - public void doApplyInformationToEditor() { - pass.applyInformationToEditor(); - if (document != null) { - VirtualFile file = FileDocumentManager.getInstance().getFile(document); - FileEditor[] editors = file == null ? FileEditor.EMPTY_ARRAY : FileEditorManager.getInstance(myProject).getEditors(file); - for (FileEditor editor : editors) { - repaintErrorStripeAndIcon(editor); - } - } - } - }; - if (previousPassId != 0) { - textEditorHighlightingPass.setCompletionPredecessorIds(new int[]{previousPassId}); - } - return textEditorHighlightingPass; - } - - @NotNull - private FileEditor getPreferredFileEditor(Document document, @NotNull Collection fileEditors) { + private FileEditor getPreferredFileEditor(@NotNull Document document, @NotNull Collection fileEditors) { assert !fileEditors.isEmpty(); - if (document != null) { - FileEditor focusedEditor = ContainerUtil.find(fileEditors, it -> it instanceof TextEditor && - ((TextEditor)it).getEditor().getContentComponent().isFocusOwner()); - if (focusedEditor != null) return focusedEditor; + FileEditor focusedEditor = ContainerUtil.find(fileEditors, it -> it instanceof TextEditor && + ((TextEditor)it).getEditor().getContentComponent().isFocusOwner()); + if (focusedEditor != null) return focusedEditor; - final VirtualFile file = FileDocumentManager.getInstance().getFile(document); - if (file != null) { - final FileEditor selected = FileEditorManager.getInstance(myProject).getSelectedEditor(file); - if (selected != null && fileEditors.contains(selected)) { - return selected; - } + final VirtualFile file = FileDocumentManager.getInstance().getFile(document); + if (file != null) { + final FileEditor selected = FileEditorManager.getInstance(myProject).getSelectedEditor(file); + if (selected != null && fileEditors.contains(selected)) { + return selected; } } return fileEditors.iterator().next(); @@ -340,7 +290,7 @@ final class PassExecutorService implements Disposable { int id = nextAvailablePassId.incrementAndGet(); ip.setId(id); checkUniquePassId(id, ip, thisEditorId2Pass); - ip.setCompletionPredecessorIds(new int[]{scheduledPass.myPass.getId()}); + ip.setCompletionPredecessorIds(new int[]{passId}); createScheduledPass(fileEditor, ip, toBeSubmitted, id2Pass, freePasses, dependentPasses, updateProgress, threadsToStartCountdown); } @@ -388,7 +338,7 @@ final class PassExecutorService implements Disposable { private class ScheduledPass implements Runnable { private final FileEditor myFileEditor; - private final TextEditorHighlightingPass myPass; + private final HighlightingPass myPass; private final AtomicInteger myThreadsToStartCountdown; private final AtomicInteger myRunningPredecessorsCount = new AtomicInteger(0); private final List mySuccessorsOnCompletion = new ArrayList<>(); @@ -396,7 +346,7 @@ final class PassExecutorService implements Disposable { @NotNull private final DaemonProgressIndicator myUpdateProgress; private ScheduledPass(@NotNull FileEditor fileEditor, - @NotNull TextEditorHighlightingPass pass, + @NotNull HighlightingPass pass, @NotNull DaemonProgressIndicator progressIndicator, @NotNull AtomicInteger threadsToStartCountdown) { myFileEditor = fileEditor; @@ -495,7 +445,7 @@ final class PassExecutorService implements Disposable { } private void applyInformationToEditorsLater(@NotNull final FileEditor fileEditor, - @NotNull final TextEditorHighlightingPass pass, + @NotNull final HighlightingPass pass, @NotNull final DaemonProgressIndicator updateProgress, @NotNull final AtomicInteger threadsToStartCountdown, @NotNull Runnable callbackOnApplied) { @@ -507,15 +457,16 @@ final class PassExecutorService implements Disposable { log(updateProgress, pass, " is canceled during apply, sorry"); return; } - Document document = pass.getDocument(); try { if (fileEditor instanceof TextEditor && EditorActivityManager.getInstance().isVisible(((TextEditor)fileEditor).getEditor()) || fileEditor.getComponent().isDisplayable()) { pass.applyInformationToEditor(); repaintErrorStripeAndIcon(fileEditor); - FileStatusMap fileStatusMap = DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap(); - if (document != null) { - fileStatusMap.markFileUpToDate(document, pass.getId()); + if (pass instanceof TextEditorHighlightingPass) { + FileStatusMap fileStatusMap = DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap(); + Document document = ((TextEditorHighlightingPass)pass).getDocument(); + int passId = ((TextEditorHighlightingPass)pass).getId(); + fileStatusMap.markFileUpToDate(document, passId); } log(updateProgress, pass, " Applied"); } @@ -525,7 +476,7 @@ final class PassExecutorService implements Disposable { throw e; } catch (RuntimeException e) { - VirtualFile file = document == null ? null : FileDocumentManager.getInstance().getFile(document); + VirtualFile file = FileEditorManagerEx.getInstanceEx(myProject).getFile(fileEditor); FileType fileType = file == null ? null : file.getFileType(); String message = "Exception while applying information to " + fileEditor + "("+fileType+")"; log(updateProgress, pass, message + e); @@ -559,14 +510,13 @@ final class PassExecutorService implements Disposable { } @NotNull - List getAllSubmittedPasses() { - List result = new ArrayList<>(mySubmittedPasses.size()); + List getAllSubmittedPasses() { + List result = new ArrayList<>(mySubmittedPasses.size()); for (ScheduledPass scheduledPass : mySubmittedPasses.keySet()) { if (!scheduledPass.myUpdateProgress.isCanceled()) { result.add(scheduledPass.myPass); } } - sortById(result); return result; } @@ -580,9 +530,10 @@ final class PassExecutorService implements Disposable { return StringUtil.parseInt(num, 0); } - static void log(ProgressIndicator progressIndicator, TextEditorHighlightingPass pass, @NonNls Object @NotNull ... info) { + static void log(ProgressIndicator progressIndicator, HighlightingPass pass, @NonNls Object @NotNull ... info) { if (LOG.isDebugEnabled()) { - CharSequence docText = pass == null || pass.getDocument() == null ? "" : ": '" + StringUtil.first(pass.getDocument().getCharsSequence(), 10, true)+ "'"; + Document document = pass instanceof TextEditorHighlightingPass ? ((TextEditorHighlightingPass)pass).getDocument() : null; + CharSequence docText = document == null ? "" : ": '" + StringUtil.first(document.getCharsSequence(), 10, true)+ "'"; synchronized (PassExecutorService.class) { String infos = StringUtil.join(info, Functions.TO_STRING(), " "); String message = StringUtil.repeatSymbol(' ', getThreadNum() * 4) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.java index 29fefdd731a2..03560b02776e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.java @@ -65,6 +65,7 @@ import java.util.stream.Collectors; public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable { @NotNull private final Project myProject; + @NotNull private final Document myDocument; private final DaemonCodeAnalyzerImpl myDaemonCodeAnalyzer; private final SeverityRegistrar mySeverityRegistrar; @@ -94,7 +95,7 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable { DeprecatedMethodException.report("Please use TrafficLightRenderer(Project, Document) instead"); } - public TrafficLightRenderer(@NotNull Project project, @Nullable Document document) { + public TrafficLightRenderer(@NotNull Project project, @NotNull Document document) { myProject = project; myDaemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project); myDocument = document; @@ -102,25 +103,23 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable { refresh(null); - if (document != null) { - final MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); - model.addMarkupModelListener(this, new MarkupModelListener() { - @Override - public void afterAdded(@NotNull RangeHighlighterEx highlighter) { - incErrorCount(highlighter, 1); - } + final MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); + model.addMarkupModelListener(this, new MarkupModelListener() { + @Override + public void afterAdded(@NotNull RangeHighlighterEx highlighter) { + incErrorCount(highlighter, 1); + } - @Override - public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) { - incErrorCount(highlighter, -1); - } - }); - UIUtil.invokeLaterIfNeeded(() -> { - for (RangeHighlighter rangeHighlighter : model.getAllHighlighters()) { - incErrorCount(rangeHighlighter, 1); - } - }); - } + @Override + public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) { + incErrorCount(highlighter, -1); + } + }); + UIUtil.invokeLaterIfNeeded(() -> { + for (RangeHighlighter rangeHighlighter : model.getAllHighlighters()) { + incErrorCount(rangeHighlighter, 1); + } + }); } private PsiFile getPsiFile() { @@ -154,7 +153,7 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable { } public boolean isValid() { - return myDocument == null || getPsiFile() != null; + return getPsiFile() != null; } protected static final class DaemonCodeAnalyzerStatus { @@ -250,12 +249,8 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable { status.errorCount = errorCount.clone(); - status.passes = ContainerUtil.mapNotNull(myDaemonCodeAnalyzer.getPassesToShowProgressFor(myDocument), pass-> { - if (!(pass instanceof ProgressableTextEditorHighlightingPass)) return null; - ProgressableTextEditorHighlightingPass p = (ProgressableTextEditorHighlightingPass)pass; - if (StringUtil.isEmpty(p.getPresentableName()) || p.getProgress() < 0) return null; - return p; - }); + status.passes = ContainerUtil.filter(myDaemonCodeAnalyzer.getPassesToShowProgressFor(myDocument), + p -> !StringUtil.isEmpty(p.getPresentableName()) && p.getProgress() >= 0); status.errorAnalyzingFinished = myDaemonCodeAnalyzer.isAllAnalysisFinished(psiFile); status.reasonWhySuspended = myDaemonCodeAnalyzer.isUpdateByTimerEnabled() ? null : "Highlighting is paused temporarily"; @@ -429,7 +424,7 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable { } } - if (statusItems.size() > 0) { + if (!statusItems.isEmpty()) { if (mainIcon == null) { mainIcon = AllIcons.General.InspectionsOK; } @@ -484,7 +479,7 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable { private final List myLevelsList; private final List myAdditionalPanels; - protected AbstractUIController() { + AbstractUIController() { PsiFile psiFile = getPsiFile(); if (psiFile != null) { ProjectFileIndex fileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficProgressPanel.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficProgressPanel.java index d2919165b60e..34a4f9a6feff 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficProgressPanel.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficProgressPanel.java @@ -64,7 +64,7 @@ class TrafficProgressPanel extends JPanel { fakeStatusLargeEnough.passes = new ArrayList<>(); for (int i = 0; i < 3; i++) { fakeStatusLargeEnough.passes - .add(new ProgressableTextEditorHighlightingPass(project, null, DaemonBundle.message("pass.wolf"), psiFile, editor, TextRange.EMPTY_RANGE, false, + .add(new ProgressableTextEditorHighlightingPass(project, editor.getDocument(), DaemonBundle.message("pass.wolf"), psiFile, editor, TextRange.EMPTY_RANGE, false, HighlightInfoProcessor.getEmpty()) { @Override protected void collectInformationWithProgress(@NotNull ProgressIndicator progress) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/render/DocRenderPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/render/DocRenderPassFactory.java index 41a15d2aa193..db4622fca893 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/render/DocRenderPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/render/DocRenderPassFactory.java @@ -25,7 +25,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Objects; public class DocRenderPassFactory implements TextEditorHighlightingPassFactoryRegistrar, TextEditorHighlightingPassFactory, DumbAware { private static final Logger LOG = Logger.getInstance(DocRenderPassFactory.class); @@ -62,7 +61,7 @@ public class DocRenderPassFactory implements TextEditorHighlightingPassFactoryRe @Override public void doCollectInformation(@NotNull ProgressIndicator progress) { - items = calculateItemsToRender(Objects.requireNonNull(myDocument), myFile); + items = calculateItemsToRender(myDocument, myFile); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPass.java index 37a9fd7d7b05..deec340e889f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPass.java @@ -56,7 +56,6 @@ public class ParameterHintsPass extends EditorBoundHighlightingPass { @Override public void doCollectInformation(@NotNull ProgressIndicator progress) { - assert myDocument != null; myHints.clear(); Language language = myFile.getLanguage(); @@ -135,8 +134,6 @@ public class ParameterHintsPass extends EditorBoundHighlightingPass { @NotNull private List hintsInRootElementArea(ParameterHintsPresentationManager manager) { - assert myDocument != null; - TextRange range = myRootElement.getTextRange(); int elementStart = range.getStartOffset(); int elementEnd = range.getEndOffset(); @@ -163,7 +160,7 @@ public class ParameterHintsPass extends EditorBoundHighlightingPass { if (!rootRange.containsOffset(offset)) return false; if (offset > rootRange.getStartOffset() && offset < rootRange.getEndOffset()) return true; - return myDocument != null && myDocument.getTextLength() == rootRange.getLength(); + return myDocument.getTextLength() == rootRange.getLength(); } static class HintData { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index f28a356ebb3e..ad97b32dd1dd 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -804,7 +804,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextEx { if (!lTools.isEmpty()) { try { - final LocalInspectionsPass pass = new LocalInspectionsPass(file, PsiDocumentManager.getInstance(getProject()).getDocument(file), range != null ? range.getStartOffset() : 0, + final LocalInspectionsPass pass = new LocalInspectionsPass(file, file.getViewProvider().getDocument(), range != null ? range.getStartOffset() : 0, range != null ? range.getEndOffset() : file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true, HighlightInfoProcessor.getEmpty(), true); Runnable runnable = () -> pass.doInspectInBatch(GlobalInspectionContextImpl.this, InspectionManager.getInstance(getProject()), lTools); diff --git a/plugins/devkit/devkit-core/src/testAssistant/TestDataHighlightingPass.java b/plugins/devkit/devkit-core/src/testAssistant/TestDataHighlightingPass.java index e9b8f3a961b8..c277de879134 100644 --- a/plugins/devkit/devkit-core/src/testAssistant/TestDataHighlightingPass.java +++ b/plugins/devkit/devkit-core/src/testAssistant/TestDataHighlightingPass.java @@ -26,7 +26,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.util.ui.PlatformColors; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -43,7 +42,7 @@ public class TestDataHighlightingPass extends TextEditorHighlightingPass { private static final TextAttributes CARET_ATTRIBUTES = new TextAttributes(PlatformColors.BLUE, null, null, null, Font.BOLD); private static final String CARET = ""; - protected TestDataHighlightingPass(@NotNull final Project project, @Nullable final Document document) { + protected TestDataHighlightingPass(@NotNull final Project project, @NotNull final Document document) { super(project, document); } @@ -55,30 +54,22 @@ public class TestDataHighlightingPass extends TextEditorHighlightingPass { public void doApplyInformationToEditor() { removeHighlighters(); - if (myDocument == null) { - return; - } final MarkupModel model = DocumentMarkupModel.forDocument(myDocument, myProject, true); final String text = myDocument.getText(); - if (text != null) { - int ind = -1; - while ((ind = text.indexOf(CARET, ind + 1)) >= 0) { - final RangeHighlighter highlighter = model.addRangeHighlighter(ind, - ind + CARET.length(), - HighlighterLayer.ADDITIONAL_SYNTAX, - CARET_ATTRIBUTES, - HighlighterTargetArea.EXACT_RANGE); - highlighter.setGutterIconRenderer(ICON_RENDERER); - highlighter.putUserData(KEY, VALUE); - } + int ind = -1; + while ((ind = text.indexOf(CARET, ind + 1)) >= 0) { + final RangeHighlighter highlighter = model.addRangeHighlighter(ind, + ind + CARET.length(), + HighlighterLayer.ADDITIONAL_SYNTAX, + CARET_ATTRIBUTES, + HighlighterTargetArea.EXACT_RANGE); + highlighter.setGutterIconRenderer(ICON_RENDERER); + highlighter.putUserData(KEY, VALUE); } } private void removeHighlighters() { - if (myDocument == null) { - return; - } final MarkupModel model = DocumentMarkupModel.forDocument(myDocument, myProject, true); for (RangeHighlighter highlighter : model.getAllHighlighters()) { if (highlighter.getUserData(KEY) == VALUE) { diff --git a/plugins/devkit/devkit-core/src/testAssistant/TestDataHighlightingPassFactory.java b/plugins/devkit/devkit-core/src/testAssistant/TestDataHighlightingPassFactory.java index c5ef64e65fff..65e98db3b6ed 100644 --- a/plugins/devkit/devkit-core/src/testAssistant/TestDataHighlightingPassFactory.java +++ b/plugins/devkit/devkit-core/src/testAssistant/TestDataHighlightingPassFactory.java @@ -6,13 +6,13 @@ import com.intellij.codeHighlighting.TextEditorHighlightingPassFactory; import com.intellij.codeHighlighting.TextEditorHighlightingPassFactoryRegistrar; import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar; import com.intellij.ide.scratch.ScratchUtil; +import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -39,8 +39,9 @@ final class TestDataHighlightingPassFactory implements TextEditorHighlightingPas final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile != null) { Project project = file.getProject(); - if (isSupported(virtualFile, project)) { - return new TestDataHighlightingPass(project, PsiDocumentManager.getInstance(project).getDocument(file)); + Document document = file.getViewProvider().getDocument(); + if (isSupported(virtualFile, project) && document != null) { + return new TestDataHighlightingPass(project, document); } } return null; diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighter.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighter.java index 54de61be5d50..046318b2e7b6 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighter.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighter.java @@ -7,7 +7,6 @@ import com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil; import com.intellij.openapi.editor.Document; import com.intellij.openapi.progress.ProgressIndicator; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; import java.util.ArrayList; @@ -22,7 +21,7 @@ public class GrReferenceHighlighter extends TextEditorHighlightingPass { private final GroovyFileBase myFile; private List myInfos = null; - public GrReferenceHighlighter(@Nullable Document document, @NotNull GroovyFileBase file) { + public GrReferenceHighlighter(@NotNull GroovyFileBase file, @NotNull Document document) { super(file.getProject(), document); myFile = file; } @@ -37,7 +36,7 @@ public class GrReferenceHighlighter extends TextEditorHighlightingPass { @Override public void doApplyInformationToEditor() { - if (myInfos == null || myDocument == null) return; + if (myInfos == null) return; UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), myInfos, getColorsScheme(), getId()); } } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighterFactory.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighterFactory.java index d8d4f0de373e..c913aecedb56 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighterFactory.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GrReferenceHighlighterFactory.java @@ -24,7 +24,7 @@ final class GrReferenceHighlighterFactory implements TextEditorHighlightingPassF @Override public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull Editor editor) { PsiFile groovyFile = file.getViewProvider().getPsi(GroovyLanguage.INSTANCE); - return groovyFile instanceof GroovyFileBase ? new GrReferenceHighlighter(editor.getDocument(), (GroovyFileBase)groovyFile) : null; + return groovyFile instanceof GroovyFileBase ? new GrReferenceHighlighter((GroovyFileBase)groovyFile, editor.getDocument()) : null; } static boolean shouldHighlight(@NotNull PsiFile file) { diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/highlighter/util.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/highlighter/util.kt index 95f2eb64eadb..802531333173 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/highlighter/util.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/highlighter/util.kt @@ -26,7 +26,7 @@ internal abstract class GroovyHighlightingPass(val myFile: PsiFile, document: Do private val myInfos = mutableListOf() override fun doApplyInformationToEditor() { - if (myDocument == null || myInfos.isEmpty()) return + if (myInfos.isEmpty()) return UpdateHighlightersUtil.setHighlightersToEditor( myProject, myDocument, 0, myFile.textLength, myInfos, colorsScheme, id ) diff --git a/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementsErrorPanel.java b/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementsErrorPanel.java index b31f1b9a123a..70c95290f298 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementsErrorPanel.java +++ b/xml/dom-impl/src/com/intellij/util/xml/highlighting/DomElementsErrorPanel.java @@ -22,7 +22,6 @@ import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; -import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.xml.XmlFile; import com.intellij.util.Alarm; import com.intellij.util.containers.ContainerUtil; @@ -141,7 +140,7 @@ public class DomElementsErrorPanel extends JPanel implements CommittablePanel, H private class DomElementsTrafficLightRenderer extends TrafficLightRenderer { DomElementsTrafficLightRenderer(@NotNull XmlFile xmlFile) { super(xmlFile.getProject(), - PsiDocumentManager.getInstance(xmlFile.getProject()).getDocument(xmlFile)); + xmlFile.getViewProvider().getDocument()); } @NotNull 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 746b4e92d778..903a2d315e4e 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 @@ -161,10 +161,8 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass { @Override public void doApplyInformationToEditor() { - if (myDocument != null) { - List infos = getHighlights(); - UpdateHighlightersUtil.setHighlightersToSingleEditor(myProject, myEditor, 0, myFile.getTextLength(), infos, getColorsScheme(), getId()); - } + List infos = getHighlights(); + UpdateHighlightersUtil.setHighlightersToSingleEditor(myProject, myEditor, 0, myFile.getTextLength(), infos, getColorsScheme(), getId()); } public List getHighlights() {