KT-18501: Fix to find KDoc even if KDoc is in ModifierList
This commit is contained in:
committed by
Simon Ogorodnik
parent
4b92349031
commit
fe9d3f16d3
@@ -16,14 +16,19 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.psi.findDocComment
|
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.kdoc.psi.api.KDoc
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.KtDeclarationModifierList
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||||
|
|
||||||
fun findDocComment(declaration: KtDeclaration): KDoc? {
|
fun findDocComment(declaration: KtDeclaration): KDoc? {
|
||||||
return declaration.allChildren
|
return declaration.allChildren
|
||||||
.dropWhile { it !is KDoc && (it is PsiWhiteSpace || it is PsiComment) }
|
.flatMap {
|
||||||
.first() as? KDoc
|
if (it is KtDeclarationModifierList) {
|
||||||
|
return@flatMap it.children.asSequence()
|
||||||
|
}
|
||||||
|
sequenceOf(it)
|
||||||
|
}
|
||||||
|
.dropWhile { it !is KDoc }
|
||||||
|
.firstOrNull() as? KDoc
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class Foo() {
|
||||||
|
@Supress("unused")
|
||||||
|
/** Doc for method xyzzy */
|
||||||
|
fun xyzzy(): Int = 0
|
||||||
|
}
|
||||||
@@ -39,6 +39,15 @@ class KDocFinderTest() : LightPlatformCodeInsightFixtureTestCase() {
|
|||||||
Assert.assertEquals("Doc for constructor of class C.", doc!!.getContent())
|
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() {
|
fun testOverridden() {
|
||||||
myFixture.configureByFile(getTestName(false) + ".kt")
|
myFixture.configureByFile(getTestName(false) + ".kt")
|
||||||
val declaration = (myFixture.file as KtFile).declarations.single { it.name == "Bar" }
|
val declaration = (myFixture.file as KtFile).declarations.single { it.name == "Bar" }
|
||||||
|
|||||||
Reference in New Issue
Block a user