[Analysis API] rework renderer
^KTIJ-23268 fixed
This commit is contained in:
+1
-2
@@ -77,8 +77,7 @@ private constructor(
|
||||
|
||||
override val importOptimizerImpl: KtImportOptimizer = KtFirImportOptimizer(token, firResolveSession)
|
||||
|
||||
override val symbolDeclarationRendererProviderImpl: KtSymbolDeclarationRendererProvider =
|
||||
KtFirSymbolDeclarationRendererProvider(this, token)
|
||||
override val symbolDeclarationRendererProviderImpl: KtSymbolDeclarationRendererProvider = KtFirRendererProvider(this, token)
|
||||
|
||||
override val expressionInfoProviderImpl = KtFirExpressionInfoProvider(this, token)
|
||||
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.kotlin.analysis.api.fir.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.firSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.components.KtRendererProviderImpl
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
|
||||
@OptIn(KtAnalysisApiInternals::class)
|
||||
internal class KtFirRendererProvider(
|
||||
analysisSession: KtAnalysisSession,
|
||||
token: KtLifetimeToken
|
||||
) : KtRendererProviderImpl(analysisSession, token) {
|
||||
override fun renderDeclaration(symbol: KtDeclarationSymbol, renderer: KtDeclarationRenderer): String {
|
||||
symbol.firSymbol.lazyResolveToPhase(FirResolvePhase.BODY_RESOLVE)
|
||||
return super.renderDeclaration(symbol, renderer)
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.kotlin.analysis.api.fir.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtDeclarationRendererOptions
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtSymbolDeclarationRendererProvider
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtTypeRendererOptions
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.renderer.ConeTypeIdeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.renderer.FirIdeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.fir.types.KtFirType
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
|
||||
internal class KtFirSymbolDeclarationRendererProvider(
|
||||
override val analysisSession: KtFirAnalysisSession,
|
||||
override val token: KtLifetimeToken
|
||||
) : KtSymbolDeclarationRendererProvider() {
|
||||
|
||||
override fun render(type: KtType, options: KtTypeRendererOptions): String {
|
||||
require(type is KtFirType)
|
||||
return ConeTypeIdeRenderer(analysisSession.firResolveSession.useSiteFirSession, options).renderType(type.coneType)
|
||||
}
|
||||
|
||||
override fun renderDeclaration(symbol: KtDeclarationSymbol, options: KtDeclarationRendererOptions): String {
|
||||
require(symbol is KtFirSymbol<*>)
|
||||
symbol.firSymbol.lazyResolveToPhase(FirResolvePhase.BODY_RESOLVE)
|
||||
return FirIdeRenderer.render(symbol.firSymbol.fir, options, symbol.firSymbol.fir.moduleData.session)
|
||||
}
|
||||
}
|
||||
+13
-2
@@ -51,13 +51,24 @@ internal class KtFirTypeProvider(
|
||||
) : KtTypeProvider(), KtFirAnalysisSessionComponent {
|
||||
override val builtinTypes: KtBuiltinTypes = KtFirBuiltInTypes(rootModuleSession.builtinTypes, firSymbolBuilder, token)
|
||||
|
||||
override fun approximateToSuperPublicDenotableType(type: KtType): KtType? {
|
||||
override fun approximateToSuperPublicDenotableType(type: KtType, approximateLocalTypes: Boolean): KtType? {
|
||||
require(type is KtFirType)
|
||||
val coneType = type.coneType
|
||||
val approximatedConeType = PublicTypeApproximator.approximateTypeToPublicDenotable(
|
||||
coneType,
|
||||
rootModuleSession,
|
||||
approximateLocalTypes = true,
|
||||
approximateLocalTypes = approximateLocalTypes,
|
||||
)
|
||||
|
||||
return approximatedConeType?.asKtType()
|
||||
}
|
||||
|
||||
override fun approximateToSubPublicDenotableType(type: KtType, approximateLocalTypes: Boolean): KtType? {
|
||||
require(type is KtFirType)
|
||||
val coneType = type.coneType
|
||||
val approximatedConeType = rootModuleSession.typeApproximator.approximateToSubType(
|
||||
coneType,
|
||||
PublicTypeApproximator.PublicApproximatorConfiguration(localTypes = approximateLocalTypes),
|
||||
)
|
||||
|
||||
return approximatedConeType?.asKtType()
|
||||
|
||||
+5
-1
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LLFirResolveSession
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.typeParameterSymbols
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.isNullableAny
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
@@ -41,7 +42,10 @@ internal class KtFirTypeParameterSymbol(
|
||||
override val name: Name get() = withValidityAssertion { firSymbol.name }
|
||||
|
||||
override val upperBounds: List<KtType> by cached {
|
||||
firSymbol.resolvedBounds.map { type -> builder.typeBuilder.buildKtType(type) }
|
||||
firSymbol.resolvedBounds.mapNotNull { type ->
|
||||
if (type.isNullableAny) return@mapNotNull null
|
||||
builder.typeBuilder.buildKtType(type)
|
||||
}
|
||||
}
|
||||
|
||||
override val variance: Variance get() = withValidityAssertion { firSymbol.variance }
|
||||
|
||||
Reference in New Issue
Block a user