From 7faf488b58232a9caac3f376fa59d9e82c71f500 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 20 May 2015 16:08:25 +0300 Subject: [PATCH] more logging --- .../daemon/impl/FileStatusMap.java | 26 +++++++++---------- .../psi/impl/PsiTreeChangeEventImpl.java | 7 ++--- .../daemon/impl/DaemonCodeAnalyzerImpl.java | 9 ++++--- .../daemon/impl/PsiChangeHandler.java | 20 +++++++------- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java index e417dfb07f60..4bf905f017ee 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,18 +53,18 @@ public class FileStatusMap implements Disposable { private final Map myDocumentToStatusMap = new WeakHashMap(); // all dirty if absent private volatile boolean myAllowDirt = true; - public FileStatusMap(@NotNull Project project) { + FileStatusMap(@NotNull Project project) { myProject = project; } @Override public void dispose() { // clear dangling references to PsiFiles/Documents. SCR#10358 - markAllFilesDirty(); + markAllFilesDirty("FileStatusMap dispose"); } @Nullable("null means the file is clean") - public static TextRange getDirtyTextRange(@NotNull Editor editor, int passId) { + static TextRange getDirtyTextRange(@NotNull Editor editor, int passId) { Document document = editor.getDocument(); FileStatusMap me = DaemonCodeAnalyzerEx.getInstanceEx(editor.getProject()).getFileStatusMap(); @@ -87,7 +87,7 @@ public class FileStatusMap implements Disposable { } } - public boolean wasErrorFound(@NotNull Document document) { + boolean wasErrorFound(@NotNull Document document) { synchronized(myDocumentToStatusMap) { FileStatus status = myDocumentToStatusMap.get(document); return status != null && status.errorFound; @@ -164,9 +164,9 @@ public class FileStatusMap implements Disposable { } } - public void markAllFilesDirty() { + void markAllFilesDirty(@NotNull @NonNls Object reason) { assertAllowModifications(); - LOG.debug("********************************* Mark all dirty"); + LOG.debug("Mark all dirty: ", reason); synchronized (myDocumentToStatusMap) { myDocumentToStatusMap.clear(); } @@ -220,10 +220,10 @@ public class FileStatusMap implements Disposable { } } - public void markFileScopeDirtyDefensively(@NotNull PsiFile file) { + void markFileScopeDirtyDefensively(@NotNull PsiFile file, @NotNull @NonNls Object reason) { assertAllowModifications(); if (LOG.isDebugEnabled()) { - LOG.debug("********************************* Mark dirty file defensively: "+file.getName()); + LOG.debug("Mark dirty file defensively: "+file.getName()+": "+reason); } // mark whole file dirty in case no subsequent PSI events will come, but file requires rehighlighting nevertheless // e.g. in the case of quick typing/backspacing char @@ -236,10 +236,10 @@ public class FileStatusMap implements Disposable { } } - public void markFileScopeDirty(@NotNull Document document, @NotNull TextRange scope, int fileLength) { + void markFileScopeDirty(@NotNull Document document, @NotNull TextRange scope, int fileLength, @NotNull @NonNls Object reason) { assertAllowModifications(); if (LOG.isDebugEnabled()) { - LOG.debug("********************************* Mark dirty: "+scope); + LOG.debug("Mark scope dirty: "+scope+" : "+reason); } synchronized(myDocumentToStatusMap) { FileStatus status = myDocumentToStatusMap.get(document); @@ -270,7 +270,7 @@ public class FileStatusMap implements Disposable { return document.createRangeMarker(union); } - public boolean allDirtyScopesAreNull(@NotNull Document document) { + boolean allDirtyScopesAreNull(@NotNull Document document) { synchronized (myDocumentToStatusMap) { PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document); if (!ProblemHighlightFilter.shouldHighlightFile(file)) return true; @@ -342,7 +342,7 @@ public class FileStatusMap implements Disposable { @Override public T getUserData(@NotNull Key key) { - throw null; + throw new UnsupportedOperationException(); } @Override diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiTreeChangeEventImpl.java b/platform/core-impl/src/com/intellij/psi/impl/PsiTreeChangeEventImpl.java index 9c9bc6ca7d76..0805dc95d7c3 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiTreeChangeEventImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiTreeChangeEventImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ public class PsiTreeChangeEventImpl extends PsiTreeChangeEvent{ private PsiEventType myCode; - public PsiTreeChangeEventImpl(PsiManager manager) { + public PsiTreeChangeEventImpl(@NotNull PsiManager manager) { super(manager); } @@ -124,8 +124,9 @@ public class PsiTreeChangeEventImpl extends PsiTreeChangeEvent{ isGenericChange = genericChange; } + @NotNull @Override public String toString() { - return "PsiTreeChangeEventImpl{myCode=" + myCode + (isGenericChange ? " (generic)" : "") + '}'; + return "PsiTreeChangeEventImpl{" + myCode + (isGenericChange ? " (generic)" : "") + '}'; } } 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 8663b82128a9..346d1e1ad920 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 @@ -143,7 +143,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers myInitialized = true; myDisposed = false; - myFileStatusMap.markAllFilesDirty(); + myFileStatusMap.markAllFilesDirty("DCAI init"); Disposer.register(this, new Disposable() { @Override public void dispose() { @@ -477,7 +477,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers @Override public void restart() { - myFileStatusMap.markAllFilesDirty(); + myFileStatusMap.markAllFilesDirty("Global restart"); stopProcess(true, "Global restart"); } @@ -485,8 +485,9 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers public void restart(@NotNull PsiFile file) { Document document = myPsiDocumentManager.getCachedDocument(file); if (document == null) return; - myFileStatusMap.markFileScopeDirty(document, new TextRange(0, document.getTextLength()), file.getTextLength()); - stopProcess(true, "Psi file restart"); + String reason = "Psi file restart: " + file.getName(); + myFileStatusMap.markFileScopeDirty(document, new TextRange(0, document.getTextLength()), file.getTextLength(), reason); + stopProcess(true, reason); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PsiChangeHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PsiChangeHandler.java index becc369f534b..b2acbad9c634 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PsiChangeHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PsiChangeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -178,7 +178,7 @@ class PsiChangeHandler extends PsiTreeChangeAdapter implements Disposable { // mark file dirty just in case PsiFile psiFile = event.getFile(); if (psiFile != null) { - myFileStatusMap.markFileScopeDirtyDefensively(psiFile); + myFileStatusMap.markFileScopeDirtyDefensively(psiFile, event); } } @@ -186,15 +186,15 @@ class PsiChangeHandler extends PsiTreeChangeAdapter implements Disposable { public void propertyChanged(@NotNull PsiTreeChangeEvent event) { String propertyName = event.getPropertyName(); if (!propertyName.equals(PsiTreeChangeEvent.PROP_WRITABLE)) { - myFileStatusMap.markAllFilesDirty(); + myFileStatusMap.markAllFilesDirty(event); } } - private void queueElement(PsiElement child, final boolean whitespaceOptimizationAllowed, PsiTreeChangeEvent event) { + private void queueElement(@NotNull PsiElement child, final boolean whitespaceOptimizationAllowed, @NotNull PsiTreeChangeEvent event) { PsiFile file = event.getFile(); if (file == null) file = child.getContainingFile(); if (file == null) { - myFileStatusMap.markAllFilesDirty(); + myFileStatusMap.markAllFilesDirty(child); return; } @@ -216,30 +216,30 @@ class PsiChangeHandler extends PsiTreeChangeAdapter implements Disposable { file = child.getContainingFile(); } catch (PsiInvalidElementAccessException e) { - myFileStatusMap.markAllFilesDirty(); + myFileStatusMap.markAllFilesDirty(e); return; } if (file == null || file instanceof PsiCompiledElement) { - myFileStatusMap.markAllFilesDirty(); + myFileStatusMap.markAllFilesDirty(child); return; } int fileLength = file.getTextLength(); if (!file.getViewProvider().isPhysical()) { - myFileStatusMap.markFileScopeDirty(document, new TextRange(0, fileLength), fileLength); + myFileStatusMap.markFileScopeDirty(document, new TextRange(0, fileLength), fileLength, "Non-physical file update: "+file); return; } PsiElement element = whitespaceOptimizationAllowed && UpdateHighlightersUtil.isWhitespaceOptimizationAllowed(document) ? child : child.getParent(); while (true) { if (element == null || element instanceof PsiFile || element instanceof PsiDirectory) { - myFileStatusMap.markAllFilesDirty(); + myFileStatusMap.markAllFilesDirty("Top element: "+element); return; } final PsiElement scope = getChangeHighlightingScope(element); if (scope != null) { - myFileStatusMap.markFileScopeDirty(document, scope.getTextRange(), fileLength); + myFileStatusMap.markFileScopeDirty(document, scope.getTextRange(), fileLength, "Scope: "+scope); return; }