mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-133960 Fix IndexTest#_test language level change
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -67,6 +67,9 @@ public class PerIndexDocumentVersionMap {
|
||||
}
|
||||
}
|
||||
|
||||
public void clearForDocument(@NotNull Document document) {
|
||||
document.putUserData(KEY, new ArrayList<IdVersionInfo>());
|
||||
}
|
||||
public void clear() {
|
||||
mapVersion++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user