psi/document sync cleanup

This commit is contained in:
peter
2013-06-24 14:24:28 +02:00
parent fa40e14809
commit e342aa624d
3 changed files with 9 additions and 13 deletions
@@ -52,7 +52,7 @@ import java.util.Arrays;
public abstract class DocumentCommitProcessor {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.DocumentCommitThread");
public abstract void commitSynchronously(@NotNull Document document, @NotNull Project project, PsiFile excludeFile);
public abstract void commitSynchronously(@NotNull Document document, @NotNull Project project);
public abstract void commitAsynchronously(@NotNull final Project project, @NotNull final Document document, @NonNls @NotNull Object reason);
protected static class CommitTask {
@@ -262,7 +262,7 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen
public void commitDocument(@NotNull final Document doc) {
final Document document = doc instanceof DocumentWindow ? ((DocumentWindow)doc).getDelegate() : doc;
if (!isCommitted(document)) {
doCommit(document, null);
doCommit(document);
}
}
@@ -345,17 +345,17 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen
}
}
protected void doCommit(@NotNull final Document document, final PsiFile excludeFile) {
private void doCommit(@NotNull final Document document) {
assert !myIsCommitInProgress : "Do not call commitDocument() from inside PSI change listener";
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
// otherwise there are many clients calling commitAllDocs() on PSI childrenChanged()
if (getSynchronizer().isDocumentAffectedByTransactions(document) && excludeFile == null) return;
if (getSynchronizer().isDocumentAffectedByTransactions(document)) return;
myIsCommitInProgress = true;
try {
myDocumentCommitProcessor.commitSynchronously(document, myProject, excludeFile);
myDocumentCommitProcessor.commitSynchronously(document, myProject);
}
finally {
myIsCommitInProgress = false;
@@ -293,7 +293,7 @@ public class DocumentCommitThread extends DocumentCommitProcessor implements Run
((ProgressManagerImpl)ProgressManager.getInstance()).executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
result[0] = commitUnderProgress(commitTask, null, false);
result[0] = commitUnderProgress(commitTask, false);
}
}, commitTask.indicator);
finishRunnable = result[0];
@@ -331,7 +331,7 @@ public class DocumentCommitThread extends DocumentCommitProcessor implements Run
}
@Override
public void commitSynchronously(@NotNull Document document, @NotNull Project project, PsiFile excludeFile) {
public void commitSynchronously(@NotNull Document document, @NotNull Project project) {
assert !isDisposed;
ApplicationManager.getApplication().assertWriteAccessAllowed();
@@ -363,7 +363,7 @@ public class DocumentCommitThread extends DocumentCommitProcessor implements Run
log("About to commit sync", task, true, indicator);
Runnable finish = commitUnderProgress(task, excludeFile, true);
Runnable finish = commitUnderProgress(task, true);
log("Committed sync", task, true, finish, indicator);
assert finish != null;
@@ -392,7 +392,6 @@ public class DocumentCommitThread extends DocumentCommitProcessor implements Run
// returns finish commit Runnable (to be invoked later in EDT), or null on failure
@Nullable
private Runnable commitUnderProgress(@NotNull final CommitTask task,
final PsiFile excludeFile,
final boolean synchronously) {
final Project project = task.project;
final Document document = task.document;
@@ -407,7 +406,7 @@ public class DocumentCommitThread extends DocumentCommitProcessor implements Run
if (viewProvider == null) return;
List<PsiFile> psiFiles = viewProvider.getAllFiles();
for (PsiFile file : psiFiles) {
if (file.isValid() && file != excludeFile) {
if (file.isValid()) {
Processor<Document> finishProcessor = doCommit(task, file, synchronously);
if (finishProcessor != null) {
finishProcessors.add(finishProcessor);
@@ -465,9 +464,6 @@ public class DocumentCommitThread extends DocumentCommitProcessor implements Run
}
PsiDocumentManagerImpl documentManager = (PsiDocumentManagerImpl)PsiDocumentManager.getInstance(project);
Collection<Document> uncommitted = documentManager.getUncommittedDocumentsUnsafe();
FileViewProvider viewProvider = documentManager.getCachedViewProvider(document);
//if (!documentManager.getSynchronizer().isInSynchronization(document) && !uncommitted.contains(document)) return; // already committed, must be the sync commit
log("Executing later finishCommit", task, false);
boolean success = documentManager.finishCommit(document, finishProcessors, synchronously, task.reason);