From 0a929ebad41a64ca7cc972f3d2460c17258b677f Mon Sep 17 00:00:00 2001 From: "no_reply@jetbrains.com" Date: Tue, 25 Jan 2005 17:19:40 +0300 Subject: [PATCH] timestamps now change only on transactions commit --- .../psi/impl/PsiToDocumentSynchronizer.java | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/source/com/intellij/psi/impl/PsiToDocumentSynchronizer.java b/source/com/intellij/psi/impl/PsiToDocumentSynchronizer.java index 621d000a4f65..fbf3098a2e64 100644 --- a/source/com/intellij/psi/impl/PsiToDocumentSynchronizer.java +++ b/source/com/intellij/psi/impl/PsiToDocumentSynchronizer.java @@ -49,32 +49,40 @@ public class PsiToDocumentSynchronizer extends PsiTreeChangeAdapter { textBlock.clear(); } - boolean isOriginal = true; - if(event.getParent() != null){ - ASTNode element = SourceTreeToPsiMap.psiElementToTree(event.getParent()); + boolean isOriginal = isOriginal(event.getParent(), psiFile, document); + + if (isOriginal) { + myPsiDocumentManager.setProcessDocumentEvents(false); + syncAction.syncDocument(document, (PsiTreeChangeEventImpl)event); + myPsiDocumentManager.setProcessDocumentEvents(true); + + if(!myTransactionsMap.containsKey(document)){ + document.setModificationStamp(psiFile.getModificationStamp()); + mySmartPointerManager.synchronizePointers(psiFile); + if (LOG.isDebugEnabled()) { + PsiDocumentManagerImpl.checkConsistency(psiFile, document); + if (psiFile instanceof JspxFileImpl) { + ( (JspxFileImpl)psiFile).checkAllConsistent(); + } + } + } + } + } + + private boolean isOriginal(final PsiElement changeScope, final PsiFile psiFile, final DocumentEx document) { + boolean original = true; + if(changeScope != null){ + ASTNode element = SourceTreeToPsiMap.psiElementToTree(changeScope); while(element != null && !(element instanceof FileElement)) { element = element.getTreeParent(); } PsiFile fileForDoc = PsiDocumentManager.getInstance(psiFile.getProject()).getPsiFile(document); - isOriginal = element != null ? fileForDoc == SourceTreeToPsiMap.treeElementToPsi(element) : false; - LOG.debug("DOCSync: " + isOriginal + "; document=" + document+"; file="+psiFile.getName() + ":" + + original = element != null ? fileForDoc == SourceTreeToPsiMap.treeElementToPsi(element) : false; + LOG.debug("DOCSync: " + original + "; document=" + document+"; file="+psiFile.getName() + ":" + psiFile.getClass() +"; file for doc="+fileForDoc.getName()+"; virtualfile="+psiFile.getVirtualFile()); } - - if (isOriginal) { - myPsiDocumentManager.setProcessDocumentEvents(false); - syncAction.syncDocument(document, (PsiTreeChangeEventImpl)event); - document.setModificationStamp(psiFile.getModificationStamp()); - myPsiDocumentManager.setProcessDocumentEvents(true); - mySmartPointerManager.synchronizePointers(psiFile); - if (LOG.isDebugEnabled()) { - PsiDocumentManagerImpl.checkConsistency(psiFile, document); - if (psiFile instanceof JspxFileImpl) { - ( (JspxFileImpl)psiFile).checkAllConsistent(); - } - } - } + return original; } public void childAdded(final PsiTreeChangeEvent event) { @@ -215,23 +223,19 @@ public class PsiToDocumentSynchronizer extends PsiTreeChangeAdapter { public void commitTransaction(Document document){ final DocumentChangeTransaction documentChangeTransaction = myTransactionsMap.get(document); - try{ - if(documentChangeTransaction == null) return; - if(documentChangeTransaction.getAffectedFragments().size() == 0) return; // Nothing to do + myTransactionsMap.remove(document); + if(documentChangeTransaction == null) return; + if(documentChangeTransaction.getAffectedFragments().size() == 0) return; // Nothing to do - final PsiElement changeScope = documentChangeTransaction.getChangeScope(); - final PsiTreeChangeEventImpl fakeEvent = new PsiTreeChangeEventImpl(changeScope.getManager()); - fakeEvent.setParent(changeScope); - fakeEvent.setFile(changeScope.getContainingFile()); - doSync(fakeEvent, new DocSyncAction() { - public void syncDocument(Document document, PsiTreeChangeEventImpl event) { - doCommitTransaction(document, documentChangeTransaction); - } - }); - } - finally{ - myTransactionsMap.remove(document); - } + final PsiElement changeScope = documentChangeTransaction.getChangeScope(); + final PsiTreeChangeEventImpl fakeEvent = new PsiTreeChangeEventImpl(changeScope.getManager()); + fakeEvent.setParent(changeScope); + fakeEvent.setFile(changeScope.getContainingFile()); + doSync(fakeEvent, new DocSyncAction() { + public void syncDocument(Document document, PsiTreeChangeEventImpl event) { + doCommitTransaction(document, documentChangeTransaction); + } + }); } public void doCommitTransaction(final Document document){