FirRenderer: add renderAllModifiers and renderDetailedTypeReferences
Related to KT-52020
This commit is contained in:
+1
-1
@@ -82,4 +82,4 @@ KtErrorCallInfo:
|
||||
callableIdIfNonLocal = null)
|
||||
}
|
||||
]
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [public final fun function(a: R|kotlin/Char|): R|kotlin/Unit|, public final fun function(b: R|kotlin/Boolean|): R|kotlin/Unit|, public final fun function(c: R|kotlin/String|): R|kotlin/Unit|]>
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [fun function(a: Char): Unit, fun function(b: Boolean): Unit, fun function(c: String): Unit]>
|
||||
Vendored
+1
-1
@@ -47,4 +47,4 @@ KtErrorCallInfo:
|
||||
typeArgumentsMapping = {}
|
||||
argumentMapping = {}
|
||||
]
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [local final operator fun R|kotlin/Int|.invoke(a: R|kotlin/String|): R|kotlin/Unit|, local final operator fun R|kotlin/Int|.invoke(b: R|kotlin/Boolean|): R|kotlin/Unit|]>
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [fun Int.invoke(a: String): Unit, fun Int.invoke(b: Boolean): Unit]>
|
||||
+1
-1
@@ -106,4 +106,4 @@ KtErrorCallInfo:
|
||||
callableIdIfNonLocal = null)
|
||||
}
|
||||
]
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [public final fun <T> function(t: R|T|, a: R|kotlin/Char|): R|kotlin/Unit|, public final fun <U> function(u: R|U|, b: R|kotlin/Boolean|): R|kotlin/Unit|, public final fun <V> function(v: R|V|, c: R|kotlin/String|): R|kotlin/Unit|]>
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [fun <T> function(t: T, a: Char): Unit, fun <U> function(u: U, b: Boolean): Unit, fun <V> function(v: V, c: String): Unit]>
|
||||
+1
-1
@@ -100,4 +100,4 @@ KtErrorCallInfo:
|
||||
callableIdIfNonLocal = null)
|
||||
}
|
||||
]
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [public final fun <T> function(t: R|T|, a: R|kotlin/Char|): R|kotlin/Unit|, public final fun <U> function(u: R|U|, b: R|kotlin/Boolean|): R|kotlin/Unit|, public final fun <V> function(v: R|V|, c: R|kotlin/String|): R|kotlin/Unit|]>
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [fun <T> function(t: T, a: Char): Unit, fun <U> function(u: U, b: Boolean): Unit, fun <V> function(v: V, c: String): Unit]>
|
||||
+1
-1
@@ -47,4 +47,4 @@ KtErrorCallInfo:
|
||||
typeArgumentsMapping = {}
|
||||
argumentMapping = {}
|
||||
]
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [public constructor(p: R|kotlin/Int|): R|Sub|, public constructor(i: R|kotlin/Int|, j: R|kotlin/Int|): R|Sub|]>
|
||||
diagnostic = ERROR<NONE_APPLICABLE: None of the following functions are applicable: [public constructor(p: Int): Sub, public constructor(i: Int, j: Int): Sub]>
|
||||
+1
-1
@@ -14,4 +14,4 @@ KtErrorCallInfo:
|
||||
typeArgumentsMapping = {}
|
||||
argumentMapping = {}
|
||||
]
|
||||
diagnostic = ERROR<INVISIBLE_REFERENCE: Symbol private constructor(): R|Obj| is invisible>
|
||||
diagnostic = ERROR<INVISIBLE_REFERENCE: Symbol private constructor(): Obj is invisible>
|
||||
+1
-1
@@ -17,4 +17,4 @@ KtErrorCallInfo:
|
||||
typeArgumentsMapping = {}
|
||||
argumentMapping = {}
|
||||
]
|
||||
diagnostic = ERROR<INVISIBLE_REFERENCE: Symbol private final fun foo(): R|kotlin/Unit| is invisible>
|
||||
diagnostic = ERROR<INVISIBLE_REFERENCE: Symbol fun foo(): Unit is invisible>
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
KtInapplicableCallCandidateInfo:
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [public final operator fun R|kotlin/Double|.invoke(): R|kotlin/Unit|]>
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [fun Double.invoke(): Unit]>
|
||||
candidate = KtSimpleFunctionCall:
|
||||
isImplicitInvoke = true
|
||||
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
|
||||
@@ -38,7 +38,7 @@ KtApplicableCallCandidateInfo:
|
||||
isInBestCandidates = true
|
||||
|
||||
KtInapplicableCallCandidateInfo:
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [public final operator fun R|kotlin/Long|.invoke(): R|kotlin/Double|]>
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [fun Long.invoke(): Double]>
|
||||
candidate = KtSimpleFunctionCall:
|
||||
isImplicitInvoke = true
|
||||
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
KtInapplicableCallCandidateInfo:
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [public final operator fun R|kotlin/Double|.invoke(): R|kotlin/Unit|]>
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [fun Double.invoke(): Unit]>
|
||||
candidate = KtSimpleFunctionCall:
|
||||
isImplicitInvoke = true
|
||||
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
|
||||
@@ -19,7 +19,7 @@ KtInapplicableCallCandidateInfo:
|
||||
isInBestCandidates = false
|
||||
|
||||
KtInapplicableCallCandidateInfo:
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [public final operator fun R|kotlin/Int|.invoke(): R|kotlin/Long|]>
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [fun Int.invoke(): Long]>
|
||||
candidate = KtSimpleFunctionCall:
|
||||
isImplicitInvoke = true
|
||||
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ KtApplicableCallCandidateInfo:
|
||||
isInBestCandidates = true
|
||||
|
||||
KtInapplicableCallCandidateInfo:
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [public final operator fun R|kotlin/Int|.invoke(): R|kotlin/Long|]>
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [fun Int.invoke(): Long]>
|
||||
candidate = KtSimpleFunctionCall:
|
||||
isImplicitInvoke = true
|
||||
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
|
||||
@@ -38,7 +38,7 @@ KtInapplicableCallCandidateInfo:
|
||||
isInBestCandidates = false
|
||||
|
||||
KtInapplicableCallCandidateInfo:
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [public final operator fun R|kotlin/Long|.invoke(): R|kotlin/Double|]>
|
||||
diagnostic = ERROR<UNRESOLVED_REFERENCE_WRONG_RECEIVER: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: [fun Long.invoke(): Double]>
|
||||
candidate = KtSimpleFunctionCall:
|
||||
isImplicitInvoke = true
|
||||
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtInapplicableCallCandidateInfo:
|
||||
diagnostic = ERROR<INVISIBLE_REFERENCE: Symbol private constructor(): R|Obj| is invisible>
|
||||
diagnostic = ERROR<INVISIBLE_REFERENCE: Symbol private constructor(): Obj is invisible>
|
||||
candidate = KtSimpleFunctionCall:
|
||||
isImplicitInvoke = false
|
||||
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtInapplicableCallCandidateInfo:
|
||||
diagnostic = ERROR<INVISIBLE_REFERENCE: Symbol private final fun foo(): R|kotlin/Unit| is invisible>
|
||||
diagnostic = ERROR<INVISIBLE_REFERENCE: Symbol fun foo(): Unit is invisible>
|
||||
candidate = KtSimpleFunctionCall:
|
||||
isImplicitInvoke = false
|
||||
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
|
||||
|
||||
@@ -9,20 +9,24 @@ import org.jetbrains.kotlin.builtins.functions.FunctionClassKind
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
fun ConeKotlinType.render(): String {
|
||||
fun ConeKotlinType.render(renderFqNames: Boolean = true): String {
|
||||
val nullabilitySuffix = if (this !is ConeFlexibleType && this !is ConeErrorType) nullability.suffix else ""
|
||||
return when (this) {
|
||||
is ConeTypeVariableType -> "${renderAttributes()}TypeVariable(${this.lookupTag.name})"
|
||||
is ConeDefinitelyNotNullType -> "${original.render()} & Any"
|
||||
is ConeDefinitelyNotNullType -> "${original.render(renderFqNames)} & Any"
|
||||
is ConeErrorType -> "${renderAttributes()}ERROR CLASS: ${diagnostic.reason}"
|
||||
is ConeCapturedType -> "${renderAttributes()}CapturedType(${constructor.projection.render()})"
|
||||
is ConeCapturedType -> "${renderAttributes()}CapturedType(${constructor.projection.render(renderFqNames)})"
|
||||
is ConeClassLikeType -> {
|
||||
buildString {
|
||||
append(renderAttributes())
|
||||
append(lookupTag.classId.asString())
|
||||
if (renderFqNames) {
|
||||
append(lookupTag.classId.asString())
|
||||
} else {
|
||||
append(lookupTag.classId.relativeClassName.asString())
|
||||
}
|
||||
if (typeArguments.isNotEmpty()) {
|
||||
append(typeArguments.joinToString(prefix = "<", postfix = ">") {
|
||||
it.render()
|
||||
it.render(renderFqNames)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -31,13 +35,15 @@ fun ConeKotlinType.render(): String {
|
||||
"${renderAttributes()}${lookupTag.name.asString()}"
|
||||
}
|
||||
is ConeDynamicType -> "dynamic"
|
||||
is ConeFlexibleType -> this.render()
|
||||
is ConeFlexibleType -> this.render(renderFqNames)
|
||||
is ConeIntersectionType -> {
|
||||
intersectedTypes.joinToString(
|
||||
separator = " & ",
|
||||
prefix = "${renderAttributes()}it(",
|
||||
postfix = ")"
|
||||
)
|
||||
) {
|
||||
it.render(renderFqNames)
|
||||
}
|
||||
}
|
||||
is ConeStubTypeForSyntheticFixation -> "${renderAttributes()}Stub (fixation): ${constructor.variable}"
|
||||
is ConeStubTypeForChainInference -> "${renderAttributes()}Stub (chain inference): ${constructor.variable}"
|
||||
@@ -47,12 +53,12 @@ fun ConeKotlinType.render(): String {
|
||||
} + nullabilitySuffix
|
||||
}
|
||||
|
||||
private fun ConeFlexibleType.render(): String =
|
||||
private fun ConeFlexibleType.render(renderFqNames: Boolean): String =
|
||||
buildString {
|
||||
append("ft<")
|
||||
append(lowerBound.render())
|
||||
append(lowerBound.render(renderFqNames))
|
||||
append(", ")
|
||||
append(upperBound.render())
|
||||
append(upperBound.render(renderFqNames))
|
||||
append(">")
|
||||
}
|
||||
|
||||
@@ -61,18 +67,18 @@ private fun ConeKotlinType.renderAttributes(): String {
|
||||
return attributes.joinToString(" ", postfix = " ") { it.toString() }
|
||||
}
|
||||
|
||||
fun ConeTypeProjection.render(): String {
|
||||
fun ConeTypeProjection.render(renderFqNames: Boolean): String {
|
||||
return when (this) {
|
||||
ConeStarProjection -> "*"
|
||||
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.render()}"
|
||||
is ConeKotlinTypeProjectionIn -> "in ${type.render()}"
|
||||
is ConeKotlinTypeProjectionOut -> "out ${type.render()}"
|
||||
is ConeKotlinType -> render()
|
||||
is ConeKotlinTypeConflictingProjection -> "CONFLICTING-PROJECTION ${type.render(renderFqNames)}"
|
||||
is ConeKotlinTypeProjectionIn -> "in ${type.render(renderFqNames)}"
|
||||
is ConeKotlinTypeProjectionOut -> "out ${type.render(renderFqNames)}"
|
||||
is ConeKotlinType -> render(renderFqNames)
|
||||
}
|
||||
}
|
||||
|
||||
fun ConeKotlinType.renderFunctionType(
|
||||
kind: FunctionClassKind?, renderType: ConeTypeProjection.() -> String = { render() }
|
||||
kind: FunctionClassKind?, renderFqNames: Boolean, renderType: ConeTypeProjection.() -> String = { render(renderFqNames) }
|
||||
): String {
|
||||
if (!kind.withPrettyRender()) return renderType()
|
||||
|
||||
|
||||
@@ -66,6 +66,8 @@ open class FirRenderer(builder: StringBuilder, protected val mode: RenderMode =
|
||||
val renderPackageDirective: Boolean = false,
|
||||
val renderNestedDeclarations: Boolean = true,
|
||||
val renderDefaultParameterValues: Boolean = true,
|
||||
val renderDetailedTypeReferences: Boolean = true,
|
||||
val renderAllModifiers: Boolean = true,
|
||||
) {
|
||||
companion object {
|
||||
val Normal = RenderMode(
|
||||
@@ -124,6 +126,8 @@ open class FirRenderer(builder: StringBuilder, protected val mode: RenderMode =
|
||||
renderPackageDirective = false,
|
||||
renderNestedDeclarations = false,
|
||||
renderDefaultParameterValues = false,
|
||||
renderDetailedTypeReferences = false,
|
||||
renderAllModifiers = false,
|
||||
)
|
||||
|
||||
val WithDeclarationAttributes = RenderMode(
|
||||
@@ -236,7 +240,6 @@ open class FirRenderer(builder: StringBuilder, protected val mode: RenderMode =
|
||||
|
||||
override fun visitCallableDeclaration(callableDeclaration: FirCallableDeclaration) {
|
||||
renderContexts(callableDeclaration.contextReceivers)
|
||||
callableDeclaration.contextReceivers
|
||||
callableDeclaration.annotations.renderAnnotations()
|
||||
visitMemberDeclaration(callableDeclaration)
|
||||
val receiverType = callableDeclaration.receiverTypeRef
|
||||
@@ -338,7 +341,7 @@ open class FirRenderer(builder: StringBuilder, protected val mode: RenderMode =
|
||||
}
|
||||
|
||||
override fun visitMemberDeclaration(memberDeclaration: FirMemberDeclaration) {
|
||||
if (memberDeclaration !is FirProperty || !memberDeclaration.isLocal) {
|
||||
if (mode.renderAllModifiers && (memberDeclaration !is FirProperty || !memberDeclaration.isLocal)) {
|
||||
// we can't access session.effectiveVisibilityResolver from here!
|
||||
// print(memberDeclaration.visibility.asString(memberDeclaration.getEffectiveVisibility(...)) + " ")
|
||||
print(memberDeclaration.visibility.asString() + " ")
|
||||
@@ -350,11 +353,13 @@ open class FirRenderer(builder: StringBuilder, protected val mode: RenderMode =
|
||||
if (memberDeclaration.isActual) {
|
||||
print("actual ")
|
||||
}
|
||||
if (memberDeclaration.isExternal) {
|
||||
print("external ")
|
||||
}
|
||||
if (memberDeclaration.isOverride) {
|
||||
print("override ")
|
||||
if (mode.renderAllModifiers) {
|
||||
if (memberDeclaration.isExternal) {
|
||||
print("external ")
|
||||
}
|
||||
if (memberDeclaration.isOverride) {
|
||||
print("override ")
|
||||
}
|
||||
}
|
||||
if (memberDeclaration.isStatic) {
|
||||
print("static ")
|
||||
@@ -379,26 +384,28 @@ open class FirRenderer(builder: StringBuilder, protected val mode: RenderMode =
|
||||
print("fun ")
|
||||
}
|
||||
|
||||
if (memberDeclaration.isInline) {
|
||||
print("inline ")
|
||||
}
|
||||
if (memberDeclaration.isOperator) {
|
||||
print("operator ")
|
||||
}
|
||||
if (memberDeclaration.isInfix) {
|
||||
print("infix ")
|
||||
}
|
||||
if (memberDeclaration.isTailRec) {
|
||||
print("tailrec ")
|
||||
}
|
||||
if (memberDeclaration.isSuspend) {
|
||||
print("suspend ")
|
||||
}
|
||||
if (memberDeclaration.isConst) {
|
||||
print("const ")
|
||||
}
|
||||
if (memberDeclaration.isLateInit) {
|
||||
print("lateinit ")
|
||||
if (mode.renderAllModifiers) {
|
||||
if (memberDeclaration.isInline) {
|
||||
print("inline ")
|
||||
}
|
||||
if (memberDeclaration.isOperator) {
|
||||
print("operator ")
|
||||
}
|
||||
if (memberDeclaration.isInfix) {
|
||||
print("infix ")
|
||||
}
|
||||
if (memberDeclaration.isTailRec) {
|
||||
print("tailrec ")
|
||||
}
|
||||
if (memberDeclaration.isSuspend) {
|
||||
print("suspend ")
|
||||
}
|
||||
if (memberDeclaration.isConst) {
|
||||
print("const ")
|
||||
}
|
||||
if (memberDeclaration.isLateInit) {
|
||||
print("lateinit ")
|
||||
}
|
||||
}
|
||||
|
||||
visitDeclaration(memberDeclaration as FirDeclaration)
|
||||
@@ -1128,10 +1135,14 @@ open class FirRenderer(builder: StringBuilder, protected val mode: RenderMode =
|
||||
|
||||
override fun visitResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef) {
|
||||
val kind = resolvedTypeRef.functionTypeKind
|
||||
print("R|")
|
||||
if (mode.renderDetailedTypeReferences) {
|
||||
print("R|")
|
||||
}
|
||||
val coneType = resolvedTypeRef.type
|
||||
print(coneType.renderFunctionType(kind))
|
||||
print("|")
|
||||
print(coneType.renderFunctionType(kind, renderFqNames = mode.renderDetailedTypeReferences))
|
||||
if (mode.renderDetailedTypeReferences) {
|
||||
print("|")
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitUserTypeRef(userTypeRef: FirUserTypeRef) {
|
||||
|
||||
+3
-3
@@ -1,15 +1,15 @@
|
||||
warning: ATTENTION!
|
||||
This build uses experimental K2 compiler:
|
||||
-Xuse-k2
|
||||
compiler/testData/cli/jvm/firDeprecationJava.kt:3:12: warning: '@R|kotlin/Deprecated|(...) public final fun stop(): R|kotlin/Unit|
|
||||
compiler/testData/cli/jvm/firDeprecationJava.kt:3:12: warning: '@Deprecated(...) fun stop(): Unit
|
||||
' is deprecated. Deprecated in Java
|
||||
thread.stop()
|
||||
^
|
||||
compiler/testData/cli/jvm/firDeprecationJava.kt:4:17: warning: '@R|kotlin/Deprecated|(...) public open fun bar(a: R|ft<kotlin/String, kotlin/String?>|, b: R|kotlin/Int|, c: R|kotlin/Double|): R|ft<kotlin/String, kotlin/String?>|
|
||||
compiler/testData/cli/jvm/firDeprecationJava.kt:4:17: warning: '@Deprecated(...) fun bar(a: ft<String, String?>, b: Int, c: Double): ft<String, String?>
|
||||
' is deprecated. Deprecated in Java
|
||||
JavaClass().bar("", 1, 2.0)
|
||||
^
|
||||
compiler/testData/cli/jvm/firDeprecationJava.kt:5:27: warning: '@R|kotlin/Deprecated|(...) public open field baz: R|ft<List, List?>|
|
||||
compiler/testData/cli/jvm/firDeprecationJava.kt:5:27: warning: '@Deprecated(...) field baz: ft<List, List?>
|
||||
' is deprecated. Deprecated in Java
|
||||
val baz = JavaClass().baz
|
||||
^
|
||||
|
||||
+2
-2
@@ -324,7 +324,7 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
|
||||
|
||||
private fun ConeTypeProjection.tryToRenderConeAsFunctionType(): String {
|
||||
if (this !is ConeKotlinType) return localTypeRenderer()
|
||||
val functionType = renderFunctionType(functionTypeKind) { localTypeRenderer() }
|
||||
val functionType = renderFunctionType(functionTypeKind, renderFqNames = true) { localTypeRenderer() }
|
||||
return functionType.removeCurrentFilePackage()
|
||||
}
|
||||
|
||||
@@ -429,7 +429,7 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
|
||||
intersectedTypes.map { it.render().replace("/", ".").replace("kotlin.", "") }.sorted()
|
||||
.joinToString(separator = " & ", prefix = "{", postfix = "}")
|
||||
}
|
||||
else -> this.render()
|
||||
else -> this.render(renderFqNames = true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user