aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-03-05 16:16:53 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-03-05 16:16:53 +0100
commite97dba639279678381168c252dd72a06afa23c31 (patch)
tree1d19244306a1b31e791857253543ff07c0bab7f2 /src
parentf3973480c0b03c9f28f05b5a4cf61bf3de3597bd (diff)
downloaddokka-e97dba639279678381168c252dd72a06afa23c31.tar.gz
dokka-e97dba639279678381168c252dd72a06afa23c31.tar.bz2
dokka-e97dba639279678381168c252dd72a06afa23c31.zip
special case to ensure that we find base class documentation for stdlib classes that override equals/hashCode/toString
Diffstat (limited to 'src')
-rw-r--r--src/Kotlin/DocumentationBuilder.kt30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index 60f03f14..5ceb7f3d 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -47,7 +47,7 @@ class DocumentationBuilder(val session: ResolveSession,
"kotlin.Float", "kotlin.Double", "kotlin.String", "kotlin.Array", "kotlin.Any")
fun parseDocumentation(descriptor: DeclarationDescriptor): Content {
- val kdoc = KDocFinder.findKDoc(descriptor)
+ val kdoc = KDocFinder.findKDoc(descriptor) ?: findStdlibKDoc(descriptor)
if (kdoc == null) {
if (options.reportUndocumented && !descriptor.isDeprecated() &&
descriptor !is ValueParameterDescriptor && descriptor !is TypeParameterDescriptor &&
@@ -84,6 +84,34 @@ class DocumentationBuilder(val session: ResolveSession,
return content
}
+ /**
+ * Special case for generating stdlib documentation (the Any class to which the override chain will resolve
+ * is not the same one as the Any class included in the source scope).
+ */
+ fun findStdlibKDoc(descriptor: DeclarationDescriptor): KDocTag? {
+ if (descriptor !is CallableMemberDescriptor) {
+ return null
+ }
+ val name = descriptor.getName().asString()
+ if (name == "equals" || name == "hashCode" || name == "toString") {
+ var deepestDescriptor = descriptor: CallableMemberDescriptor
+ while (!deepestDescriptor.getOverriddenDescriptors().isEmpty()) {
+ deepestDescriptor = deepestDescriptor.getOverriddenDescriptors().first()
+ }
+ if (DescriptorUtils.getFqName(deepestDescriptor.getContainingDeclaration()).asString() == "kotlin.Any") {
+ val anyClassDescriptors = session.getTopLevelClassDescriptors(FqName.fromSegments(listOf("kotlin", "Any")))
+ anyClassDescriptors.forEach {
+ val anyMethod = it.getMemberScope(listOf()).getFunctions(descriptor.getName()).single()
+ val kdoc = KDocFinder.findKDoc(anyMethod)
+ if (kdoc != null) {
+ return kdoc
+ }
+ }
+ }
+ }
+ return null
+ }
+
fun DeclarationDescriptor.isDeprecated(): Boolean = getAnnotations().any {
DescriptorUtils.getFqName(it.getType().getConstructor().getDeclarationDescriptor()).asString() == "kotlin.deprecated"
} || (this is ConstructorDescriptor && getContainingDeclaration().isDeprecated())