FIR: Support DEBUG_INFO_EXPRESSION_TYPE
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
|||||||
|
fun foo(
|
||||||
|
x1: String,
|
||||||
|
x2: Collection<CharSequence>,
|
||||||
|
x3: MutableMap<out CharSequence, in MutableList<*>>
|
||||||
|
) {
|
||||||
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>x1<!>
|
||||||
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Collection<kotlin.CharSequence>")!>x2<!>
|
||||||
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.MutableMap<out kotlin.CharSequence, in kotlin.collections.MutableList<*>>")!>x3<!>
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
FILE: debugExpressionType.kt
|
||||||
|
public final fun foo(x1: R|kotlin/String|, x2: R|kotlin/collections/Collection<kotlin/CharSequence>|, x3: R|kotlin/collections/MutableMap<out kotlin/CharSequence, in kotlin/collections/MutableList<*>>|): R|kotlin/Unit| {
|
||||||
|
R|<local>/x1|
|
||||||
|
R|<local>/x2|
|
||||||
|
R|<local>/x3|
|
||||||
|
}
|
||||||
Generated
+5
@@ -584,6 +584,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/companionInvoke.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/companionInvoke.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("debugExpressionType.kt")
|
||||||
|
public void testDebugExpressionType() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/debugExpressionType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("debugInfoCall.kt")
|
@TestMetadata("debugInfoCall.kt")
|
||||||
public void testDebugInfoCall() throws Exception {
|
public void testDebugInfoCall() throws Exception {
|
||||||
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/debugInfoCall.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/debugInfoCall.kt");
|
||||||
|
|||||||
+5
@@ -584,6 +584,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/companionInvoke.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/companionInvoke.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("debugExpressionType.kt")
|
||||||
|
public void testDebugExpressionType() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/debugExpressionType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("debugInfoCall.kt")
|
@TestMetadata("debugInfoCall.kt")
|
||||||
public void testDebugInfoCall() throws Exception {
|
public void testDebugInfoCall() throws Exception {
|
||||||
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/debugInfoCall.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/debugInfoCall.kt");
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
||||||
@@ -31,6 +33,9 @@ import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
|||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||||
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
|
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitorVoid
|
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitorVoid
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||||
@@ -124,6 +129,14 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() {
|
|||||||
|
|
||||||
object : FirDefaultVisitorVoid() {
|
object : FirDefaultVisitorVoid() {
|
||||||
override fun visitElement(element: FirElement) {
|
override fun visitElement(element: FirElement) {
|
||||||
|
if (element is FirExpression) {
|
||||||
|
result.addIfNotNull(
|
||||||
|
createExpressionTypeDiagnosticIfExpected(
|
||||||
|
element, diagnosedRangesToDiagnosticNames
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
element.acceptChildren(this)
|
element.acceptChildren(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,46 +152,67 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createCallDiagnosticIfExpected(
|
fun createExpressionTypeDiagnosticIfExpected(
|
||||||
|
element: FirExpression,
|
||||||
|
diagnosedRangesToDiagnosticNames: MutableMap<IntRange, MutableSet<String>>
|
||||||
|
): FirDiagnosticWithParameters1<FirSourceElement, String>? =
|
||||||
|
DebugInfoDiagnosticFactory1.EXPRESSION_TYPE.createDebugInfoDiagnostic(element, diagnosedRangesToDiagnosticNames) {
|
||||||
|
element.typeRef.renderAsString((element as? FirExpressionWithSmartcast)?.originalType)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun FirTypeRef.renderAsString(originalTypeRef: FirTypeRef?): String {
|
||||||
|
val type = coneTypeSafe<ConeKotlinType>() ?: return "Type is unknown"
|
||||||
|
val rendered = type.renderForDebugInfo()
|
||||||
|
val originalTypeRendered = originalTypeRef?.coneTypeSafe<ConeKotlinType>()?.renderForDebugInfo() ?: return rendered
|
||||||
|
|
||||||
|
return "$rendered & $originalTypeRendered"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createCallDiagnosticIfExpected(
|
||||||
element: FirElement,
|
element: FirElement,
|
||||||
reference: FirNamedReference,
|
reference: FirNamedReference,
|
||||||
diagnosedRangesToDiagnosticNames: MutableMap<IntRange, MutableSet<String>>
|
diagnosedRangesToDiagnosticNames: MutableMap<IntRange, MutableSet<String>>
|
||||||
|
): FirDiagnosticWithParameters1<FirSourceElement, String>? =
|
||||||
|
DebugInfoDiagnosticFactory1.CALL.createDebugInfoDiagnostic(element, diagnosedRangesToDiagnosticNames) {
|
||||||
|
|
||||||
|
val resolvedSymbol = (reference as? FirResolvedNamedReference)?.resolvedSymbol
|
||||||
|
val fqName = resolvedSymbol?.fqNameUnsafe()
|
||||||
|
Renderers.renderCallInfo(fqName, getTypeOfCall(reference, resolvedSymbol))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun DebugInfoDiagnosticFactory1.createDebugInfoDiagnostic(
|
||||||
|
element: FirElement,
|
||||||
|
diagnosedRangesToDiagnosticNames: MutableMap<IntRange, MutableSet<String>>,
|
||||||
|
argument: () -> String,
|
||||||
): FirDiagnosticWithParameters1<FirSourceElement, String>? {
|
): FirDiagnosticWithParameters1<FirSourceElement, String>? {
|
||||||
val resolvedSymbol = (reference as? FirResolvedNamedReference)?.resolvedSymbol
|
|
||||||
val sourceElement = element.source ?: return null
|
val sourceElement = element.source ?: return null
|
||||||
|
if (diagnosedRangesToDiagnosticNames[sourceElement.startOffset..sourceElement.endOffset]?.contains(this.name) != true) return null
|
||||||
|
|
||||||
val factory = DebugInfoDiagnosticFactory1.CALL
|
val argumentText = argument()
|
||||||
if (diagnosedRangesToDiagnosticNames[sourceElement.startOffset..sourceElement.endOffset]?.contains(factory.name) != true) return null
|
|
||||||
|
|
||||||
val fqName = resolvedSymbol?.fqNameUnsafe()
|
|
||||||
|
|
||||||
val argument = Renderers.renderCallInfo(fqName, getTypeOfCall(reference, resolvedSymbol))
|
|
||||||
|
|
||||||
return when (sourceElement) {
|
return when (sourceElement) {
|
||||||
is FirPsiSourceElement<*> -> FirPsiDiagnosticWithParameters1(
|
is FirPsiSourceElement<*> -> FirPsiDiagnosticWithParameters1(
|
||||||
sourceElement,
|
sourceElement,
|
||||||
argument,
|
argumentText,
|
||||||
factory.severity,
|
severity,
|
||||||
FirDiagnosticFactory1(
|
FirDiagnosticFactory1(
|
||||||
factory.name,
|
name,
|
||||||
factory.severity,
|
severity,
|
||||||
factory
|
this
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
is FirLightSourceElement -> FirLightDiagnosticWithParameters1(
|
is FirLightSourceElement -> FirLightDiagnosticWithParameters1(
|
||||||
sourceElement,
|
sourceElement,
|
||||||
argument,
|
argumentText,
|
||||||
factory.severity,
|
severity,
|
||||||
FirDiagnosticFactory1<FirSourceElement, PsiElement, String>(
|
FirDiagnosticFactory1<FirSourceElement, PsiElement, String>(
|
||||||
factory.name,
|
name,
|
||||||
factory.severity,
|
severity,
|
||||||
factory
|
this
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun AbstractFirBasedSymbol<*>.fqNameUnsafe(): FqNameUnsafe? = when (this) {
|
private fun AbstractFirBasedSymbol<*>.fqNameUnsafe(): FqNameUnsafe? = when (this) {
|
||||||
is FirClassLikeSymbol<*> -> classId.asSingleFqName().toUnsafe()
|
is FirClassLikeSymbol<*> -> classId.asSingleFqName().toUnsafe()
|
||||||
is FirCallableSymbol<*> -> callableId.asFqName().toUnsafe()
|
is FirCallableSymbol<*> -> callableId.asFqName().toUnsafe()
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 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.fir
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
|
|
||||||
|
fun ConeKotlinType.renderForDebugInfo(): String {
|
||||||
|
val nullabilitySuffix = if (this !is ConeKotlinErrorType && this !is ConeClassErrorType) nullability.suffix else ""
|
||||||
|
return when (this) {
|
||||||
|
is ConeTypeVariableType -> "TypeVariable(${this.lookupTag.name})"
|
||||||
|
is ConeDefinitelyNotNullType -> "${original.renderForDebugInfo()}!!"
|
||||||
|
is ConeClassErrorType -> "ERROR CLASS: $reason"
|
||||||
|
is ConeCapturedType -> "CapturedType(${constructor.projection.renderForDebugInfo()})"
|
||||||
|
is ConeClassLikeType -> {
|
||||||
|
buildString {
|
||||||
|
append(lookupTag.classId.asSingleFqName().asString())
|
||||||
|
if (typeArguments.isNotEmpty()) {
|
||||||
|
append(typeArguments.joinToString(prefix = "<", postfix = ">") {
|
||||||
|
it.renderForDebugInfo()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is ConeLookupTagBasedType -> {
|
||||||
|
lookupTag.name.asString()
|
||||||
|
}
|
||||||
|
is ConeFlexibleType -> {
|
||||||
|
buildString {
|
||||||
|
append(lowerBound.renderForDebugInfo())
|
||||||
|
append("..")
|
||||||
|
append(upperBound.renderForDebugInfo())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is ConeIntersectionType -> {
|
||||||
|
intersectedTypes.joinToString(
|
||||||
|
separator = " & ",
|
||||||
|
) { it.renderForDebugInfo() }
|
||||||
|
}
|
||||||
|
is ConeStubType -> "Stub: $variable"
|
||||||
|
is ConeIntegerLiteralType -> "ILT: $value"
|
||||||
|
} + nullabilitySuffix
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ConeTypeProjection.renderForDebugInfo(): String {
|
||||||
|
return when (this) {
|
||||||
|
ConeStarProjection -> "*"
|
||||||
|
is ConeKotlinTypeProjectionIn -> "in ${type.renderForDebugInfo()}"
|
||||||
|
is ConeKotlinTypeProjectionOut -> "out ${type.renderForDebugInfo()}"
|
||||||
|
is ConeKotlinType -> renderForDebugInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user