From e484284d3aafeea33aff7e6ef319ba9b474ee711 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Wed, 13 Feb 2013 21:23:21 +0400 Subject: [PATCH] Fixed PIEAE when imported file is renamed and then renamed back using undo ExportedNameCache contains elements with parent file stubs without the PSI element set. Therefore these elements are invalid. We reset exported name cache each time the modification stamp differs from its value at the moment of cache creation, --- .../com/jetbrains/python/psi/impl/PyFileImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java index 5408cd0b9aee..135000abe605 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java @@ -54,8 +54,10 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression { private final List myNameDefiners = new ArrayList(); private final List myNameDefinerNegativeCache = new ArrayList(); private long myNameDefinerOOCBModCount = -1; + private final long myModificationStamp; - private ExportedNameCache() { + private ExportedNameCache(long modificationStamp) { + myModificationStamp = modificationStamp; final List children = PyPsiUtils.collectAllStubChildren(PyFileImpl.this, getStub()); final List exceptParts = new ArrayList(); for (PsiElement child : children) { @@ -226,6 +228,9 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression { return null; } + public long getModificationStamp() { + return myModificationStamp; + } } public PyFileImpl(FileViewProvider viewProvider) { @@ -433,8 +438,13 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression { ExportedNameCache cache; synchronized (myENCLock) { cache = myExportedNameCache != null ? myExportedNameCache.get() : null; + final long modificationStamp = getModificationStamp(); + if (myExportedNameCache != null && cache != null && modificationStamp != cache.getModificationStamp()) { + myExportedNameCache.clear(); + cache = null; + } if (cache == null) { - cache = new ExportedNameCache(); + cache = new ExportedNameCache(modificationStamp); myExportedNameCache = new SoftReference(cache); } }