From 517fd24f1474adce63bb1ea34cd9254b34a7fd13 Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Tue, 1 Jun 2021 08:26:08 -0700 Subject: [PATCH] UAST: unify implementation/creation of type reference expression --- .../jetbrains/uast/kotlin/KotlinConverter.kt | 4 ++-- .../uast/kotlin/declarations/KotlinUClass.kt | 4 ++-- .../uast/kotlin/declarations/KotlinUMethod.kt | 2 +- .../kotlin/declarations/KotlinUVariable.kt | 2 +- .../KotlinUBinaryExpressionWithType.kt | 4 ++-- .../kotlin/expressions/KotlinUCatchClause.kt | 4 ++-- .../expressions/KotlinUTypeCheckExpression.kt | 4 ++-- .../KotlinUTypeReferenceExpression.kt | 18 +++++------------- 8 files changed, 17 insertions(+), 25 deletions(-) diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinConverter.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinConverter.kt index 9973a2adf35..a037ae66e12 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinConverter.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinConverter.kt @@ -95,7 +95,7 @@ internal object KotlinConverter : BaseKotlinConverter { is KtWhenCondition -> convertWhenCondition(element, givenParent, expectedTypes) is KtTypeReference -> expectedTypes.accommodate( - alternative { LazyKotlinUTypeReferenceExpression(element, givenParent) }, + alternative { KotlinUTypeReferenceExpression(element, givenParent) }, alternative { convertReceiverParameter(element) } ).firstOrNull() is KtConstructorDelegationCall -> @@ -289,7 +289,7 @@ internal object KotlinConverter : BaseKotlinConverter { } val typeRef = condition.typeReference typeReference = typeRef?.let { - LazyKotlinUTypeReferenceExpression(it, this) { typeRef.toPsiType(this, boxed = true) } + KotlinUTypeReferenceExpression(it, this) { typeRef.toPsiType(this, boxed = true) } } } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUClass.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUClass.kt index 2aa6ebc1dc4..8ffdb170026 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUClass.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUClass.kt @@ -49,7 +49,7 @@ abstract class AbstractKotlinUClass(givenParent: UElement?) : KotlinAbstractUEle override val uastSuperTypes: List get() = ktClass?.superTypeListEntries.orEmpty().mapNotNull { it.typeReference }.map { - LazyKotlinUTypeReferenceExpression(it, this) + KotlinUTypeReferenceExpression(it, this) } val delegateExpressions: List @@ -80,7 +80,7 @@ class KotlinSupertypeDelegationUExpression(override val sourcePsi: KtDelegatedSu override val psi: PsiElement? get() = sourcePsi val typeReference: UTypeReferenceExpression? by lazy { - sourcePsi.typeReference?.let { KotlinUTypeReferenceExpression(it.toPsiType(this), it, this) } + sourcePsi.typeReference?.let { KotlinUTypeReferenceExpression(it, this) { it.toPsiType(this) } } } val delegateExpression: UExpression? by lazy { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt index 68af3571b3c..30181778810 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt @@ -119,7 +119,7 @@ open class KotlinUMethod( override val returnTypeReference: UTypeReferenceExpression? by lz { (sourcePsi as? KtCallableDeclaration)?.typeReference?.let { - LazyKotlinUTypeReferenceExpression(it, this) { javaPsi.returnType ?: UastErrorType } + KotlinUTypeReferenceExpression(it, this) { javaPsi.returnType ?: UastErrorType } } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt index 402b18db5ec..cb9dc5fbb62 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt @@ -95,7 +95,7 @@ abstract class AbstractKotlinUVariable(givenParent: UElement?) : KotlinAbstractU protected abstract fun acceptsAnnotationTarget(target: AnnotationUseSiteTarget?): Boolean override val typeReference: UTypeReferenceExpression? by lz { - KotlinUTypeReferenceExpression(type, (sourcePsi as? KtCallableDeclaration)?.typeReference, this) + KotlinUTypeReferenceExpression((sourcePsi as? KtCallableDeclaration)?.typeReference, this) { type } } override val uastAnchor: UIdentifier? diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUBinaryExpressionWithType.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUBinaryExpressionWithType.kt index c30625bf547..45986ee65fd 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUBinaryExpressionWithType.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUBinaryExpressionWithType.kt @@ -32,7 +32,7 @@ class KotlinUBinaryExpressionWithType( override val type by lz { sourcePsi.right.toPsiType(this) } override val typeReference by lz { - sourcePsi.right?.let { LazyKotlinUTypeReferenceExpression(it, this) } + sourcePsi.right?.let { KotlinUTypeReferenceExpression(it, this) } } override val operationKind = when (sourcePsi.operationReference.getReferencedNameElementType()) { @@ -56,4 +56,4 @@ class KotlinCustomUBinaryExpressionWithType( override var typeReference: UTypeReferenceExpression? = null internal set -} \ No newline at end of file +} diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCatchClause.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCatchClause.kt index daf55dbcb07..051e8033e26 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCatchClause.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUCatchClause.kt @@ -45,7 +45,7 @@ class KotlinUCatchClause( override val typeReferences by lz { val parameter = sourcePsi.catchParameter ?: return@lz emptyList() val typeReference = parameter.typeReference ?: return@lz emptyList() - listOf(LazyKotlinUTypeReferenceExpression(typeReference, this) { typeReference.toPsiType(this, boxed = true) }) + listOf(KotlinUTypeReferenceExpression(typeReference, this) { typeReference.toPsiType(this, boxed = true) }) } // equal to IDEA 202 implementation @@ -59,4 +59,4 @@ class KotlinUCatchClause( // equal to IDEA 202 implementation override fun asRenderString(): String = "catch (${parameters.joinToString { it.asRenderString() }}) ${body.asRenderString()}" -} \ No newline at end of file +} diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTypeCheckExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTypeCheckExpression.kt index d6f655d6436..04e68958488 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTypeCheckExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTypeCheckExpression.kt @@ -30,7 +30,7 @@ class KotlinUTypeCheckExpression( override val type by lz { sourcePsi.typeReference.toPsiType(this) } override val typeReference = sourcePsi.typeReference?.let { - LazyKotlinUTypeReferenceExpression(it, this) { it.toPsiType(this) } + KotlinUTypeReferenceExpression(it, this) { it.toPsiType(this) } } override val operationKind = @@ -38,4 +38,4 @@ class KotlinUTypeCheckExpression( KotlinBinaryExpressionWithTypeKinds.NEGATED_INSTANCE_CHECK else UastBinaryExpressionWithTypeKind.INSTANCE_CHECK -} \ No newline at end of file +} diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTypeReferenceExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTypeReferenceExpression.kt index 1c480406b60..1352304aa63 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTypeReferenceExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUTypeReferenceExpression.kt @@ -1,23 +1,15 @@ package org.jetbrains.uast.kotlin -import com.intellij.psi.PsiElement import com.intellij.psi.PsiType import org.jetbrains.kotlin.psi.KtTypeReference import org.jetbrains.uast.UElement import org.jetbrains.uast.UTypeReferenceExpression -open class KotlinUTypeReferenceExpression( - override val type: PsiType, - override val psi: PsiElement?, - givenParent: UElement? -) : KotlinAbstractUExpression(givenParent), UTypeReferenceExpression, KotlinUElementWithType - - -class LazyKotlinUTypeReferenceExpression( - override val sourcePsi: KtTypeReference, - givenParent: UElement?, - private val typeSupplier: (() -> PsiType)? = null -) : KotlinAbstractUExpression(givenParent), UTypeReferenceExpression { +class KotlinUTypeReferenceExpression( + override val sourcePsi: KtTypeReference?, + givenParent: UElement?, + private val typeSupplier: (() -> PsiType)? = null +) : KotlinAbstractUExpression(givenParent), UTypeReferenceExpression, KotlinUElementWithType { override val type: PsiType by lz { typeSupplier?.invoke() ?: sourcePsi.toPsiType(uastParent ?: this) }