mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
JavaPsiIndexConsistencyTest: don't report duplicate classes when reparse moved PsiClass instance downward
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-2
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user