aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2017-02-23 19:08:31 +0100
committerDmitry Jemerov <yole@jetbrains.com>2017-02-23 19:08:31 +0100
commitff8fdb0bbc4069773424400acfdce36a4e3d6d6a (patch)
treeced42fb0bc0690191fc8836a47e3a4e19765e563 /core
parent66757b43bb48d52e4fb92d38e9a893ab40d1d63e (diff)
downloaddokka-ff8fdb0bbc4069773424400acfdce36a4e3d6d6a.tar.gz
dokka-ff8fdb0bbc4069773424400acfdce36a4e3d6d6a.tar.bz2
dokka-ff8fdb0bbc4069773424400acfdce36a4e3d6d6a.zip
Resolve link and generate alltypes only once, not after every platform
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/Generation/DokkaGenerator.kt3
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt38
-rw-r--r--core/src/test/kotlin/TestAPI.kt20
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt5
4 files changed, 36 insertions, 30 deletions
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<SourceLinkDefinition>,
+ val sourceLinks: List<SourceLinkDefinition> = emptyList(),
val impliedPlatforms: List<String> = emptyList())
private fun isExtensionForExternalClass(extensionFunctionDescriptor: DeclarationDescriptor,
@@ -344,9 +344,6 @@ class DocumentationBuilder
}
propagateExtensionFunctionsToSubclasses(fragments)
- if (options.generateIndexPages) {
- generateAllTypesNode()
- }
}
private fun propagateExtensionFunctionsToSubclasses(fragments: Collection<PackageFragmentDescriptor>) {
@@ -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<SourceLinkDefinition>(),
+ 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<String> = 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<SourceLinkDefinition>(),
- 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
}