[Analysis API] render extra debug information for nested symbols if renders for outers
This commit is contained in:
+1
-1
@@ -629,7 +629,7 @@ private class BuilderCache<From, To : KtSymbol> {
|
||||
inline fun <reified S : To> cache(key: From, calculation: () -> S): S {
|
||||
val value = cache.getOrPut(key, calculation)
|
||||
return value as? S
|
||||
?: error("Cannot cast ${value::class} to ${S::class}\n${DebugSymbolRenderer.render(value)}")
|
||||
?: error("Cannot cast ${value::class} to ${S::class}\n${value}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -80,7 +80,7 @@ internal class KtFirSymbolContainingDeclarationProvider(
|
||||
val source = symbol.firSymbol.source
|
||||
val thisSource = when (source?.kind) {
|
||||
null -> buildErrorWithAttachment("PSI should present for declaration built by Kotlin code") {
|
||||
withSymbolAttachment("symbolForContainingPsi", symbol)
|
||||
withSymbolAttachment("symbolForContainingPsi", symbol, analysisSession)
|
||||
}
|
||||
|
||||
KtFakeSourceElementKind.ImplicitConstructor ->
|
||||
@@ -92,19 +92,19 @@ internal class KtFirSymbolContainingDeclarationProvider(
|
||||
KtRealSourceElementKind -> source.psi!!
|
||||
else ->
|
||||
buildErrorWithAttachment("errorWithAttachment FirSourceElement: kind=${source.kind} element=${source.psi!!::class.simpleName}") {
|
||||
withSymbolAttachment("symbolForContainingPsi", symbol)
|
||||
withSymbolAttachment("symbolForContainingPsi", symbol, analysisSession)
|
||||
}
|
||||
}
|
||||
|
||||
return when (symbol.origin) {
|
||||
KtSymbolOrigin.SOURCE -> thisSource.getContainingKtDeclaration()
|
||||
?: buildErrorWithAttachment("Containing declaration should present for non-toplevel declaration ${thisSource::class}") {
|
||||
withSymbolAttachment("symbolForContainingPsi", symbol)
|
||||
withSymbolAttachment("symbolForContainingPsi", symbol, analysisSession)
|
||||
}
|
||||
|
||||
KtSymbolOrigin.SOURCE_MEMBER_GENERATED -> thisSource as KtDeclaration
|
||||
else -> buildErrorWithAttachment("Unsupported declaration origin ${symbol.origin} ${thisSource::class}") {
|
||||
withSymbolAttachment("symbolForContainingPsi", symbol)
|
||||
withSymbolAttachment("symbolForContainingPsi", symbol, analysisSession)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -5,17 +5,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.fir.utils
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.DebugSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.withFirEntry
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.ExceptionAttachmentBuilder
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.withPsiEntry
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
|
||||
|
||||
fun ExceptionAttachmentBuilder.withSymbolAttachment(name: String, symbol: KtSymbol) {
|
||||
withEntry(name, symbol, DebugSymbolRenderer::render)
|
||||
fun ExceptionAttachmentBuilder.withSymbolAttachment(name: String, symbol: KtSymbol, analysisSession: KtAnalysisSession) {
|
||||
with(analysisSession) {
|
||||
withEntry(name, symbol) { DebugSymbolRenderer(renderExtra = true).render(it) }
|
||||
}
|
||||
withPsiEntry("${name}Psi", symbol.psi)
|
||||
|
||||
if (symbol is KtFirSymbol<*>) {
|
||||
|
||||
Reference in New Issue
Block a user