diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt index 040b8e26d2e..76a3abd39e8 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt @@ -17,6 +17,7 @@ package org.jetbrains.uast.kotlin import com.intellij.openapi.components.ServiceManager +import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.util.Key import com.intellij.psi.PsiElement import com.intellij.psi.PsiPrimitiveType @@ -49,14 +50,19 @@ import java.text.StringCharacterIterator internal val KOTLIN_CACHED_UELEMENT_KEY = Key.create>("cached-kotlin-uelement") @Suppress("NOTHING_TO_INLINE") -internal inline fun String?.orAnonymous(kind: String = ""): String { - return this ?: "" -} +internal inline fun String?.orAnonymous(kind: String = ""): String = this ?: "" -internal fun DeclarationDescriptor.toSource() = try { - DescriptorToSourceUtils.descriptorToDeclaration(this) -} catch (e: Exception) { - null +internal fun DeclarationDescriptor.toSource(): PsiElement? { + return try { + DescriptorToSourceUtils.getEffectiveReferencedDescriptors(this) + .asSequence() + .mapNotNull { DescriptorToSourceUtils.getSourceFromDescriptor(it) } + .firstOrNull() + } + catch (e: Exception) { + Logger.getInstance("DeclarationDescriptor.toSource").error(e) + null + } } internal fun lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, initializer)