mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
removed explicit log management since LOG.debug() does all that automatically
This commit is contained in:
@@ -21,7 +21,7 @@ import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar;
|
||||
import com.intellij.codeInsight.daemon.ProblemHighlightFilter;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
@@ -45,6 +45,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class FileStatusMap implements Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.FileStatusMap");
|
||||
private final Project myProject;
|
||||
private final Map<Document,FileStatus> myDocumentToStatusMap = new WeakHashMap<>(); // all dirty if absent
|
||||
private volatile boolean myAllowDirt = true;
|
||||
@@ -159,8 +160,10 @@ public class FileStatusMap implements Disposable {
|
||||
|
||||
void markAllFilesDirty(@NotNull @NonNls Object reason) {
|
||||
assertAllowModifications();
|
||||
log("Mark all dirty: ", reason);
|
||||
synchronized (myDocumentToStatusMap) {
|
||||
if (!myDocumentToStatusMap.isEmpty()) {
|
||||
log("Mark all dirty: ", reason);
|
||||
}
|
||||
myDocumentToStatusMap.clear();
|
||||
}
|
||||
}
|
||||
@@ -176,11 +179,7 @@ public class FileStatusMap implements Disposable {
|
||||
|
||||
public void markFileUpToDate(@NotNull Document document, int passId) {
|
||||
synchronized(myDocumentToStatusMap){
|
||||
FileStatus status = myDocumentToStatusMap.get(document);
|
||||
if (status == null){
|
||||
status = new FileStatus(myProject);
|
||||
myDocumentToStatusMap.put(document, status);
|
||||
}
|
||||
FileStatus status = myDocumentToStatusMap.computeIfAbsent(document, k -> new FileStatus(myProject));
|
||||
status.defensivelyMarked=false;
|
||||
if (passId == Pass.WOLF) {
|
||||
status.wolfPassFinished = true;
|
||||
@@ -350,25 +349,10 @@ public class FileStatusMap implements Disposable {
|
||||
private static int getThreadNum() {
|
||||
return ConcurrencyUtil.cacheOrGet(threads, Thread.currentThread(), threads.size());
|
||||
}
|
||||
private static final StringBuilder log = new StringBuilder();
|
||||
private static final boolean IN_TESTS = ApplicationManager.getApplication().isUnitTestMode();
|
||||
public static void log(@NonNls @NotNull Object... info) {
|
||||
if (IN_TESTS) {
|
||||
synchronized (log) {
|
||||
if (log.length() > 10000) {
|
||||
log.replace(0, log.length()-5000, "");
|
||||
}
|
||||
String s = StringUtil.repeatSymbol(' ', getThreadNum() * 4) + Arrays.asList(info) + "\n";
|
||||
log.append(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@NotNull
|
||||
static String getAndClearLog() {
|
||||
synchronized (log) {
|
||||
String l = log.toString();
|
||||
log.setLength(0);
|
||||
return l;
|
||||
if (LOG.isDebugEnabled()) {
|
||||
String s = StringUtil.repeatSymbol(' ', getThreadNum() * 4) + Arrays.asList(info) + "\n";
|
||||
LOG.debug(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,8 +202,6 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi
|
||||
}
|
||||
}
|
||||
|
||||
final StringBuilder log = new StringBuilder();
|
||||
|
||||
@SuppressWarnings({"NonConstantStringShouldBeStringBuffer", "StringConcatenationInLoop"})
|
||||
public void log(Project project, @NonNls String msg, @Nullable CommitTask task, @NonNls Object... args) {
|
||||
if (true) return;
|
||||
@@ -256,14 +254,7 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(s);
|
||||
|
||||
synchronized (log) {
|
||||
log.append(s).append("\n");
|
||||
if (log.length() > 100000) {
|
||||
log.delete(0, log.length()-50000);
|
||||
}
|
||||
}
|
||||
LOG.debug(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -294,16 +285,10 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi
|
||||
public void clearQueue() {
|
||||
synchronized (lock) {
|
||||
cancelAll();
|
||||
clearLog();
|
||||
wakeUpQueue();
|
||||
}
|
||||
}
|
||||
|
||||
@TestOnly // under lock
|
||||
private void clearLog() {
|
||||
log.setLength(0);
|
||||
}
|
||||
|
||||
private void cancelAndRemoveCurrentTask(@NotNull CommitTask newTask, @NotNull Object reason) {
|
||||
CommitTask currentTask = this.currentTask;
|
||||
if (currentTask != null && currentTask.equals(newTask)) {
|
||||
@@ -411,7 +396,6 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi
|
||||
failureReason = e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.error(log.toString(), e);
|
||||
cancel(e);
|
||||
failureReason = ExceptionUtil.getThrowableText(e);
|
||||
}
|
||||
@@ -618,30 +602,24 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
boolean changeStillValid = task.isStillValid();
|
||||
boolean success = changeStillValid && documentManager.finishCommit(document, finishProcessors, synchronously, task.reason);
|
||||
if (synchronously) {
|
||||
assert success;
|
||||
}
|
||||
if (!changeStillValid) {
|
||||
log(project, "document changed; ignore", task);
|
||||
return;
|
||||
}
|
||||
if (synchronously || success) {
|
||||
assert !documentManager.isInUncommittedSet(document);
|
||||
}
|
||||
if (success) {
|
||||
log(project, "Commit finished", task);
|
||||
}
|
||||
else {
|
||||
// add document back to the queue
|
||||
commitAsynchronously(project, document, "Re-added back", task.myCreationModalityState);
|
||||
}
|
||||
boolean changeStillValid = task.isStillValid();
|
||||
boolean success = changeStillValid && documentManager.finishCommit(document, finishProcessors, synchronously, task.reason);
|
||||
if (synchronously) {
|
||||
assert success;
|
||||
}
|
||||
catch (Error e) {
|
||||
System.err.println("Log:" + log);
|
||||
throw e;
|
||||
if (!changeStillValid) {
|
||||
log(project, "document changed; ignore", task);
|
||||
return;
|
||||
}
|
||||
if (synchronously || success) {
|
||||
assert !documentManager.isInUncommittedSet(document);
|
||||
}
|
||||
if (success) {
|
||||
log(project, "Commit finished", task);
|
||||
}
|
||||
else {
|
||||
// add document back to the queue
|
||||
commitAsynchronously(project, document, "Re-added back", task.myCreationModalityState);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -744,7 +722,7 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isStillValid() {
|
||||
boolean isStillValid() {
|
||||
Document document = getDocument();
|
||||
return ((DocumentEx)document).getModificationSequence() == modificationSequence;
|
||||
}
|
||||
@@ -960,13 +938,4 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi
|
||||
return lock != null ? lock : ((UserDataHolderEx)document).putUserDataIfAbsent(DOCUMENT_LOCK, new ReentrantLock());
|
||||
}
|
||||
private static final Key<Lock> DOCUMENT_LOCK = Key.create("DOCUMENT_LOCK");
|
||||
|
||||
@TestOnly
|
||||
int documentsToCommit() {
|
||||
return documentsToCommit.size();
|
||||
}
|
||||
@TestOnly
|
||||
int documentsToApplyInEDT() {
|
||||
return documentsToApplyInEDT.size();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-8
@@ -345,7 +345,6 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
|
||||
Project project = file.getProject();
|
||||
FileStatusMap.getAndClearLog();
|
||||
FileStatusMap fileStatusMap = getFileStatusMap();
|
||||
fileStatusMap.allowDirt(canChangeDocument);
|
||||
|
||||
@@ -411,14 +410,8 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers
|
||||
}
|
||||
finally {
|
||||
DaemonProgressIndicator.setDebug(false);
|
||||
String log = FileStatusMap.getAndClearLog();
|
||||
fileStatusMap.allowDirt(true);
|
||||
try {
|
||||
waitForTermination();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
LOG.error(log, e);
|
||||
}
|
||||
waitForTermination();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -394,7 +394,7 @@ public class PsiDocumentManagerImplTest extends PlatformTestCase {
|
||||
assertTrue(commitThread.isEnabled());
|
||||
WriteCommandAction.runWriteCommandAction(null, () -> {
|
||||
if (commitThread.isEnabled()) {
|
||||
System.err.println("commitThread: "+commitThread + ";\n"+commitThread.log+";\n"+ThreadDumper.dumpThreadsToString());
|
||||
System.err.println("commitThread: "+commitThread + ";\n"+ThreadDumper.dumpThreadsToString());
|
||||
}
|
||||
assertFalse(commitThread.isEnabled());
|
||||
WriteCommandAction.runWriteCommandAction(null, () -> assertFalse(commitThread.isEnabled()));
|
||||
|
||||
Reference in New Issue
Block a user