From 8ab23b5813bdf635525b0ce5c239b4500e706dc3 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 13 Jul 2016 13:09:33 +0300 Subject: [PATCH] migrate to afterWriteActionFinished listener --- .../application/ApplicationAdapter.java | 1 + .../psi/impl/DocumentCommitThread.java | 25 +++---------------- .../openapi/vcs/ex/LineStatusTracker.java | 14 ++--------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/application/ApplicationAdapter.java b/platform/core-api/src/com/intellij/openapi/application/ApplicationAdapter.java index 17fffb76466c..3497d6ec8c3e 100644 --- a/platform/core-api/src/com/intellij/openapi/application/ApplicationAdapter.java +++ b/platform/core-api/src/com/intellij/openapi/application/ApplicationAdapter.java @@ -39,6 +39,7 @@ public abstract class ApplicationAdapter implements ApplicationListener { public void writeActionFinished(@NotNull Object action) { } + @Override public void afterWriteActionFinished(@NotNull Object action) { } } \ No newline at end of file diff --git a/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java b/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java index 0a069a9ca0c8..f4a77ecc2759 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java +++ b/platform/core-impl/src/com/intellij/psi/impl/DocumentCommitThread.java @@ -15,7 +15,6 @@ */ package com.intellij.psi.impl; -import com.intellij.diagnostic.ThreadDumper; import com.intellij.lang.ASTNode; import com.intellij.lang.FileASTNode; import com.intellij.openapi.Disposable; @@ -86,7 +85,6 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi private volatile boolean isDisposed; private CommitTask currentTask; // guarded by lock private boolean myEnabled; // true if we can do commits. set to false temporarily during the write action. guarded by lock - private int runningWriteActions; // accessed in EDT only public static DocumentCommitThread getInstance() { return (DocumentCommitThread)ServiceManager.getService(DocumentCommitProcessor.class); @@ -97,33 +95,18 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi application.invokeLater(new Runnable() { @Override public void run() { - assert runningWriteActions == 0; if (application.isDisposed()) return; assert !application.isWriteAccessAllowed() || application.isUnitTestMode(); // crazy stuff happens in tests, e.g. UIUtil.dispatchInvocationEvents() inside write action application.addApplicationListener(new ApplicationAdapter() { @Override public void beforeWriteActionStart(@NotNull Object action) { - int writeActionsBefore = runningWriteActions++; - if (writeActionsBefore == 0) { - disable("Write action started: " + action); - } + disable("Write action started: " + action); } @Override - public void writeActionFinished(@NotNull Object action) { + public void afterWriteActionFinished(@NotNull Object action) { // crazy things happen when running tests, like starting write action in one thread but firing its end in the other - int writeActionsAfter = runningWriteActions = Math.max(0,runningWriteActions-1); - if (writeActionsAfter == 0) { - enable("Write action finished: " + action); - } - else { - if (writeActionsAfter < 0) { - System.err.println("mismatched listeners: " + writeActionsAfter + ";\n==== log==="+log+"\n====end log==="+ - ";\n=======threaddump====\n" + - ThreadDumper.dumpThreadsToString()+"\n=====END threaddump======="); - assert false; - } - } + enable("Write action finished: " + action); } }, DocumentCommitThread.this); @@ -685,7 +668,7 @@ public class DocumentCommitThread implements Runnable, Disposable, DocumentCommi @Override public String toString() { - return "Document commit thread; application: "+myApplication+"; isDisposed: "+isDisposed+"; myEnabled: "+isEnabled()+"; runningWriteActions: "+runningWriteActions; + return "Document commit thread; application: "+myApplication+"; isDisposed: "+isDisposed+"; myEnabled: "+isEnabled(); } @TestOnly diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java index d59a9fc01efe..5b3305efda8a 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java @@ -401,19 +401,9 @@ public class LineStatusTracker { } private class MyApplicationListener extends ApplicationAdapter { - private int myWriteActionDepth = 0; - @Override - public void writeActionStarted(@NotNull Object action) { - myWriteActionDepth++; - } - - @Override - public void writeActionFinished(@NotNull Object action) { - myWriteActionDepth = Math.max(myWriteActionDepth - 1, 0); - if (myWriteActionDepth == 0) { - updateRanges(); - } + public void afterWriteActionFinished(@NotNull Object action) { + updateRanges(); } }