From 3590d534e537ec8828b6dc1113a237c7559bc39d Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 2 Nov 2018 16:32:58 +0300 Subject: [PATCH] KT-24788: Fix exceptions in offline inspections When there is severe memory load SLRUCache inside getResolutionFacade may cause double computation of ResolutionFacade, thus will cause moduleDescriptor to be recreated, and it will be different from one that is stored in declarationDescriptor Newer resolutionFacade will actually not built for old moduleDescriptor and will cause exception #KT-24788 fixed --- .../kotlin/idea/kdoc/KDocReference.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt index 3c2ddb42e66..8182f28b3a5 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt @@ -26,18 +26,23 @@ import org.jetbrains.kotlin.kdoc.psi.impl.KDocName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode -class KDocReference(element: KDocName): KtMultiReference(element) { +class KDocReference(element: KDocName) : KtMultiReference(element) { override fun getTargetDescriptors(context: BindingContext): Collection { val declaration = element.getContainingDoc().getOwner() ?: return arrayListOf() - val declarationDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, declaration] ?: return arrayListOf() + val resolutionFacade = element.getResolutionFacade() + val correctContext = resolutionFacade.analyze(declaration, BodyResolveMode.PARTIAL) + val declarationDescriptor = correctContext[BindingContext.DECLARATION_TO_DESCRIPTOR, declaration] ?: return arrayListOf() val kdocLink = element.getStrictParentOfType()!! - return resolveKDocLink(context, - element.getResolutionFacade(), - declarationDescriptor, - kdocLink.getTagIfSubject(), - element.getQualifiedName()) + return resolveKDocLink( + correctContext, + resolutionFacade, + declarationDescriptor, + kdocLink.getTagIfSubject(), + element.getQualifiedName() + ) } override fun getRangeInElement(): TextRange = element.getNameTextRange()