From 0d3c91559f85bd8e373271acc9de2a93c5782ae3 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 8 Jan 2016 18:30:21 +0100 Subject: don't generate "Extensions for external classes" pages for classes which are part of the documented module but reside in another package --- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 28 ++++++++++++++-------- .../Kotlin/KotlinAsJavaDocumentationBuilder.kt | 3 ++- 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'core/src') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 4c7c75b4..f3b206c6 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -43,17 +43,22 @@ data class DocumentationOptions(val outputDir: String, val skipDeprecated: Boolean = false, val sourceLinks: List) -private fun isSamePackage(descriptor1: DeclarationDescriptor, descriptor2: DeclarationDescriptor): Boolean { - val package1 = DescriptorUtils.getParentOfType(descriptor1, PackageFragmentDescriptor::class.java) - val package2 = DescriptorUtils.getParentOfType(descriptor2, PackageFragmentDescriptor::class.java) - return package1 != null && package2 != null && package1.fqName == package2.fqName +private fun isExtensionForExternalClass(extensionFunctionDescriptor: DeclarationDescriptor, + extensionReceiverDescriptor: DeclarationDescriptor, + allFqNames: Collection): Boolean { + val extensionFunctionPackage = DescriptorUtils.getParentOfType(extensionFunctionDescriptor, PackageFragmentDescriptor::class.java) + val extensionReceiverPackage = DescriptorUtils.getParentOfType(extensionReceiverDescriptor, PackageFragmentDescriptor::class.java) + return extensionFunctionPackage != null && extensionReceiverPackage != null && + extensionFunctionPackage.fqName != extensionReceiverPackage.fqName && + extensionReceiverPackage.fqName !in allFqNames } interface PackageDocumentationBuilder { fun buildPackageDocumentation(documentationBuilder: DocumentationBuilder, packageName: FqName, packageNode: DocumentationNode, - declarations: List) + declarations: List, + allFqNames: Collection) } class DocumentationBuilder @@ -271,7 +276,8 @@ class DocumentationBuilder if (options.skipEmptyPackages && declarations.none { it.isDocumented() }) continue logger.info(" package $packageName: ${declarations.count()} declarations") val packageNode = findOrCreatePackageNode(packageName.asString(), packageContent) - packageDocumentationBuilder.buildPackageDocumentation(this@DocumentationBuilder, packageName, packageNode, declarations) + packageDocumentationBuilder.buildPackageDocumentation(this@DocumentationBuilder, packageName, packageNode, + declarations, allFqNames) } propagateExtensionFunctionsToSubclasses(fragments) @@ -594,12 +600,13 @@ class KotlinPackageDocumentationBuilder : PackageDocumentationBuilder { override fun buildPackageDocumentation(documentationBuilder: DocumentationBuilder, packageName: FqName, packageNode: DocumentationNode, - declarations: List) { + declarations: List, + allFqNames: Collection) { val externalClassNodes = hashMapOf() declarations.forEach { descriptor -> with(documentationBuilder) { if (descriptor.isDocumented()) { - val parent = packageNode.getParentForPackageMember(descriptor, externalClassNodes) + val parent = packageNode.getParentForPackageMember(descriptor, externalClassNodes, allFqNames) parent.appendChild(descriptor, RefKind.Member) } } @@ -652,10 +659,11 @@ fun DeclarationDescriptor.isDeprecated(): Boolean = annotations.any { } || (this is ConstructorDescriptor && containingDeclaration.isDeprecated()) fun DocumentationNode.getParentForPackageMember(descriptor: DeclarationDescriptor, - externalClassNodes: MutableMap): DocumentationNode { + externalClassNodes: MutableMap, + allFqNames: Collection): DocumentationNode { if (descriptor is CallableMemberDescriptor) { val extensionClassDescriptor = descriptor.getExtensionClassDescriptor() - if (extensionClassDescriptor != null && !isSamePackage(descriptor, extensionClassDescriptor) && + if (extensionClassDescriptor != null && isExtensionForExternalClass(descriptor, extensionClassDescriptor, allFqNames) && !ErrorUtils.isError(extensionClassDescriptor)) { val fqName = DescriptorUtils.getFqNameSafe(extensionClassDescriptor) return externalClassNodes.getOrPut(fqName, { diff --git a/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt index 7a1d591c..349a44e7 100644 --- a/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/KotlinAsJavaDocumentationBuilder.kt @@ -19,7 +19,8 @@ class KotlinAsJavaDocumentationBuilder override fun buildPackageDocumentation(documentationBuilder: DocumentationBuilder, packageName: FqName, packageNode: DocumentationNode, - declarations: List) { + declarations: List, + allFqNames: Collection) { val project = documentationBuilder.resolutionFacade.project val psiPackage = JavaPsiFacade.getInstance(project).findPackage(packageName.asString()) if (psiPackage == null) { -- cgit