aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Kotlin/DocumentationBuilder.kt13
-rw-r--r--src/Model/DocumentationNode.kt21
2 files changed, 21 insertions, 13 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index f1be8a50..068f251a 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -38,7 +38,6 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
val descriptorToNode = hashMapOf<DeclarationDescriptor, DocumentationNode>()
val nodeToDescriptor = hashMapOf<DocumentationNode, DeclarationDescriptor>()
val links = hashMapOf<DocumentationNode, DeclarationDescriptor>()
- val packages = hashMapOf<FqName, DocumentationNode>()
fun parseDocumentation(descriptor: DeclarationDescriptor): Content {
val kdoc = KDocFinder.findKDoc(descriptor)
@@ -119,15 +118,6 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
return this
}
- fun DocumentationNode.append(child: DocumentationNode, kind: DocumentationReference.Kind) {
- addReferenceTo(child, kind)
- when (kind) {
- DocumentationReference.Kind.Detail -> child.addReferenceTo(this, DocumentationReference.Kind.Owner)
- DocumentationReference.Kind.Member -> child.addReferenceTo(this, DocumentationReference.Kind.Owner)
- DocumentationReference.Kind.Owner -> child.addReferenceTo(this, DocumentationReference.Kind.Member)
- }
- }
-
fun DocumentationNode.appendModality(descriptor: MemberDescriptor) {
var modality = descriptor.getModality()
if (modality == Modality.OPEN) {
@@ -269,13 +259,12 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
}
for ((packageName, declarations) in descriptors) {
logger.info(" package $packageName: ${declarations.count()} declarations")
- val packageNode = DocumentationNode(packageName, Content.Empty, Kind.Package)
+ val packageNode = findOrCreatePackageNode(packageName)
val externalClassNodes = hashMapOf<FqName, DocumentationNode>()
declarations.forEach { descriptor ->
val parent = packageNode.getParentForPackageMember(descriptor, externalClassNodes)
parent.appendChild(descriptor, DocumentationReference.Kind.Member)
}
- append(packageNode, DocumentationReference.Kind.Member)
}
}
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index c3700069..64a854a8 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -101,4 +101,23 @@ val DocumentationNode.path: List<DocumentationNode>
if (parent == null)
return listOf(this)
return parent.path + this
- } \ No newline at end of file
+ }
+
+fun DocumentationNode.findOrCreatePackageNode(packageName: String): DocumentationNode {
+ val existingNode = members(DocumentationNode.Kind.Package).firstOrNull { it.name == packageName }
+ if (existingNode != null) {
+ return existingNode
+ }
+ val newNode = DocumentationNode(packageName, Content.Empty, DocumentationNode.Kind.Package)
+ append(newNode, DocumentationReference.Kind.Member)
+ return newNode
+}
+
+fun DocumentationNode.append(child: DocumentationNode, kind: DocumentationReference.Kind) {
+ addReferenceTo(child, kind)
+ when (kind) {
+ DocumentationReference.Kind.Detail -> child.addReferenceTo(this, DocumentationReference.Kind.Owner)
+ DocumentationReference.Kind.Member -> child.addReferenceTo(this, DocumentationReference.Kind.Owner)
+ DocumentationReference.Kind.Owner -> child.addReferenceTo(this, DocumentationReference.Kind.Member)
+ }
+}