diff options
-rw-r--r-- | core/src/main/kotlin/DokkaBootstrapImpl.kt | 11 | ||||
-rw-r--r-- | core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt | 10 | ||||
-rw-r--r-- | core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt | 3 | ||||
-rw-r--r-- | core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 42 | ||||
-rw-r--r-- | runners/ant/src/main/kotlin/ant/dokka.kt | 25 | ||||
-rw-r--r-- | runners/ant/src/main/resources/dokka-antlib.xml (renamed from core/src/main/resources/dokka-antlib.xml) | 0 | ||||
-rw-r--r-- | runners/cli/src/main/kotlin/cli/main.kt | 6 |
7 files changed, 73 insertions, 24 deletions
diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index 8038089f..a52fc9b6 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -10,6 +10,17 @@ fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition { urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#" + it }) } +fun parsePerPackageOptions(arg: String): List<PackageOptions> = arg.split(";").map { it.split(",") }.map { + val prefix = it.first() + if (prefix == "") + throw IllegalArgumentException("Please do not register packageOptions with all match pattern, use global settings instead") + val args = it.subList(1, it.size) + val deprecated = args.find { it.endsWith("deprecated") }?.startsWith("+") ?: true + val reportUndocumented = args.find { it.endsWith("warnUndocumented") }?.startsWith("+") ?: true + val privateApi = args.find { it.endsWith("privateApi") }?.startsWith("+") ?: false + PackageOptions(prefix, includeNonPublic = privateApi, reportUndocumented = reportUndocumented, skipDeprecated = !deprecated) +} + fun parseSourceRoot(sourceRoot: String): SourceRoot { val components = sourceRoot.split("::", limit = 2) return SourceRoot(components.last(), if (components.size == 1) listOf() else components[0].split(',')) diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt index b2f4aeaf..a950e432 100644 --- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt +++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt @@ -133,11 +133,11 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { private fun skipElement(element: Any) = skipElementByVisibility(element) || hasSuppressDocTag(element) - private fun skipElementByVisibility(element: Any): Boolean = - !options.includeNonPublic && element is PsiModifierListOwner && - (element.hasModifierProperty(PsiModifier.PRIVATE) || - element.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) || - element.isInternal()) + private fun skipElementByVisibility(element: Any): Boolean = element is PsiModifierListOwner && + !(options.effectivePackageOptions((element.containingFile as? PsiJavaFile)?.packageName ?: "").includeNonPublic) && + (element.hasModifierProperty(PsiModifier.PRIVATE) || + element.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) || + element.isInternal()) private fun PsiElement.isInternal(): Boolean { val ktElement = (this as? KtLightElement<*, *>)?.kotlinOrigin ?: return false diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt index 6d7ff7ba..dd96bafa 100644 --- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt +++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.annotations.argumentValue import org.jetbrains.kotlin.resolve.constants.StringValue +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered import org.jetbrains.kotlin.resolve.source.PsiSourceElement @@ -40,7 +41,7 @@ class DescriptorDocumentationParser val kdoc = descriptor.findKDoc() ?: findStdlibKDoc(descriptor) if (kdoc == null) { - if (options.reportUndocumented && !descriptor.isDeprecated() && + if (options.effectivePackageOptions(descriptor.fqNameSafe).reportUndocumented && !descriptor.isDeprecated() && descriptor !is ValueParameterDescriptor && descriptor !is TypeParameterDescriptor && descriptor !is PropertyAccessorDescriptor && !descriptor.isSuppressWarning()) { logger.warn("No documentation for ${descriptor.signatureWithSourceLocation()}") diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 299ad477..7c4e4531 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -30,17 +30,33 @@ import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import org.jetbrains.kotlin.types.typeUtil.supertypes import com.google.inject.name.Named as GuiceNamed -data class DocumentationOptions(val outputDir: String, - val outputFormat: String, - val includeNonPublic: Boolean = false, - val includeRootPackage: Boolean = false, - val reportUndocumented: Boolean = true, - val skipEmptyPackages: Boolean = true, - val skipDeprecated: Boolean = false, - val jdkVersion: Int = 6, - val generateIndexPages: Boolean = true, - val sourceLinks: List<SourceLinkDefinition> = emptyList(), - val impliedPlatforms: List<String> = emptyList()) +class DocumentationOptions(val outputDir: String, + val outputFormat: String, + includeNonPublic: Boolean = false, + val includeRootPackage: Boolean = false, + reportUndocumented: Boolean = true, + val skipEmptyPackages: Boolean = true, + skipDeprecated: Boolean = false, + val jdkVersion: Int = 6, + val generateIndexPages: Boolean = true, + val sourceLinks: List<SourceLinkDefinition> = emptyList(), + val impliedPlatforms: List<String> = emptyList(), + // Sorted by pattern length + perPackageOptions: List<PackageOptions> = emptyList()) { + val perPackageOptions = perPackageOptions.sortedByDescending { it.prefix.length } + PackageOptions("", includeNonPublic, reportUndocumented, skipDeprecated) + + + fun effectivePackageOptions(pack: String): PackageOptions = perPackageOptions.first { pack.startsWith(it.prefix) } + fun effectivePackageOptions(pack: FqName): PackageOptions = effectivePackageOptions(pack.asString()) +} + + +data class PackageOptions(val prefix: String, + val includeNonPublic: Boolean = false, + val reportUndocumented: Boolean = true, + val skipDeprecated: Boolean = false) + + private fun isExtensionForExternalClass(extensionFunctionDescriptor: DeclarationDescriptor, extensionReceiverDescriptor: DeclarationDescriptor, @@ -748,11 +764,11 @@ class DocumentationBuilder val visibleToDocumentation = setOf(Visibilities.PROTECTED, Visibilities.PUBLIC) fun DeclarationDescriptor.isDocumented(options: DocumentationOptions): Boolean { - return (options.includeNonPublic + return (options.effectivePackageOptions(fqNameSafe).includeNonPublic || this !is MemberDescriptor || this.visibility in visibleToDocumentation) && !isDocumentationSuppressed() && - (!options.skipDeprecated || !isDeprecated()) + (!options.effectivePackageOptions(fqNameSafe).skipDeprecated || !isDeprecated()) } private fun DeclarationDescriptor.isGenerated() = this is CallableMemberDescriptor && kind != CallableMemberDescriptor.Kind.DECLARATION diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt index e9cb35a2..c05cf1cb 100644 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ b/runners/ant/src/main/kotlin/ant/dokka.kt @@ -16,12 +16,25 @@ class AntLogger(val task: Task): DokkaLogger { class AntSourceLinkDefinition(var path: String? = null, var url: String? = null, var lineSuffix: String? = null) -class AntSourceRoot(var path: String? = null, var platforms: String? = null) +class AntSourceRoot(var path: String? = null, var platforms: String? = null) { + fun toSourceRoot(): SourceRoot? = path?.let { + path -> + SourceRoot(path, platforms?.split(',').orEmpty()) + } +} -fun AntSourceRoot.toSourceRoot(): SourceRoot? = path?.let { - path -> SourceRoot(path, platforms?.split(',').orEmpty()) +class AntPackageOptions(var prefix: String = "", + var includeNonPublic: Boolean = false, + var reportUndocumented: Boolean = true, + var skipDeprecated: Boolean = false) { + fun toPackageOptions(): PackageOptions { + if(prefix == "") + throw IllegalArgumentException("Please do not register packageOptions with all match pattern, use global settings instead") + return PackageOptions(prefix, includeNonPublic, reportUndocumented, skipDeprecated) + } } + class DokkaAntTask: Task() { var moduleName: String? = null var outputDir: String? = null @@ -38,6 +51,7 @@ class DokkaAntTask: Task() { val antSourceLinks: MutableList<AntSourceLinkDefinition> = arrayListOf() val antSourceRoots: MutableList<AntSourceRoot> = arrayListOf() + val antPackageOptions: MutableList<AntPackageOptions> = arrayListOf() fun setClasspath(classpath: Path) { compileClasspath.append(classpath) @@ -75,6 +89,8 @@ class DokkaAntTask: Task() { fun createSourceRoot(): AntSourceRoot = AntSourceRoot().apply { antSourceRoots.add(this) } + fun createPackageOptions(): AntPackageOptions = AntPackageOptions().apply { antPackageOptions.add(this) } + override fun execute() { if (sourcePath.list().isEmpty() && antSourceRoots.isEmpty()) { throw BuildException("At least one source path needs to be specified") @@ -102,7 +118,8 @@ class DokkaAntTask: Task() { skipDeprecated = skipDeprecated, sourceLinks = sourceLinks, jdkVersion = jdkVersion, - impliedPlatforms = impliedPlatforms.split(',')) + impliedPlatforms = impliedPlatforms.split(','), + perPackageOptions = antPackageOptions.map { it.toPackageOptions() }) ) generator.generate() } diff --git a/core/src/main/resources/dokka-antlib.xml b/runners/ant/src/main/resources/dokka-antlib.xml index 9c3373d5..9c3373d5 100644 --- a/core/src/main/resources/dokka-antlib.xml +++ b/runners/ant/src/main/resources/dokka-antlib.xml diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 58bca522..20897c32 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -47,6 +47,9 @@ class DokkaArguments { @set:Argument(value = "impliedPlatforms", description = "List of implied platforms (comma-separated)") var impliedPlatforms: String = "" + + @set:Argument(value = "packageOptions", description = "List of package options in format \"prefix,-deprecated,-privateApi,+warnUndocumented;...\" ") + var packageOptions: String = "" } @@ -76,7 +79,8 @@ object MainKt { arguments.outputFormat, skipDeprecated = arguments.nodeprecated, sourceLinks = sourceLinks, - impliedPlatforms = arguments.impliedPlatforms.split(',') + impliedPlatforms = arguments.impliedPlatforms.split(','), + perPackageOptions = parsePerPackageOptions(arguments.packageOptions) ) val generator = DokkaGenerator( |