Uast: WrappedUAnnotation as replacement for usage of JavaUAnnotation (KT-21025)
This commit is contained in:
committed by
Nikolay Krasko
parent
53d6c17417
commit
f0723a5c07
@@ -29,6 +29,7 @@ import org.jetbrains.uast.kotlin.declarations.UastLightIdentifier
|
||||
import org.jetbrains.uast.kotlin.internal.KotlinUElementWithComments
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
import org.jetbrains.uast.visitor.UastTypedVisitor
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
abstract class AbstractKotlinUVariable(givenParent: UElement?)
|
||||
@@ -71,7 +72,7 @@ abstract class AbstractKotlinUVariable(givenParent: UElement?)
|
||||
|
||||
override fun getContainingFile(): PsiFile = unwrapFakeFileForLightClass(psi.containingFile)
|
||||
|
||||
override val annotations: List<UAnnotation> by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
|
||||
override val annotations: List<UAnnotation> by lz { psi.annotations.map { WrappedUAnnotation(it, this) } }
|
||||
|
||||
override val typeReference by lz { getLanguagePlugin().convertOpt<UTypeReferenceExpression>(psi.typeElement, this) }
|
||||
|
||||
@@ -79,8 +80,36 @@ abstract class AbstractKotlinUVariable(givenParent: UElement?)
|
||||
get() = UIdentifier(nameIdentifier, this)
|
||||
|
||||
override fun equals(other: Any?) = other is AbstractKotlinUVariable && psi == other.psi
|
||||
|
||||
class WrappedUAnnotation(psiAnnotation: PsiAnnotation, override val uastParent: UElement) : UAnnotation, JvmDeclarationUElement {
|
||||
|
||||
override val javaPsi: PsiAnnotation = psiAnnotation
|
||||
override val psi: PsiAnnotation = javaPsi
|
||||
override val sourcePsi: PsiElement? = null
|
||||
|
||||
override val attributeValues: List<UNamedExpression> by lz {
|
||||
psi.parameterList.attributes.map { WrappedUNamedExpression(it, this) }
|
||||
}
|
||||
|
||||
class WrappedUNamedExpression(pair: PsiNameValuePair, override val uastParent: UElement?) : UNamedExpression, JvmDeclarationUElement {
|
||||
override val name: String? = pair.name
|
||||
override val psi = pair
|
||||
override val javaPsi: PsiElement? = psi
|
||||
override val sourcePsi: PsiElement? = null
|
||||
override val annotations: List<UAnnotation> = emptyList()
|
||||
override val expression: UExpression by lz { toUExpression(psi.value) }
|
||||
}
|
||||
|
||||
override val qualifiedName: String? = psi.qualifiedName
|
||||
override fun findAttributeValue(name: String?): UExpression? = psi.findAttributeValue(name)?.let { toUExpression(it) }
|
||||
override fun findDeclaredAttributeValue(name: String?): UExpression? = psi.findDeclaredAttributeValue(name)?.let { toUExpression(it) }
|
||||
override fun resolve(): PsiClass? = psi.nameReferenceElement?.resolve() as? PsiClass
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun toUExpression(psi: PsiElement?): UExpression = psi.toUElementOfType<UExpression>() ?: UastEmptyExpression
|
||||
|
||||
class KotlinUVariable(
|
||||
psi: PsiVariable,
|
||||
override val sourcePsi: KtElement,
|
||||
@@ -91,8 +120,6 @@ class KotlinUVariable(
|
||||
|
||||
override val psi = javaPsi
|
||||
|
||||
override val annotations by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
|
||||
|
||||
override val typeReference by lz { getLanguagePlugin().convertOpt<UTypeReferenceExpression>(psi.typeElement, this) }
|
||||
|
||||
override fun getInitializer(): PsiExpression? {
|
||||
@@ -110,6 +137,7 @@ class KotlinUVariable(
|
||||
override fun getContainingFile(): PsiFile {
|
||||
return super.getContainingFile()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
open class KotlinUParameter(
|
||||
|
||||
@@ -104,7 +104,6 @@ abstract class AbstractKotlinRenderLogTest : AbstractKotlinUastTest(), RenderLog
|
||||
val jvmDeclaration = node as? JvmDeclarationUElement
|
||||
?: throw AssertionError("${node.javaClass} should implement 'JvmDeclarationUElement'")
|
||||
|
||||
if (jvmDeclaration is JavaUAnnotation) return false // but actually it's strange to meet JavaUAnnotation here
|
||||
if (jvmDeclaration is UIdentifier) return false // probably should be fixed in platform to fully support in in Kotlin
|
||||
|
||||
jvmDeclaration.sourcePsi?.let {
|
||||
|
||||
Reference in New Issue
Block a user