diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-03-23 22:59:08 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-03-29 18:37:38 +0300 |
commit | 57e38932b414e7496678b3cc1f171cbf7c4d8fbb (patch) | |
tree | 4658b36056734ceda19be3ce78c62791712aef32 /core/src/main | |
parent | 921192e64c7f1df02692c1ec7f24f4a8bc9b7231 (diff) | |
download | dokka-57e38932b414e7496678b3cc1f171cbf7c4d8fbb.tar.gz dokka-57e38932b414e7496678b3cc1f171cbf7c4d8fbb.tar.bz2 dokka-57e38932b414e7496678b3cc1f171cbf7c4d8fbb.zip |
Per package options
Diffstat (limited to 'core/src/main')
5 files changed, 47 insertions, 22 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/core/src/main/resources/dokka-antlib.xml b/core/src/main/resources/dokka-antlib.xml deleted file mode 100644 index 9c3373d5..00000000 --- a/core/src/main/resources/dokka-antlib.xml +++ /dev/null @@ -1,3 +0,0 @@ -<antlib> - <taskdef name="dokka" classname="org.jetbrains.dokka.ant.DokkaAntTask"/> -</antlib> |