JavaPsiIndexConsistencyTest: don't report duplicate classes when reparse moved PsiClass instance downward

This commit is contained in:
peter
2018-05-26 15:16:55 +02:00
parent 3b9d019f82
commit 4e621ea1f4
2 changed files with 17 additions and 2 deletions
@@ -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")
}
}
}
}
@@ -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()