Migrate some FIR/Analysis API KotlinExceptionWithAttachment usages to buildErrorWithAttachment API
This commit is contained in:
committed by
Space Team
parent
24f60a542d
commit
24db4e62f5
+5
-12
@@ -12,9 +12,9 @@ import com.intellij.psi.impl.source.resolve.ResolveCache
|
||||
import org.jetbrains.kotlin.analysis.api.KtAllowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import org.jetbrains.kotlin.utils.exceptions.shouldIjPlatformExceptionBeRethrown
|
||||
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
|
||||
|
||||
object KtFirReferenceResolver : ResolveCache.PolyVariantResolver<KtReference> {
|
||||
class KotlinResolveResult(element: PsiElement) : PsiElementResolveResult(element)
|
||||
@@ -29,18 +29,11 @@ object KtFirReferenceResolver : ResolveCache.PolyVariantResolver<KtReference> {
|
||||
} catch (e: Exception) {
|
||||
if (shouldIjPlatformExceptionBeRethrown(e)) throw e
|
||||
|
||||
throw KtReferenceResolveException(ref, e)
|
||||
errorWithAttachment("Unable to resolve reference ${ref.element::class.java}", cause = e) {
|
||||
withPsiEntry("reference", ref.element)
|
||||
}
|
||||
}
|
||||
resolveToPsiElements.map { KotlinResolveResult(it) }.toTypedArray()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class KtReferenceResolveException(
|
||||
reference: KtReference,
|
||||
cause: Throwable
|
||||
) : KotlinExceptionWithAttachments("Unable to resolve reference at: ${PsiDiagnosticUtils.atLocation(reference.element)}", cause) {
|
||||
init {
|
||||
withPsiAttachment("element.kt", reference.element)
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -5,14 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.api
|
||||
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirSymbolEntry
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirSymbolEntry
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
import org.jetbrains.kotlin.utils.exceptions.KotlinIllegalArgumentExceptionWithAttachments
|
||||
import org.jetbrains.kotlin.utils.exceptions.buildAttachment
|
||||
import java.util.*
|
||||
import kotlin.reflect.KClass
|
||||
@@ -21,7 +21,7 @@ class InvalidFirElementTypeException(
|
||||
actualFirElement: Any?,
|
||||
ktElement: KtElement?,
|
||||
expectedFirClasses: List<KClass<*>>,
|
||||
) : KotlinExceptionWithAttachments("") {
|
||||
) : KotlinIllegalArgumentExceptionWithAttachments("") {
|
||||
init {
|
||||
buildAttachment {
|
||||
when (actualFirElement) {
|
||||
|
||||
Reference in New Issue
Block a user