From ff8fdb0bbc4069773424400acfdce36a4e3d6d6a Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 23 Feb 2017 19:08:31 +0100 Subject: Resolve link and generate alltypes only once, not after every platform --- core/src/main/kotlin/Generation/DokkaGenerator.kt | 3 +- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 38 ++++++++++++---------- core/src/test/kotlin/TestAPI.kt | 20 +++++++----- core/src/test/kotlin/format/MarkdownFormatTest.kt | 5 +-- 4 files changed, 36 insertions(+), 30 deletions(-) (limited to 'core') diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index 8fda1eb1..0b14418d 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -39,6 +39,7 @@ class DokkaGenerator(val logger: DokkaLogger, for ((platforms, roots) in sourcesGroupedByPlatform) { appendSourceModule(platforms, roots.map { it.path }) } + documentationModule.prepareForGeneration(options) val timeBuild = measureTimeMillis { logger.info("Generating pages... ") @@ -150,8 +151,6 @@ fun buildDocumentationModule(injector: Injector, with(injector.getInstance(JavaDocumentationBuilder::class.java)) { javaFiles.map { appendFile(it, documentationModule, packageDocs.packageContent) } } - - injector.getInstance(NodeReferenceGraph::class.java).resolveReferences() } diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index ce957d93..70c3565f 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -39,7 +39,7 @@ data class DocumentationOptions(val outputDir: String, val skipDeprecated: Boolean = false, val jdkVersion: Int = 6, val generateIndexPages: Boolean = true, - val sourceLinks: List, + val sourceLinks: List = emptyList(), val impliedPlatforms: List = emptyList()) private fun isExtensionForExternalClass(extensionFunctionDescriptor: DeclarationDescriptor, @@ -344,9 +344,6 @@ class DocumentationBuilder } propagateExtensionFunctionsToSubclasses(fragments) - if (options.generateIndexPages) { - generateAllTypesNode() - } } private fun propagateExtensionFunctionsToSubclasses(fragments: Collection) { @@ -419,19 +416,6 @@ class DocumentationBuilder return false } - private fun DocumentationNode.generateAllTypesNode() { - val allTypes = members(NodeKind.Package) - .flatMap { it.members.filter { it.kind in NodeKind.classLike || it.kind == NodeKind.ExternalClass } } - .sortedBy { if (it.kind == NodeKind.ExternalClass) it.name.substringAfterLast('.') else it.name } - - val allTypesNode = DocumentationNode("alltypes", Content.Empty, NodeKind.AllTypes) - for (typeNode in allTypes) { - allTypesNode.addReferenceTo(typeNode, RefKind.Member) - } - - append(allTypesNode, RefKind.Member) - } - fun DeclarationDescriptor.build(): DocumentationNode = when (this) { is ClassDescriptor -> build() is ConstructorDescriptor -> build() @@ -907,3 +891,23 @@ fun DeclarationDescriptor.sourceLocation(): String? { } return null } + +fun DocumentationModule.prepareForGeneration(options: DocumentationOptions) { + if (options.generateIndexPages) { + generateAllTypesNode() + } + nodeRefGraph.resolveReferences() +} + +fun DocumentationNode.generateAllTypesNode() { + val allTypes = members(NodeKind.Package) + .flatMap { it.members.filter { it.kind in NodeKind.classLike || it.kind == NodeKind.ExternalClass } } + .sortedBy { if (it.kind == NodeKind.ExternalClass) it.name.substringAfterLast('.') else it.name } + + val allTypesNode = DocumentationNode("alltypes", Content.Empty, NodeKind.AllTypes) + for (typeNode in allTypes) { + allTypesNode.addReferenceTo(typeNode, RefKind.Member) + } + + append(allTypesNode, RefKind.Member) +} diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 86111e76..be484279 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -23,11 +23,19 @@ fun verifyModel(vararg roots: ContentRoot, includeNonPublic: Boolean = true, verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") + + val options = DocumentationOptions("", format, + includeNonPublic = includeNonPublic, + skipEmptyPackages = false, + sourceLinks = listOf(), + generateIndexPages = false) + appendDocumentation(documentation, *roots, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, - format = format, - includeNonPublic = includeNonPublic) + options = options) + documentation.prepareForGeneration(options) + verifier(documentation) } @@ -35,8 +43,7 @@ fun appendDocumentation(documentation: DocumentationModule, vararg roots: ContentRoot, withJdk: Boolean = false, withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, + options: DocumentationOptions, defaultPlatforms: List = emptyList()) { val messageCollector = object : MessageCollector { override fun clear() { @@ -76,11 +83,6 @@ fun appendDocumentation(documentation: DocumentationModule, } addRoots(roots.toList()) } - val options = DocumentationOptions("", format, - includeNonPublic = includeNonPublic, - skipEmptyPackages = false, - sourceLinks = listOf(), - generateIndexPages = false) val injector = Guice.createInjector( DokkaAnalysisModule(environment, options, defaultPlatforms, documentation.nodeRefGraph, DokkaConsoleLogger)) buildDocumentationModule(injector, documentation) diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index c09f2624..dc24c8d8 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -267,8 +267,9 @@ class MarkdownFormatTest { private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM")) - appendDocumentation(module, contentRootFromPath("testdata/format/$path/js.kt"), defaultPlatforms = listOf("JS")) + val options = DocumentationOptions("", "html", generateIndexPages = false) + appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) + appendDocumentation(module, contentRootFromPath("testdata/format/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) return module } -- cgit