aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Kotlin/DocumentationBuilder.kt36
-rw-r--r--src/Model/DocumentationReference.kt13
-rw-r--r--src/main.kt6
3 files changed, 27 insertions, 28 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index 5d9857a7..dae1c4ea 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -33,14 +33,12 @@ private fun isSamePackage(descriptor1: DeclarationDescriptor, descriptor2: Decla
return package1 != null && package2 != null && package1.fqName == package2.fqName
}
-class PendingLink(val lazyNodeFrom: () -> DocumentationNode?,
- val lazyNodeTo: () -> DocumentationNode?,
- val kind: DocumentationReference.Kind)
-
-class DocumentationBuilder(val session: ResolveSession, val options: DocumentationOptions, val logger: DokkaLogger) {
+class DocumentationBuilder(val session: ResolveSession,
+ val options: DocumentationOptions,
+ val pendingReferences: MutableList<PendingDocumentationReference>,
+ val logger: DokkaLogger) {
val visibleToDocumentation = setOf(Visibilities.INTERNAL, Visibilities.PROTECTED, Visibilities.PUBLIC)
val descriptorToNode = hashMapOf<DeclarationDescriptor, DocumentationNode>()
- val links = arrayListOf<PendingLink>()
fun parseDocumentation(descriptor: DeclarationDescriptor): Content {
val kdoc = KDocFinder.findKDoc(descriptor)
@@ -104,12 +102,18 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
}
fun link(node: DocumentationNode, descriptor: DeclarationDescriptor) {
- links.add(PendingLink({() -> node}, {() -> descriptorToNode[descriptor]}, DocumentationReference.Kind.Link))
+ pendingReferences.add(PendingDocumentationReference(
+ {() -> node},
+ {() -> descriptorToNode[descriptor]},
+ DocumentationReference.Kind.Link))
}
fun link(fromDescriptor: DeclarationDescriptor?, toDescriptor: DeclarationDescriptor?, kind: DocumentationReference.Kind) {
if (fromDescriptor != null && toDescriptor != null) {
- links.add(PendingLink({() -> descriptorToNode[fromDescriptor]}, {() -> descriptorToNode[toDescriptor]}, kind))
+ pendingReferences.add(PendingDocumentationReference(
+ {() -> descriptorToNode[fromDescriptor]},
+ {() -> descriptorToNode[toDescriptor]},
+ kind))
}
}
@@ -489,20 +493,4 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
}
return if (valueString != null) DocumentationNode(valueString, Content.Empty, DocumentationNode.Kind.Value) else null
}
-
- /**
- * Generates cross-references for documentation such as extensions for a type, inheritors, etc
- *
- * $receiver: [DocumentationContext] for node/descriptor resolutions
- * $node: [DocumentationNode] to visit
- */
- public fun resolveReferences() {
- for (link in links) {
- val fromNode = link.lazyNodeFrom()
- val toNode = link.lazyNodeTo()
- if (fromNode != null && toNode != null) {
- fromNode.addReferenceTo(toNode, link.kind)
- }
- }
- }
}
diff --git a/src/Model/DocumentationReference.kt b/src/Model/DocumentationReference.kt
index d7ad5f9e..4bc819f6 100644
--- a/src/Model/DocumentationReference.kt
+++ b/src/Model/DocumentationReference.kt
@@ -15,5 +15,14 @@ public data class DocumentationReference(val from: DocumentationNode, val to: Do
}
}
-
-
+class PendingDocumentationReference(val lazyNodeFrom: () -> DocumentationNode?,
+ val lazyNodeTo: () -> DocumentationNode?,
+ val kind: DocumentationReference.Kind) {
+ fun resolve() {
+ val fromNode = lazyNodeFrom()
+ val toNode = lazyNodeTo()
+ if (fromNode != null && toNode != null) {
+ fromNode.addReferenceTo(toNode, kind)
+ }
+ }
+}
diff --git a/src/main.kt b/src/main.kt
index 44c435d2..535eee5c 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -195,7 +195,8 @@ fun buildDocumentationModule(environment: AnalysisEnvironment,
val fragments = fragmentFiles.map { session.getPackageFragment(it.getPackageFqName()) }.filterNotNull().distinct()
val moduleContent = Content()
- val documentationBuilder = DocumentationBuilder(session, options, logger)
+ val pendingReferences = arrayListOf<PendingDocumentationReference>()
+ val documentationBuilder = DocumentationBuilder(session, options, pendingReferences, logger)
for (include in includes) {
val file = File(include)
if (file.exists()) {
@@ -211,13 +212,14 @@ fun buildDocumentationModule(environment: AnalysisEnvironment,
with(documentationBuilder) {
documentationModule.appendFragments(fragments)
- documentationBuilder.resolveReferences()
}
val javaFiles = environment.getJavaSourceFiles().filter(filesToDocumentFilter)
val javaDocumentationBuilder = JavaDocumentationBuilder(options)
javaFiles.map { javaDocumentationBuilder.appendFile(it, documentationModule) }
+ pendingReferences.forEach { it.resolve() }
+
documentationModule
}