aboutsummaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorZubakov Aleksey <aleks.zubakov@gmail.com>2018-08-17 13:00:06 +0300
committerZubakov Aleksey <aleks.zubakov@gmail.com>2018-08-17 15:47:47 +0300
commit1f45cac76a79abb6eaad99b541234cbf34fbce9c (patch)
treebab06b6ff330b6811ba85f9a48a00dfff82d5646 /core/src/main
parent39b2f9faf768c185f6bd42a9fde18ceaecb34990 (diff)
downloaddokka-1f45cac76a79abb6eaad99b541234cbf34fbce9c.tar.gz
dokka-1f45cac76a79abb6eaad99b541234cbf34fbce9c.tar.bz2
dokka-1f45cac76a79abb6eaad99b541234cbf34fbce9c.zip
Merger platforms bug fix, refactoring
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt2
-rw-r--r--core/src/main/kotlin/Generation/DocumentationMerger.kt58
-rw-r--r--core/src/main/kotlin/Generation/DokkaGenerator.kt19
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt23
4 files changed, 42 insertions, 60 deletions
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index 41c8f29a..b810dfca 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -404,6 +404,8 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
fun String.isKotlinVersion() = this.startsWith("Kotlin")
+ if (platforms.count() == 0) return emptySet()
+
// Calculating common platforms for items
return platforms.reduce { result, platformsOfItem ->
val otherKotlinVersion = result.find { it.isKotlinVersion() }
diff --git a/core/src/main/kotlin/Generation/DocumentationMerger.kt b/core/src/main/kotlin/Generation/DocumentationMerger.kt
index c2089821..c4a40df6 100644
--- a/core/src/main/kotlin/Generation/DocumentationMerger.kt
+++ b/core/src/main/kotlin/Generation/DocumentationMerger.kt
@@ -22,7 +22,6 @@ class DocumentationMerger(
producedNodeRefGraph = NodeReferenceGraph()
documentationModules.map { it.nodeRefGraph }
.flatMap { it.references }
- .distinct()
.forEach { producedNodeRefGraph.addReference(it) }
}
@@ -30,7 +29,6 @@ class DocumentationMerger(
from: DocumentationNode,
packages: List<DocumentationReference>
): List<DocumentationReference> {
-
val packagesByName = packages
.map { it.to }
.groupBy { it.name }
@@ -63,11 +61,13 @@ class DocumentationMerger(
}
oldToNewNodeMap[packageNode] = mergedPackage
}
- mergedPackage.clear()
val references = packages.flatMap { it.allReferences() }
val mergedReferences = mergeReferences(mergedPackage, references)
- for (ref in mergedReferences.distinct()) {
+ for (ref in mergedReferences) {
+ if (ref.kind == RefKind.Owner) {
+ continue
+ }
mergedPackage.addReference(ref)
}
@@ -76,8 +76,6 @@ class DocumentationMerger(
return mergedPackage
}
- private fun DocumentationNode.clear() = dropReferences { true }
-
private fun mergeMembers(
from: DocumentationNode,
refs: List<DocumentationReference>
@@ -106,24 +104,17 @@ class DocumentationMerger(
): DocumentationNode {
val singleNode = refs.singleOrNull()
if (singleNode != null) {
- singleNode.owner?.let { owner ->
- singleNode.dropReferences { it.to == owner && it.kind == RefKind.Owner }
- }
+ singleNode.dropReferences { it.kind == RefKind.Owner }
return singleNode
}
val groupNode = DocumentationNode(refs.first().name, Content.Empty, NodeKind.GroupNode)
groupNode.appendTextNode(signature, NodeKind.Signature, RefKind.Detail)
for (node in refs) {
- if (node != groupNode) {
- node.owner?.let { owner ->
- node.dropReferences { it.to == owner && it.kind == RefKind.Owner }
- from.dropReferences { it.to == node && it.kind == RefKind.Member }
- }
- groupNode.append(node, RefKind.Member)
+ node.dropReferences { it.kind == RefKind.Owner }
+ groupNode.append(node, RefKind.Member)
- oldToNewNodeMap[node] = groupNode
- }
+ oldToNewNodeMap[node] = groupNode
}
return groupNode
}
@@ -140,25 +131,7 @@ class DocumentationMerger(
val mergedMembers = mergeMembers(from, refsToMembers)
// TODO: think about
- return mergedPackages + (mergedMembers + refsNotToMembers).distinctBy {
- it.to.kind to it.to.name
- }
- }
-
-
- private fun updatePendingReferences() {
- producedNodeRefGraph.references.forEach {
- it.lazyNodeFrom.update()
- it.lazyNodeTo.update()
- }
- }
-
- private fun NodeResolver.update() {
- if (this is NodeResolver.Exact) {
- if (exactNode != null && oldToNewNodeMap.containsKey(exactNode!!)) {
- exactNode = oldToNewNodeMap[exactNode!!]
- }
- }
+ return mergedPackages + mergedMembers + refsNotToMembers
}
fun merge(): DocumentationModule {
@@ -175,5 +148,18 @@ class DocumentationMerger(
return mergedDocumentationModule
}
+ private fun updatePendingReferences() {
+ for (ref in producedNodeRefGraph.references) {
+ ref.lazyNodeFrom.update()
+ ref.lazyNodeTo.update()
+ }
+ }
+ private fun NodeResolver.update() {
+ if (this is NodeResolver.Exact) {
+ if (exactNode != null && exactNode!! in oldToNewNodeMap) {
+ exactNode = oldToNewNodeMap[exactNode!!]
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt
index 37f62ed6..1193657e 100644
--- a/core/src/main/kotlin/Generation/DokkaGenerator.kt
+++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt
@@ -69,13 +69,13 @@ class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration,
logger.info("Analysing sources and libraries... ")
val startAnalyse = System.currentTimeMillis()
- val defaultPlatformAsList = listOf(passConfiguration.analysisPlatform.key)
+ val defaultPlatformAsList = passConfiguration.targets
val defaultPlatformsProvider = object : DefaultPlatformsProvider {
override fun getDefaultPlatforms(descriptor: DeclarationDescriptor): List<String> {
val containingFilePath = descriptor.sourcePsi()?.containingFile?.virtualFile?.canonicalPath
?.let { File(it).absolutePath }
val sourceRoot = containingFilePath?.let { path -> sourceRoots.find { path.startsWith(it.path) } }
- return sourceRoot?.platforms ?: defaultPlatformAsList
+ return /*sourceRoot?.platforms ?: */defaultPlatformAsList
}
}
@@ -83,12 +83,6 @@ class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration,
DokkaAnalysisModule(environment, dokkaConfiguration, defaultPlatformsProvider, documentationModule.nodeRefGraph, passConfiguration, logger))
buildDocumentationModule(injector, documentationModule, { isNotSample(it, passConfiguration.samples) }, includes)
- documentationModule.visit { it ->
- it.addReferenceTo(
- DocumentationNode(analysisPlatform.key, Content.Empty, NodeKind.Platform),
- RefKind.Platform
- )
- }
val timeAnalyse = System.currentTimeMillis() - startAnalyse
logger.info("done in ${timeAnalyse / 1000} secs")
@@ -96,15 +90,6 @@ class DokkaGenerator(val dokkaConfiguration: DokkaConfiguration,
Disposer.dispose(environment)
}
- private fun DocumentationNode.visit(action: (DocumentationNode) -> Unit) {
- action(this)
-
- for (member in members) {
- member.visit(action)
- }
- }
-
-
fun createAnalysisEnvironment(
sourcePaths: List<String>,
passConfiguration: DokkaConfiguration.PassConfiguration
diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
index be3eef71..c25a7069 100644
--- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
@@ -889,23 +889,27 @@ class DocumentationBuilder
}
- fun DocumentationNode.getParentForPackageMember(descriptor: DeclarationDescriptor,
- externalClassNodes: MutableMap<FqName, DocumentationNode>,
- allFqNames: Collection<FqName>): DocumentationNode {
+ fun DocumentationNode.getParentForPackageMember(
+ descriptor: DeclarationDescriptor,
+ externalClassNodes: MutableMap<FqName, DocumentationNode>,
+ allFqNames: Collection<FqName>,
+ packageName: FqName
+ ): DocumentationNode {
if (descriptor is CallableMemberDescriptor) {
val extensionClassDescriptor = descriptor.getExtensionClassDescriptor()
if (extensionClassDescriptor != null && isExtensionForExternalClass(descriptor, extensionClassDescriptor, allFqNames) &&
!ErrorUtils.isError(extensionClassDescriptor)) {
val fqName = DescriptorUtils.getFqNameSafe(extensionClassDescriptor)
- return externalClassNodes.getOrPut(fqName, {
+ return externalClassNodes.getOrPut(fqName) {
val newNode = DocumentationNode(fqName.asString(), Content.Empty, NodeKind.ExternalClass)
val externalLink = linkResolver.externalDocumentationLinkResolver.buildExternalDocumentationLink(extensionClassDescriptor)
if (externalLink != null) {
newNode.append(DocumentationNode(externalLink, Content.Empty, NodeKind.ExternalLink), RefKind.Link)
}
append(newNode, RefKind.Member)
+ refGraph.register("${packageName.asString()}:${extensionClassDescriptor.signature()}", newNode)
newNode
- })
+ }
}
}
return this
@@ -933,7 +937,12 @@ class KotlinPackageDocumentationBuilder : PackageDocumentationBuilder {
declarations.forEach { descriptor ->
with(documentationBuilder) {
if (descriptor.isDocumented(passConfiguration)) {
- val parent = packageNode.getParentForPackageMember(descriptor, externalClassNodes, allFqNames)
+ val parent = packageNode.getParentForPackageMember(
+ descriptor,
+ externalClassNodes,
+ allFqNames,
+ packageName
+ )
parent.appendOrUpdateMember(descriptor)
}
}
@@ -1025,7 +1034,7 @@ fun DeclarationDescriptor.signature(): String {
is TypeAliasDescriptor -> DescriptorUtils.getFqName(this).asString()
is PropertyDescriptor -> containingDeclaration.signature() + "$" + name + receiverSignature()
- is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature() + ":" + returnType?.signature()
+ is FunctionDescriptor -> containingDeclaration.signature() + "$" + name + parameterSignature() + ":" + returnType?.signature()
is ValueParameterDescriptor -> containingDeclaration.signature() + "/" + name
is TypeParameterDescriptor -> containingDeclaration.signature() + "*" + name
is ReceiverParameterDescriptor -> containingDeclaration.signature() + "/" + name