diff options
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 18 | ||||
-rw-r--r-- | test/src/TestAPI.kt | 2 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 83e5898b..0518bb03 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions public data class DocumentationOptions(val includeNonPublic: Boolean = false, val reportUndocumented: Boolean = true, + val skipEmptyPackages: Boolean = true, val sourceLinks: List<SourceLinkDefinition>) private fun isSamePackage(descriptor1: DeclarationDescriptor, descriptor2: DeclarationDescriptor): Boolean { @@ -277,9 +278,7 @@ class DocumentationBuilder(val session: ResolveSession, if (descriptor is CallableMemberDescriptor && descriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) return null - if (options.includeNonPublic - || descriptor !is MemberDescriptor - || descriptor.getVisibility() in visibleToDocumentation) { + if (descriptor.isDocumented()) { val node = descriptor.build() append(node, kind) return node @@ -287,6 +286,18 @@ class DocumentationBuilder(val session: ResolveSession, return null } + private fun DeclarationDescriptor.isDocumented(): Boolean { + return (options.includeNonPublic + || this !is MemberDescriptor + || this.getVisibility() in visibleToDocumentation) && !isDocumentationSuppressed() + } + + fun DeclarationDescriptor.isDocumentationSuppressed(): Boolean { + val doc = KDocFinder.findKDoc(this) + return doc is KDocSection && doc.findTagByName("suppress") != null + } + + fun DocumentationNode.appendChildren(descriptors: Iterable<DeclarationDescriptor>, kind: DocumentationReference.Kind) { descriptors.forEach { descriptor -> appendChild(descriptor, kind) } } @@ -320,6 +331,7 @@ class DocumentationBuilder(val session: ResolveSession, descriptors.put(name.asString(), parts.flatMap { it.getMemberScope().getAllDescriptors() }) } for ((packageName, declarations) in descriptors) { + if (options.skipEmptyPackages && declarations.none { it.isDocumented()}) continue logger.info(" package $packageName: ${declarations.count()} declarations") val packageNode = findOrCreatePackageNode(packageName) val externalClassNodes = hashMapOf<FqName, DocumentationNode>() diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt index 6fc83279..ebee1290 100644 --- a/test/src/TestAPI.kt +++ b/test/src/TestAPI.kt @@ -32,7 +32,7 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> addSources(files.toList()) addClasspath(files.map { File(it)}.filter { it.isDirectory()} ) } - val options = DocumentationOptions(includeNonPublic = true, sourceLinks = listOf<SourceLinkDefinition>()) + val options = DocumentationOptions(includeNonPublic = true, skipEmptyPackages = false, sourceLinks = listOf<SourceLinkDefinition>()) val documentation = buildDocumentationModule(environment, "test", options, logger = DokkaConsoleLogger) verifier(documentation) Disposer.dispose(environment) |