[DLC] add missing visitor methods
Some of our light classes have no correct parent (KT-56882), so I temporarily disabled AbstractSymbolLightClassesParentingTestBase for such cases (previously decompiled light classes were not tested at all) ^KT-56613 ^KT-56882
This commit is contained in:
committed by
Space Team
parent
0bd193ccba
commit
95455c9870
+11
-1
@@ -5,8 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
||||
|
||||
import com.intellij.psi.JavaElementVisitor
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import org.jetbrains.kotlin.asJava.classes.KtExtensibleLightClass
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
@@ -15,4 +17,12 @@ abstract class KtLightClassForDecompiledDeclarationBase(
|
||||
val clsDelegate: PsiClass,
|
||||
clsParent: PsiElement,
|
||||
final override val kotlinOrigin: KtClassOrObject?
|
||||
) : KtLightElementBase(clsParent), PsiClass, KtExtensibleLightClass
|
||||
) : KtLightElementBase(clsParent), PsiClass, KtExtensibleLightClass {
|
||||
override fun accept(visitor: PsiElementVisitor) {
|
||||
if (visitor is JavaElementVisitor) {
|
||||
visitor.visitClass(this)
|
||||
} else {
|
||||
visitor.visitElement(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -34,4 +34,12 @@ internal class KtLightEnumClassForDecompiledDeclaration(
|
||||
|
||||
override fun equals(other: Any?): Boolean = this === other || other is KtLightEnumClassForDecompiledDeclaration && super.equals(other)
|
||||
override fun hashCode(): Int = super.hashCode()
|
||||
}
|
||||
|
||||
override fun accept(visitor: PsiElementVisitor) {
|
||||
if (visitor is JavaElementVisitor) {
|
||||
visitor.visitEnumConstantInitializer(this)
|
||||
} else {
|
||||
visitor.visitElement(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -44,4 +44,12 @@ internal class KtLightEnumEntryForDecompiledDeclaration(
|
||||
fldDelegate == other.fldDelegate
|
||||
|
||||
override fun hashCode(): Int = super.hashCode()
|
||||
}
|
||||
|
||||
override fun accept(visitor: PsiElementVisitor) {
|
||||
if (visitor is JavaElementVisitor) {
|
||||
visitor.visitEnumConstant(this)
|
||||
} else {
|
||||
visitor.visitElement(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -77,4 +77,12 @@ open class KtLightFieldForDecompiledDeclaration(
|
||||
another is KtLightFieldForDecompiledDeclaration && fldDelegate.isEquivalentTo(another.fldDelegate) ||
|
||||
fldDelegate.isEquivalentTo(another)
|
||||
}
|
||||
}
|
||||
|
||||
override fun accept(visitor: PsiElementVisitor) {
|
||||
if (visitor is JavaElementVisitor) {
|
||||
visitor.visitField(this)
|
||||
} else {
|
||||
visitor.visitElement(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -109,10 +109,18 @@ class KtLightMethodForDecompiledDeclaration(
|
||||
another is KtLightMethodForDecompiledDeclaration && funDelegate.isEquivalentTo(another.funDelegate) ||
|
||||
funDelegate.isEquivalentTo(another)
|
||||
}
|
||||
|
||||
override fun accept(visitor: PsiElementVisitor) {
|
||||
if (visitor is JavaElementVisitor) {
|
||||
visitor.visitMethod(this)
|
||||
} else {
|
||||
visitor.visitElement(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtLightMethod.checkIsMangled(): Boolean {
|
||||
val demangledName = demangleInternalName(name) ?: return false
|
||||
val originalName = propertyNameByAccessor(demangledName, this) ?: demangledName
|
||||
return originalName == kotlinOrigin?.name
|
||||
}
|
||||
}
|
||||
|
||||
+22
-13
@@ -40,15 +40,20 @@ open class AbstractSymbolLightClassesParentingTestBase(
|
||||
protected fun createLightElementsVisitor(directives: RegisteredDirectives, assertions: AssertionsService): JavaElementVisitor {
|
||||
Assume.assumeFalse("The test is not supported", Directives.IGNORE_PARENTING_CHECK in directives)
|
||||
|
||||
// drop after KT-56882
|
||||
val ignoreDecompiledClasses = stopIfCompilationErrorDirectivePresent
|
||||
return object : JavaElementVisitor() {
|
||||
private val declarationStack = ArrayDeque<PsiElement>()
|
||||
|
||||
private fun <T : PsiElement> checkParentAndVisitChildren(
|
||||
declaration: T?,
|
||||
notCheckItself: Boolean = false,
|
||||
action: T.(visitor: JavaElementVisitor) -> Unit = {},
|
||||
) {
|
||||
if (declaration == null) return
|
||||
checkDeclarationParent(declaration)
|
||||
if (!notCheckItself) {
|
||||
checkDeclarationParent(declaration)
|
||||
}
|
||||
|
||||
declarationStack.addLast(declaration)
|
||||
try {
|
||||
@@ -72,19 +77,19 @@ open class AbstractSymbolLightClassesParentingTestBase(
|
||||
}
|
||||
|
||||
override fun visitModifierList(list: PsiModifierList?) {
|
||||
checkParentAndVisitChildren(list) { visitor ->
|
||||
checkParentAndVisitChildren(list, notCheckItself = ignoreDecompiledClasses) { visitor ->
|
||||
annotations.forEach { it.accept(visitor) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitParameterList(list: PsiParameterList?) {
|
||||
checkParentAndVisitChildren(list) { visitor ->
|
||||
checkParentAndVisitChildren(list, notCheckItself = ignoreDecompiledClasses) { visitor ->
|
||||
parameters.forEach { it.accept(visitor) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypeParameterList(list: PsiTypeParameterList?) {
|
||||
checkParentAndVisitChildren(list) { visitor ->
|
||||
checkParentAndVisitChildren(list, notCheckItself = ignoreDecompiledClasses) { visitor ->
|
||||
typeParameters.forEach { it.accept(visitor) }
|
||||
}
|
||||
}
|
||||
@@ -108,6 +113,8 @@ open class AbstractSymbolLightClassesParentingTestBase(
|
||||
}
|
||||
|
||||
override fun visitMethod(method: PsiMethod?) {
|
||||
if (method is SyntheticElement) return
|
||||
|
||||
checkParentAndVisitChildren(method) { visitor ->
|
||||
annotations.forEach { it.accept(visitor) }
|
||||
|
||||
@@ -150,17 +157,19 @@ open class AbstractSymbolLightClassesParentingTestBase(
|
||||
(lastDeclaration as PsiModifierList).parent
|
||||
} as PsiModifierListOwner
|
||||
|
||||
when (psiModifierListOwner) {
|
||||
is PsiClass,
|
||||
is PsiParameter ->
|
||||
assertions.assertTrue(owner is SymbolLightClassModifierList<*>)
|
||||
if (!ignoreDecompiledClasses) {
|
||||
when (psiModifierListOwner) {
|
||||
is PsiClass,
|
||||
is PsiParameter ->
|
||||
assertions.assertTrue(owner is SymbolLightClassModifierList<*>)
|
||||
|
||||
is PsiField,
|
||||
is PsiMethod ->
|
||||
assertions.assertTrue(owner is SymbolLightMemberModifierList<*>)
|
||||
is PsiField,
|
||||
is PsiMethod ->
|
||||
assertions.assertTrue(owner is SymbolLightMemberModifierList<*>)
|
||||
|
||||
else ->
|
||||
throw IllegalStateException("Unexpected annotation owner kind: ${lastDeclaration::class.java}")
|
||||
else ->
|
||||
throw IllegalStateException("Unexpected annotation owner kind: ${lastDeclaration::class.java}")
|
||||
}
|
||||
}
|
||||
|
||||
val modifierList = psiModifierListOwner.modifierList!!
|
||||
|
||||
Reference in New Issue
Block a user