diff --git a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaPsiIndexConsistencyTest.kt b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaPsiIndexConsistencyTest.kt index f5a575a93ccf..d526792da478 100644 --- a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaPsiIndexConsistencyTest.kt +++ b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaPsiIndexConsistencyTest.kt @@ -35,6 +35,7 @@ import com.intellij.testFramework.propertyBased.PsiIndexConsistencyTester.Model import com.intellij.testFramework.propertyBased.PsiIndexConsistencyTester.RefKind import org.jetbrains.jetCheck.Generator import org.jetbrains.jetCheck.PropertyChecker +import org.junit.Assert /** * @author peter @@ -143,6 +144,14 @@ class JavaPsiIndexConsistencyTest : LightCodeInsightFixtureTestCase() { private object ClassRef : RefKind(){ override fun loadRef(model: Model) = model.findPsiClass() + override fun checkDuplicates(oldValue: Any, newValue: Any) { + oldValue as PsiClass + newValue as PsiClass + if (oldValue.isValid && (newValue.containingFile as PsiJavaFile).classes.size == 1) { + // if there are >1 classes in the file, it could be that after reparse previously retrieved PsiClass instance is now pointing to a non-first one, and so there's no duplicate + Assert.fail("Duplicate PSI elements: $oldValue and $newValue") + } + } } } diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/PsiIndexConsistencyTester.kt b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/PsiIndexConsistencyTester.kt index 8f71f980254d..307c2f3109c3 100644 --- a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/PsiIndexConsistencyTester.kt +++ b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/PsiIndexConsistencyTester.kt @@ -165,8 +165,8 @@ object PsiIndexConsistencyTester { override fun performAction(model: Model) { val oldValue = model.refs[kind] val newValue = kind.loadRef(model) - if (oldValue is PsiElement && oldValue.isValid && newValue is PsiElement && oldValue !== newValue) { - fail("Duplicate PSI elements: $oldValue and $newValue") + if (oldValue !== null && newValue !== null && oldValue !== newValue) { + kind.checkDuplicates(oldValue, newValue) } model.refs[kind] = newValue } @@ -194,6 +194,12 @@ object PsiIndexConsistencyTester { abstract class RefKind { abstract fun loadRef(model: Model): Any? + + open fun checkDuplicates(oldValue: Any, newValue: Any) { + if (oldValue is PsiElement && oldValue.isValid && newValue is PsiElement) { + fail("Duplicate PSI elements: $oldValue and $newValue") + } + } object PsiFileRef : RefKind() { override fun loadRef(model: Model): Any? = model.findPsiFile()