change KDoc parsing so that space after parameter/section name is not included in tag content; support @property tag in KDocFinder
This commit is contained in:
@@ -16,14 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.kdoc
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
|
||||
object KDocFinder {
|
||||
fun findKDoc(declaration: DeclarationDescriptor): KDocTag? {
|
||||
@@ -44,6 +43,20 @@ object KDocFinder {
|
||||
}
|
||||
}
|
||||
|
||||
if (declaration is PropertyDescriptor) {
|
||||
val containingClassDescriptor = declaration.getContainingDeclaration() as? ClassDescriptor
|
||||
if (containingClassDescriptor != null) {
|
||||
val classKDoc = findKDoc(containingClassDescriptor)?.getParentOfType<KDoc>(false)
|
||||
if (classKDoc != null) {
|
||||
val propertySection = classKDoc.findSectionByTag(KDocKnownTag.PROPERTY,
|
||||
declaration.getName().asString())
|
||||
if (propertySection != null) {
|
||||
return propertySection
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (declaration is CallableDescriptor) {
|
||||
for (baseDescriptor in declaration.getOverriddenDescriptors()) {
|
||||
val baseKDoc = findKDoc(baseDescriptor.getOriginal())
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* @property xyzzy Doc for property xyzzy
|
||||
*/
|
||||
class Foo(val xyzzy: String)
|
||||
@@ -55,4 +55,13 @@ public class KDocFinderTest() : LightPlatformCodeInsightFixtureTestCase() {
|
||||
val doc = KDocFinder.findKDoc(overriddenFunctionDescriptor)
|
||||
Assert.assertEquals("Doc for method xyzzy", doc!!.getContent())
|
||||
}
|
||||
|
||||
public fun testProperty() {
|
||||
myFixture.configureByFile(getTestName(false) + ".kt")
|
||||
val declaration = (myFixture.getFile() as JetFile).getDeclarations().single { it.getName() == "Foo" }
|
||||
val descriptor = declaration.resolveToDescriptor() as ClassDescriptor
|
||||
val propertyDescriptor = descriptor.getDefaultType().getMemberScope().getProperties(Name.identifier("xyzzy")).single()
|
||||
val doc = KDocFinder.findKDoc(propertyDescriptor)
|
||||
Assert.assertEquals("Doc for property xyzzy", doc!!.getContent())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user