diff options
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 12 | ||||
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 11 | ||||
-rw-r--r-- | src/main.kt | 2 |
3 files changed, 21 insertions, 4 deletions
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 11c40743..44a4f39e 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -131,17 +131,23 @@ public fun buildInlineContentTo(tree: MarkdownNode, target: ContentBlock, linkRe } fun DocumentationBuilder.functionBody(descriptor: DeclarationDescriptor, functionName: String?): ContentNode { - if (functionName == null) + if (functionName == null) { + logger.warn("Missing function name in @sample in ${descriptor.signature()}") return ContentBlockCode().let() { it.append(ContentText("Missing function name in @sample")); it } + } val scope = getResolutionScope(session, descriptor) val rootPackage = session.getModuleDescriptor().getPackage(FqName.ROOT)!! val rootScope = rootPackage.getMemberScope() val symbol = resolveInScope(functionName, scope) ?: resolveInScope(functionName, rootScope) - if (symbol == null) + if (symbol == null) { + logger.warn("Unresolved function $functionName in @sample in ${descriptor.signature()}") return ContentBlockCode().let() { it.append(ContentText("Unresolved: $functionName")); it } + } val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(symbol) - if (psiElement == null) + if (psiElement == null) { + logger.warn("Can't find source for function $functionName in @sample in ${descriptor.signature()}") return ContentBlockCode().let() { it.append(ContentText("Source not found: $functionName")); it } + } val text = when (psiElement) { is JetDeclarationWithBody -> ContentBlockCode().let() { diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 2c4c5119..83e5898b 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.types.TypeProjection import org.jetbrains.kotlin.types.expressions.OperatorConventions public data class DocumentationOptions(val includeNonPublic: Boolean = false, + val reportUndocumented: Boolean = true, val sourceLinks: List<SourceLinkDefinition>) private fun isSamePackage(descriptor1: DeclarationDescriptor, descriptor2: DeclarationDescriptor): Boolean { @@ -46,6 +47,11 @@ class DocumentationBuilder(val session: ResolveSession, fun parseDocumentation(descriptor: DeclarationDescriptor): Content { val kdoc = KDocFinder.findKDoc(descriptor) if (kdoc == null) { + if (options.reportUndocumented && !descriptor.isDeprecated() && + descriptor !is ValueParameterDescriptor && descriptor !is TypeParameterDescriptor && + descriptor !is PropertyAccessorDescriptor) { + logger.warn("No documentation for ${descriptor.signature()}") + } return Content.Empty } var kdocText = kdoc.getContent() @@ -76,6 +82,10 @@ class DocumentationBuilder(val session: ResolveSession, return content } + fun DeclarationDescriptor.isDeprecated() = getAnnotations().any { + DescriptorUtils.getFqName(it.getType().getConstructor().getDeclarationDescriptor()).asString() == "kotlin.deprecated" + } + fun DeclarationDescriptor.signature(): String = when(this) { is ClassDescriptor, is PackageFragmentDescriptor -> DescriptorUtils.getFqName(this).asString() is PropertyDescriptor -> getContainingDeclaration().signature() + "#" + getName() + receiverSignature() @@ -122,6 +132,7 @@ class DocumentationBuilder(val session: ResolveSession, if ("/" in href) { return ContentExternalLink(href) } + logger.warn("Unresolved link to $href in doc comment of ${descriptor.signature()}") return ContentExternalLink("#") } diff --git a/src/main.kt b/src/main.kt index d7ff749c..8fa0a97e 100644 --- a/src/main.kt +++ b/src/main.kt @@ -124,7 +124,7 @@ class DokkaGenerator(val logger: DokkaLogger, logger.info("Analysing sources and libraries... ") val startAnalyse = System.currentTimeMillis() - val options = DocumentationOptions(false, sourceLinks) + val options = DocumentationOptions(false, sourceLinks = sourceLinks) val documentation = buildDocumentationModule(environment, moduleName, options, includes, { isSample(it) }, logger) val timeAnalyse = System.currentTimeMillis() - startAnalyse |