From 826f63268a905e665fc12ec93dbf7245bdf3356a Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 6 Feb 2015 17:11:46 +0100 Subject: [PATCH] IDEA-133960 Fix IndexTest#_test language level change --- .../com/intellij/index/IndexTest.groovy | 20 ++++++++++++++++++ .../util/indexing/FileBasedIndexImpl.java | 21 +++++++++++++------ .../indexing/PerIndexDocumentVersionMap.java | 3 +++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy b/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy index c9a28e7febd2..a605926210bc 100644 --- a/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy +++ b/java/java-tests/testSrc/com/intellij/index/IndexTest.groovy @@ -33,6 +33,7 @@ import com.intellij.psi.* import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.impl.PsiManagerEx import com.intellij.psi.impl.file.impl.FileManagerImpl +import com.intellij.psi.impl.source.PostprocessReformattingAspect import com.intellij.psi.impl.source.PsiFileWithStubSupport import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.PsiSearchHelper @@ -338,6 +339,25 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase { assert ((PsiJavaFile)psiFile).importList.node } + public void "test language level change2"() { + def psiFile = myFixture.addFileToProject("Foo.java", "class Foo {}") + def vFile = psiFile.virtualFile + def scope = GlobalSearchScope.allScope(project) + + psiFile.add(elementFactory.createEnum("SomeEnum")) + + CodeStyleManager.getInstance(getProject()).reformat(psiFile) + PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting() + + assert JavaPsiFacade.getInstance(project).findClass("Foo", scope) + + IdeaTestUtil.setModuleLanguageLevel(myFixture.module, LanguageLevel.JDK_1_3) + assert ((PsiJavaFile)getPsiManager().findFile(vFile)).importList.node + + PlatformTestUtil.tryGcSoftlyReachableObjects() + assert ((PsiJavaFile)getPsiManager().findFile(vFile)).importList.node + } + public void "test changing a file without psi makes the document committed and updates index"() { def psiFile = myFixture.addFileToProject("Foo.java", "class Foo {}") def vFile = psiFile.virtualFile diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index 585aacff4a16..21f02bf10972 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -1982,7 +1982,7 @@ public class FileBasedIndexImpl extends FileBasedIndex { } if (!myUpToDateIndicesForUnsavedOrTransactedDocuments.isEmpty()) { - clearPsiIndicesForUnsavedDocuments(file); + clearUpToDateStateForPsiIndicesOfUnsavedDocuments(file); } } finally { @@ -2068,6 +2068,8 @@ public class FileBasedIndexImpl extends FileBasedIndex { } } + clearUpToDateStateForPsiIndicesOfUnsavedDocuments(file); + // the file is for sure not a dir and it was previously indexed by at least one index AND it belongs to some update set if (!isTooLarge(file) && getIndexableSetForFile(file) != null) scheduleForUpdate(file); } @@ -2320,12 +2322,19 @@ public class FileBasedIndexImpl extends FileBasedIndex { } } - private boolean clearPsiIndicesForUnsavedDocuments(@NotNull VirtualFile file) { - Document document = myFileDocumentManager.getDocument(file); + private boolean clearUpToDateStateForPsiIndicesOfUnsavedDocuments(@NotNull VirtualFile file) { + Document document = myFileDocumentManager.getCachedDocument(file); + if (document != null && myFileDocumentManager.isDocumentUnsaved(document)) { - for (ID psiBackedIndex : myPsiDependentIndices) { - myUpToDateIndicesForUnsavedOrTransactedDocuments.remove(psiBackedIndex); + if (!myUpToDateIndicesForUnsavedOrTransactedDocuments.isEmpty()) { + for (ID psiBackedIndex : myPsiDependentIndices) { + myUpToDateIndicesForUnsavedOrTransactedDocuments.remove(psiBackedIndex); + } } + + myLastIndexedDocStamps.clearForDocument(document); // Q: non psi indices + document.putUserData(ourFileContentKey, null); + return true; } return false; @@ -2472,7 +2481,7 @@ public class FileBasedIndexImpl extends FileBasedIndex { PsiFile file = event.getFile(); if (file != null) { VirtualFile virtualFile = file.getVirtualFile(); - if (!clearPsiIndicesForUnsavedDocuments(virtualFile)) { + if (!clearUpToDateStateForPsiIndicesOfUnsavedDocuments(virtualFile)) { // change in persistent file if (virtualFile instanceof VirtualFileWithId) { int fileId = ((VirtualFileWithId)virtualFile).getId(); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentVersionMap.java b/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentVersionMap.java index f9b2b4c169cd..c86edbc1089f 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentVersionMap.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentVersionMap.java @@ -67,6 +67,9 @@ public class PerIndexDocumentVersionMap { } } + public void clearForDocument(@NotNull Document document) { + document.putUserData(KEY, new ArrayList()); + } public void clear() { mapVersion++; }