FIR IDE: get the return type of KtDeclaration as PsiType
This commit is contained in:
committed by
Ilya Kirillov
parent
de4c2d35ab
commit
5690b4d8c2
+5
@@ -7,12 +7,14 @@ package org.jetbrains.kotlin.idea.frontend.api.components
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDoubleColonExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
|
||||
public abstract class KtPsiTypeProvider : KtAnalysisSessionComponent() {
|
||||
public abstract fun getPsiTypeForKtExpression(expression: KtExpression, mode: TypeMappingMode): PsiType
|
||||
public abstract fun getPsiTypeForKtDeclaration(ktDeclaration: KtDeclaration, mode: TypeMappingMode): PsiType
|
||||
public abstract fun getPsiTypeForKtTypeReference(ktTypeReference: KtTypeReference, mode: TypeMappingMode): PsiType
|
||||
public abstract fun getPsiTypeForReceiverOfDoubleColonExpression(
|
||||
ktDoubleColonExpression: KtDoubleColonExpression,
|
||||
@@ -24,6 +26,9 @@ public interface KtPsiTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtExpression.getPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType =
|
||||
analysisSession.psiTypeProvider.getPsiTypeForKtExpression(this, mode)
|
||||
|
||||
public fun KtDeclaration.getPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType =
|
||||
analysisSession.psiTypeProvider.getPsiTypeForKtDeclaration(this, mode)
|
||||
|
||||
public fun KtTypeReference.getPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType =
|
||||
analysisSession.psiTypeProvider.getPsiTypeForKtTypeReference(this, mode)
|
||||
|
||||
|
||||
+11
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.idea.frontend.api.fir.components
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
|
||||
@@ -13,6 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFir
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFirOfType
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.api.throwUnexpectedFirElementError
|
||||
import org.jetbrains.kotlin.idea.frontend.api.components.KtPsiTypeProvider
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtFirAnalysisSession
|
||||
@@ -21,6 +23,7 @@ import org.jetbrains.kotlin.idea.frontend.api.tokens.ValidityToken
|
||||
import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDoubleColonExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
@@ -41,6 +44,14 @@ internal class KtFirPsiTypeProvider(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPsiTypeForKtDeclaration(
|
||||
ktDeclaration: KtDeclaration,
|
||||
mode: TypeMappingMode
|
||||
): PsiType = withValidityAssertion {
|
||||
val firDeclaration = ktDeclaration.getOrBuildFirOfType<FirCallableDeclaration>(firResolveState)
|
||||
firDeclaration.returnTypeRef.coneType.asPsiType(mode, ktDeclaration)
|
||||
}
|
||||
|
||||
override fun getPsiTypeForKtTypeReference(
|
||||
ktTypeReference: KtTypeReference,
|
||||
mode: TypeMappingMode
|
||||
|
||||
Reference in New Issue
Block a user