diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/FindDocComment.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/FindDocComment.kt index a67a874c860..af625260d81 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/FindDocComment.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/FindDocComment.kt @@ -16,14 +16,19 @@ package org.jetbrains.kotlin.psi.findDocComment -import com.intellij.psi.PsiComment -import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.kdoc.psi.api.KDoc import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.psi.KtDeclarationModifierList import org.jetbrains.kotlin.psi.psiUtil.allChildren fun findDocComment(declaration: KtDeclaration): KDoc? { return declaration.allChildren - .dropWhile { it !is KDoc && (it is PsiWhiteSpace || it is PsiComment) } - .first() as? KDoc + .flatMap { + if (it is KtDeclarationModifierList) { + return@flatMap it.children.asSequence() + } + sequenceOf(it) + } + .dropWhile { it !is KDoc } + .firstOrNull() as? KDoc } diff --git a/idea/testData/kdoc/finder/Annotated.kt b/idea/testData/kdoc/finder/Annotated.kt new file mode 100644 index 00000000000..ebad6933a3b --- /dev/null +++ b/idea/testData/kdoc/finder/Annotated.kt @@ -0,0 +1,5 @@ +class Foo() { + @Supress("unused") + /** Doc for method xyzzy */ + fun xyzzy(): Int = 0 +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocFinderTest.kt b/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocFinderTest.kt index 7f84654f6f4..1f1deb612eb 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocFinderTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/kdoc/KDocFinderTest.kt @@ -39,6 +39,15 @@ class KDocFinderTest() : LightPlatformCodeInsightFixtureTestCase() { Assert.assertEquals("Doc for constructor of class C.", doc!!.getContent()) } + fun testAnnotated() { + myFixture.configureByFile(getTestName(false) + ".kt") + val declaration = (myFixture.file as KtFile).declarations[0] + val descriptor = declaration.resolveToDescriptor() as ClassDescriptor + val overriddenFunctionDescriptor = descriptor.defaultType.memberScope.getContributedFunctions(Name.identifier("xyzzy"), NoLookupLocation.FROM_TEST).single() + val doc = overriddenFunctionDescriptor.findKDoc() + Assert.assertEquals("Doc for method xyzzy", doc!!.getContent()) + } + fun testOverridden() { myFixture.configureByFile(getTestName(false) + ".kt") val declaration = (myFixture.file as KtFile).declarations.single { it.name == "Bar" }