From 30b98aaeb7d69d732989d99e92a4266317833dff Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 16 Oct 2019 18:10:04 +0200 Subject: [PATCH] Keep attachments of cause exception in KotlinExceptionWithAttachments and provide elements in attachments in case of errors during kotlin idea resolution Relates to EA-210942, EA-209622 etc --- .../kotlin/utils/KotlinExceptionWithAttachments.kt | 6 +++++- .../idea/caches/resolve/ResolutionFacadeWithDebugInfo.kt | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt index ba64e8a34ad..d9697ccc25d 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt @@ -13,7 +13,11 @@ open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttac constructor(message: String) : super(message) - constructor(message: String?, cause: Throwable?) : super(message, cause) + constructor(message: String?, cause: Throwable?) : super(message, cause) { + if (cause is KotlinExceptionWithAttachments) { + attachments.addAll(cause.attachments) + } + } override fun getAttachments(): Array = attachments.toTypedArray() diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ResolutionFacadeWithDebugInfo.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ResolutionFacadeWithDebugInfo.kt index 92e3845f3b8..24f34240e33 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ResolutionFacadeWithDebugInfo.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ResolutionFacadeWithDebugInfo.kt @@ -118,6 +118,9 @@ private class KotlinIdeaResolutionException( appendln("---------------------------------------------") append(creationPlace.description()) }) + for (element in resolvingWhat.elements.withIndex()) { + withAttachment("element${element.index}.kt", element.value.text) + } } } @@ -142,7 +145,7 @@ private class CreationPlace( } private class ResolvingWhat( - private val elements: Collection = emptyList(), + val elements: Collection = emptyList(), private val bodyResolveMode: BodyResolveMode? = null, private val serviceClass: Class<*>? = null, private val moduleDescriptor: ModuleDescriptor? = null