use separate modificationCount for PSI and Document (fixes psifile-dependent CachedValues) [take 2]

This commit is contained in:
Gregory.Shrago
2012-05-18 18:44:59 +04:00
parent 299d359566
commit 0879f13eda
9 changed files with 17 additions and 14 deletions
@@ -73,6 +73,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
private IElementType myElementType;
protected IElementType myContentElementType;
private long myModificationStamp;
protected PsiFile myOriginalFile = null;
private final FileViewProvider myViewProvider;
@@ -354,7 +355,9 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
myStub = null;
}
public void clearCaches() {}
public void clearCaches() {
myModificationStamp ++;
}
@Override
public String getText() {
@@ -386,7 +389,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
@Override
public long getModificationStamp() {
return getViewProvider().getModificationStamp();
return myModificationStamp;
}
@Override
@@ -180,7 +180,7 @@ public class BlockSupportImpl extends BlockSupport {
viewProvider.getLanguages();
FileType fileType = viewProvider.getVirtualFile().getFileType();
final LightVirtualFile lightFile = new LightVirtualFile(fileImpl.getName(), fileType, newFileText, viewProvider.getVirtualFile().getCharset(),
fileImpl.getModificationStamp());
fileImpl.getViewProvider().getModificationStamp());
lightFile.setOriginalFile(viewProvider.getVirtualFile());
FileViewProvider copy = viewProvider.createCopy(lightFile);
@@ -785,7 +785,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
final Pair<PsiFile, Document> pair = reference.get();
if (pair != null && pair.first.isValid() && pair.first.getClass().equals(file.getClass())) {
final PsiFile copy = pair.first;
if (copy.getModificationStamp() > file.getModificationStamp()) {
if (copy.getViewProvider().getModificationStamp() > file.getViewProvider().getModificationStamp()) {
((PsiModificationTrackerImpl) file.getManager().getModificationTracker()).incCounter();
}
final Document document = pair.second;
@@ -59,10 +59,10 @@ public class OffsetTranslator implements Disposable {
});
originalFile.getProject().getMessageBus().connect(this).subscribe(PsiModificationTracker.TOPIC, new PsiModificationTracker.Listener() {
long lastModCount = originalFile.getModificationStamp();
long lastModCount = originalFile.getViewProvider().getModificationStamp();
@Override
public void modificationCountChanged() {
if (isUpToDate() && lastModCount != originalFile.getModificationStamp()) {
if (isUpToDate() && lastModCount != originalFile.getViewProvider().getModificationStamp()) {
myTranslation.addAll(sinceCommit);
sinceCommit.clear();
}
@@ -473,7 +473,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx
if (myDisposed) return false;
Document document = PsiDocumentManager.getInstance(myProject).getCachedDocument(file);
return document != null &&
document.getModificationStamp() == file.getModificationStamp() &&
document.getModificationStamp() == file.getViewProvider().getModificationStamp() &&
myFileStatusMap.allDirtyScopesAreNull(document);
}
@@ -481,7 +481,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx
if (myDisposed) return false;
Document document = PsiDocumentManager.getInstance(myProject).getCachedDocument(file);
return document != null &&
document.getModificationStamp() == file.getModificationStamp() &&
document.getModificationStamp() == file.getViewProvider().getModificationStamp() &&
myFileStatusMap.getFileDirtyScope(document, Pass.UPDATE_ALL) == null;
}
@@ -96,7 +96,7 @@ public class PsiToDocumentSynchronizer extends PsiTreeChangeAdapter {
final boolean insideTransaction = myTransactionsMap.containsKey(document);
if (!insideTransaction) {
document.setModificationStamp(psiFile.getModificationStamp());
document.setModificationStamp(psiFile.getViewProvider().getModificationStamp());
if (LOG.isDebugEnabled()) {
PsiDocumentManagerImpl.checkConsistency(psiFile, document);
}
@@ -1384,7 +1384,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
@Override
public String getText() {
if (myFile.getModificationStamp() != myDocument.getModificationStamp()) {
if (myFile.getViewProvider().getModificationStamp() != myDocument.getModificationStamp()) {
final ASTNode node = myFile.getNode();
assert node != null;
return node.getText();
@@ -1394,7 +1394,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
@Override
public long getModificationStamp() {
return myFile.getModificationStamp();
return myFile.getViewProvider().getModificationStamp();
}
}
@@ -1418,7 +1418,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
final PsiFile dominantContentFile = findDominantPsiForDocument(document, project);
final DocumentContent content;
if (dominantContentFile != null && dominantContentFile.getModificationStamp() != document.getModificationStamp()) {
if (dominantContentFile != null && dominantContentFile.getViewProvider().getModificationStamp() != document.getModificationStamp()) {
content = new PsiContent(document, dominantContentFile);
}
else {
@@ -407,7 +407,7 @@ public class UsageInfo2UsageAdapter implements UsageInModule,
private long myModificationStamp;
private long getCurrentModificationStamp() {
final PsiFile containingFile = getPsiFile();
return containingFile == null ? -1L : containingFile.getModificationStamp();
return containingFile == null ? -1L : containingFile.getViewProvider().getModificationStamp();
}
@Override
@@ -548,7 +548,7 @@ public class ValidateXmlActionHandler {
final PsiFile psifile = PsiManager.getInstance(myProject).findFile(file);
if (psifile != null && psifile.isValid()) {
timestamp += psifile.getModificationStamp();
timestamp += psifile.getViewProvider().getModificationStamp();
} else {
break;
}