[Analysis API] add more debug info to "pointer already disposed" error
This commit is contained in:
committed by
Space Team
parent
94faa759cb
commit
c37ee83791
+3
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.relfection.renderAsDataClassToString
|
||||
|
||||
/**
|
||||
* `KtSymbol` is valid only during read action it was created in
|
||||
@@ -36,6 +37,8 @@ public abstract class KtSymbolPointer<out S : KtSymbol> {
|
||||
* @return **true** if [other] pointer can be restored to the same symbol. The operation is symmetric and transitive.
|
||||
*/
|
||||
public open fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other
|
||||
|
||||
override fun toString(): String = renderAsDataClassToString()
|
||||
}
|
||||
|
||||
public inline fun <S : KtSymbol> symbolPointer(crossinline getSymbol: (KtAnalysisSession) -> S?): KtSymbolPointer<S> =
|
||||
|
||||
@@ -6,6 +6,7 @@ plugins {
|
||||
dependencies {
|
||||
implementation(project(":compiler:psi"))
|
||||
implementation(kotlinxCollectionsImmutable())
|
||||
implementation(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
|
||||
implementation(intellijCore())
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.utils.relfection
|
||||
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import kotlin.reflect.full.declaredMemberProperties
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.prettyPrint
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
public fun Any.renderAsDataClassToString(): String = prettyPrint {
|
||||
append(this@renderAsDataClassToString::class.qualifiedName)
|
||||
append("(")
|
||||
printCollection(this@renderAsDataClassToString::class.declaredMemberProperties) { property ->
|
||||
append(property.name)
|
||||
append(": ")
|
||||
val getter = property.getter
|
||||
try {
|
||||
getter.isAccessible = true
|
||||
append(getter.call(this@renderAsDataClassToString).toString())
|
||||
} catch (e: InvocationTargetException) {
|
||||
append("ERROR_RENDERING_FIELD")
|
||||
} catch (_: Exception) {
|
||||
println("")
|
||||
}
|
||||
}
|
||||
append(")")
|
||||
}
|
||||
+5
-1
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.psi.KtTypeParameterListOwner
|
||||
import java.util.*
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.buildErrorWithAttachment
|
||||
|
||||
internal fun <L : Any> L.invalidAccess(): Nothing =
|
||||
error("Cls delegate shouldn't be accessed for symbol light classes! Qualified name: ${javaClass.name}")
|
||||
@@ -245,7 +246,10 @@ internal fun BitSet.copy(): BitSet = clone() as BitSet
|
||||
|
||||
context(KtAnalysisSession)
|
||||
internal fun <T : KtSymbol> KtSymbolPointer<T>.restoreSymbolOrThrowIfDisposed(): T =
|
||||
restoreSymbol() ?: error("${this::class} pointer already disposed")
|
||||
restoreSymbol()
|
||||
?: buildErrorWithAttachment("${this::class} pointer already disposed") {
|
||||
withEntry("pointer", this@restoreSymbolOrThrowIfDisposed) { it.toString() }
|
||||
}
|
||||
|
||||
internal fun hasTypeParameters(
|
||||
ktModule: KtModule,
|
||||
|
||||
Reference in New Issue
Block a user