FIR/UAST: commonize type reference expression
This commit is contained in:
committed by
teamcityserver
parent
517fd24f14
commit
a3710bed6a
@@ -5,14 +5,17 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtEscapeStringTemplateEntry
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtStringTemplateEntry
|
||||
import org.jetbrains.kotlin.psi.KtStringTemplateEntryWithExpression
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.uast.*
|
||||
|
||||
interface BaseKotlinConverter {
|
||||
|
||||
fun convertReceiverParameter(receiver: KtTypeReference): UParameter? {
|
||||
val call = (receiver.parent as? KtCallableDeclaration) ?: return null
|
||||
if (call.receiverTypeReference != receiver) return null
|
||||
return call.toUElementOfType<UMethod>()?.uastParameters?.firstOrNull()
|
||||
}
|
||||
|
||||
fun convertExpression(
|
||||
expression: KtExpression,
|
||||
givenParent: UElement?,
|
||||
|
||||
+3
@@ -8,6 +8,7 @@ package org.jetbrains.uast.kotlin
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
|
||||
@@ -20,6 +21,8 @@ interface BaseKotlinUastResolveProviderService {
|
||||
|
||||
fun resolveToDeclaration(ktExpression: KtExpression): PsiElement?
|
||||
|
||||
fun resolveToType(ktTypeReference: KtTypeReference, source: UElement): PsiType?
|
||||
|
||||
fun getExpressionType(uExpression: UExpression): PsiType?
|
||||
|
||||
fun evaluate(uExpression: UExpression): Any?
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UTypeReferenceExpression
|
||||
import org.jetbrains.uast.UastErrorType
|
||||
|
||||
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?.let { baseResolveProviderService.resolveToType(it, uastParent ?: this) }
|
||||
?: UastErrorType
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user