[SLC] add tests for containingClass
^KT-56613
This commit is contained in:
committed by
Space Team
parent
9129235079
commit
0a1c903e11
+25
@@ -54,6 +54,10 @@ open class AbstractSymbolLightClassesParentingTestBase(
|
|||||||
checkDeclarationParent(declaration)
|
checkDeclarationParent(declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (declaration is PsiMember && declaration !is PsiTypeParameter) {
|
||||||
|
visitPsiMemberDeclaration(declaration)
|
||||||
|
}
|
||||||
|
|
||||||
declarationStack.addLast(declaration)
|
declarationStack.addLast(declaration)
|
||||||
try {
|
try {
|
||||||
if (declaration is PsiModifierListOwner) {
|
if (declaration is PsiModifierListOwner) {
|
||||||
@@ -75,6 +79,27 @@ open class AbstractSymbolLightClassesParentingTestBase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun visitPsiMemberDeclaration(member: PsiMember) {
|
||||||
|
val containingClass = member.containingClass
|
||||||
|
val expectedClass = declarationStack.lastOrNull()
|
||||||
|
if (expectedClass != null) {
|
||||||
|
assertions.assertEquals(expectedClass, containingClass)
|
||||||
|
}
|
||||||
|
|
||||||
|
val classToCheck: PsiClass = expectedClass?.let { it as PsiClass } ?: containingClass ?: return
|
||||||
|
val memberToCheck = if (member is PsiEnumConstantInitializer) member.enumConstant else member
|
||||||
|
val collection = when (memberToCheck) {
|
||||||
|
is PsiMethod -> classToCheck.methods
|
||||||
|
is PsiField -> classToCheck.fields
|
||||||
|
is PsiClass -> classToCheck.innerClasses
|
||||||
|
else -> error("Unexpected member: ${memberToCheck::class}\nElement: $memberToCheck")
|
||||||
|
}
|
||||||
|
|
||||||
|
assertions.assertTrue(memberToCheck in collection) {
|
||||||
|
"$memberToCheck is not found in:\n${collection.joinToString(separator = "\n")}\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitModifierList(list: PsiModifierList) {
|
override fun visitModifierList(list: PsiModifierList) {
|
||||||
checkParentAndVisitChildren(list, notCheckItself = ignoreDecompiledClasses) { visitor ->
|
checkParentAndVisitChildren(list, notCheckItself = ignoreDecompiledClasses) { visitor ->
|
||||||
annotations.forEach { it.accept(visitor) }
|
annotations.forEach { it.accept(visitor) }
|
||||||
|
|||||||
Reference in New Issue
Block a user