From 1bd02472a25d85bf6572c656205ac480ff2d22d5 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Mon, 16 Jul 2018 18:53:31 +0300 Subject: [PATCH] KT-22815: Fix documentation for primary constructor params/props --- .../jetbrains/kotlin/idea/kdoc/findKDoc.kt | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/kdoc/findKDoc.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/kdoc/findKDoc.kt index cdc992f42f2..49e77273d2a 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/kdoc/findKDoc.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/kdoc/findKDoc.kt @@ -66,16 +66,24 @@ fun KtElement.findKDoc(descriptorToPsi: (DeclarationDescriptorWithSource) -> Psi if (this is KtParameter || this is KtTypeParameter) { val containingDeclaration = - PsiTreeUtil.getParentOfType(this, KtDeclarationWithBody::class.java, KtClassOrObject::class.java, KtScript::class.java) - val classKDoc = containingDeclaration?.getChildOfType() - val subjectName = name - if (classKDoc != null && subjectName != null) { - val propertySection = - classKDoc.findSectionByTag(KDocKnownTag.PROPERTY, subjectName)?.takeIf { this is KtParameter && this.isPropertyParameter() } - ?: classKDoc.findDescendantOfType { it.knownTag == KDocKnownTag.PARAM && it.getSubjectName() == subjectName } - if (propertySection != null) { - return propertySection + PsiTreeUtil.findFirstParent(this, true) { + it is KtDeclarationWithBody && it !is KtPrimaryConstructor + || it is KtClassOrObject } + val containerKDoc = containingDeclaration?.getChildOfType() + val subjectName = name + if (containerKDoc != null && subjectName != null) { + + val propertyDoc = + containerKDoc.findSectionByTag(KDocKnownTag.PROPERTY, subjectName) + ?.takeIf { this is KtParameter && this.isPropertyParameter() } + + if (propertyDoc != null) return propertyDoc + + val paramDoc = + containerKDoc.findDescendantOfType { it.knownTag == KDocKnownTag.PARAM && it.getSubjectName() == subjectName } + + if (paramDoc != null) return paramDoc } }