From e97dba639279678381168c252dd72a06afa23c31 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 5 Mar 2015 16:16:53 +0100 Subject: special case to ensure that we find base class documentation for stdlib classes that override equals/hashCode/toString --- src/Kotlin/DocumentationBuilder.kt | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/Kotlin/DocumentationBuilder.kt') 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()) -- cgit