[AA] KtTypeInfoProvider: introduce fullyExpandedType extension

^KTIJ-23547
^KTIJ-24141
This commit is contained in:
Dmitrii Gridin
2023-01-17 15:11:38 +01:00
committed by Space Team
parent 8ce4c4eba9
commit 09a77d261d
20 changed files with 293 additions and 34 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 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.
*/
@@ -23,6 +23,7 @@ public abstract class KtTypeInfoProvider : KtAnalysisSessionComponent() {
public abstract fun isDenotable(type: KtType): Boolean
public abstract fun isArrayOrPrimitiveArray(type: KtType): Boolean
public abstract fun isNestedArray(type: KtType): Boolean
public abstract fun fullyExpandedType(type: KtType): KtType
}
public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
@@ -102,6 +103,24 @@ public interface KtTypeInfoProviderMixIn : KtAnalysisSessionMixIn {
}
}
/**
* Unwraps type aliases.
* Example:
* ```
* interface Base
*
* typealias FirstAlias = @Anno1 Base
* typealias SecondAlias = @Anno2 FirstAlias
*
* fun foo(): @Anno3 SecondAlias = TODO()
* ```
* The return type of **foo** will be **@Anno3 @Anno2 @Anno1 Base** instead of **@Anno3 SecondAlias**
*/
public val KtType.fullyExpandedType: KtType
get() = withValidityAssertion {
analysisSession.typeInfoProvider.fullyExpandedType(this)
}
/**
* Returns whether the given [KtType] is an array or a primitive array type or not.
*/
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 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.
*/
@@ -31,4 +31,15 @@ public interface KtUsualClassTypeRenderer {
}
}
public object AS_FULLY_EXPANDED_CLASS_TYPE_WITH_TYPE_ARGUMENTS : KtUsualClassTypeRenderer {
context(KtAnalysisSession, KtTypeRenderer)
override fun renderType(type: KtUsualClassType, printer: PrettyPrinter) {
val fullyExpandedType = type.fullyExpandedType
if (fullyExpandedType is KtUsualClassType) {
AS_CLASS_TYPE_WITH_TYPE_ARGUMENTS.renderType(fullyExpandedType, printer)
} else {
renderType(fullyExpandedType, printer)
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 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.
*/
@@ -41,6 +41,7 @@ import kotlin.reflect.jvm.isAccessible
public class DebugSymbolRenderer(
public val renderExtra: Boolean = false,
public val renderTypeByProperties: Boolean = false,
public val renderExpandedTypes: Boolean = false,
) {
context(KtAnalysisSession)
@@ -200,17 +201,20 @@ public class DebugSymbolRenderer(
context(KtAnalysisSession)
private fun PrettyPrinter.renderType(type: KtType) {
val typeToRender = if (renderExpandedTypes) type.fullyExpandedType else type
if (renderTypeByProperties) {
renderByPropertyNames(type)
renderByPropertyNames(typeToRender)
return
}
if (type.annotations.isNotEmpty()) {
renderList(type.annotations, renderSymbolsFully = false)
if (typeToRender.annotations.isNotEmpty()) {
renderList(typeToRender.annotations, renderSymbolsFully = false)
append(' ')
}
when (type) {
when (typeToRender) {
is KtClassErrorType -> append("ERROR_TYPE")
else -> append(type.asStringForDebugging())
else -> append(typeToRender.asStringForDebugging())
}
}
@@ -0,0 +1,46 @@
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /foo
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: foo
origin: SOURCE
receiverParameter: null
returnType: kotlin/Unit
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: [
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
generatedPrimaryConstructorProperty: null
hasDefaultValue: false
isCrossinline: false
isExtension: false
isImplicitLambdaParameter: false
isNoinline: false
isVararg: false
name: param
origin: SOURCE
receiverParameter: null
returnType: SecondAlias
symbolKind: LOCAL
typeParameters: []
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
]
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
@@ -0,0 +1,8 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
// PRETTY_RENDERER_OPTION: FULLY_EXPANDED_TYPES
interface Base
typealias FirstAlias = Base
typealias SecondAlias = FirstAlias
fun foo<caret>(param: SecondAlias) {}
@@ -0,0 +1 @@
fun foo(param: Base)
@@ -0,0 +1,46 @@
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /foo
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: foo
origin: SOURCE
receiverParameter: null
returnType: kotlin/Unit
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: [
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
generatedPrimaryConstructorProperty: null
hasDefaultValue: false
isCrossinline: false
isExtension: false
isImplicitLambdaParameter: false
isNoinline: false
isVararg: false
name: param
origin: SOURCE
receiverParameter: null
returnType: Base
symbolKind: LOCAL
typeParameters: []
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
]
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
@@ -0,0 +1,26 @@
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /foo
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: foo
origin: SOURCE
receiverParameter: null
returnType: SecondAlias
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
@@ -0,0 +1,8 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
// PRETTY_RENDERER_OPTION: FULLY_EXPANDED_TYPES
interface Base
typealias FirstAlias = Base
typealias SecondAlias = FirstAlias
fun foo<caret>(): SecondAlias {}
@@ -0,0 +1 @@
fun foo(): Base
@@ -0,0 +1,26 @@
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /foo
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: foo
origin: SOURCE
receiverParameter: null
returnType: Base
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: []
visibility: Public
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
@@ -1,5 +1,5 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
// PRETTY_RENDERING_MODE: RENDER_SYMBOLS_NESTED
// PRETTY_RENDERERE_OPTION: BODY_WITH_MEMBERS
annotation class PropertyAnnotation
annotation class FieldAnnotation