aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Formats/StructuredFormatService.kt3
-rw-r--r--src/Java/JavaDocumentationBuilder.kt21
-rw-r--r--src/Kotlin/DocumentationBuilder.kt17
-rw-r--r--src/Model/Content.kt6
-rw-r--r--src/Model/DocumentationReference.kt27
-rw-r--r--src/main.kt8
6 files changed, 49 insertions, 33 deletions
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index efddd578..2eb298d8 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -57,7 +57,8 @@ public abstract class StructuredFormatService(locationService: LocationService,
is ContentListItem -> append(formatListItem(formatText(location, content.children)))
is ContentNodeLink -> {
- val linkTo = locationHref(location, content.node)
+ val node = content.node
+ val linkTo = if (node != null) locationHref(location, node) else "#"
val linkText = formatText(location, content.children)
append(formatLink(linkText, linkTo))
}
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt
index 55f9017b..a7016ae6 100644
--- a/src/Java/JavaDocumentationBuilder.kt
+++ b/src/Java/JavaDocumentationBuilder.kt
@@ -8,9 +8,7 @@ import com.intellij.psi.javadoc.PsiInlineDocTag
import org.jetbrains.dokka.DocumentationNode.Kind
public class JavaDocumentationBuilder(private val options: DocumentationOptions,
- private val pendingReferences: MutableList<PendingDocumentationReference>) {
- private val signatureToNode = hashMapOf<String, DocumentationNode>()
-
+ private val refGraph: NodeReferenceGraph) {
fun appendFile(file: PsiJavaFile, module: DocumentationModule) {
val packageNode = module.findOrCreatePackageNode(file.getPackageName())
packageNode.appendChildren(file.getClasses()) { build() }
@@ -87,7 +85,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions,
if (target != null) {
val signature = getSignature(target)
if (signature != null) {
- return ContentNodeLazyLink(valueElement!!.getText(), {() -> signatureToNode[signature]})
+ return ContentNodeLazyLink(valueElement!!.getText(), {() -> refGraph.lookup(signature)})
}
}
return null
@@ -101,26 +99,23 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions,
}
fun register(element: PsiElement, node: DocumentationNode) {
- signatureToNode[getSignature(element)] = node
+ val signature = getSignature(element)
+ if (signature != null) {
+ refGraph.register(signature, node)
+ }
}
fun link(node: DocumentationNode, element: PsiElement?) {
val qualifiedName = getSignature(element)
if (qualifiedName != null) {
- pendingReferences.add(PendingDocumentationReference(
- {() -> node},
- {() -> signatureToNode[qualifiedName]},
- DocumentationReference.Kind.Link))
+ refGraph.link(node, qualifiedName, DocumentationReference.Kind.Link)
}
}
fun link(element: PsiElement?, node: DocumentationNode, kind: DocumentationReference.Kind) {
val qualifiedName = getSignature(element)
if (qualifiedName != null) {
- pendingReferences.add(PendingDocumentationReference(
- {() -> signatureToNode[qualifiedName]},
- {() -> node},
- kind))
+ refGraph.link(qualifiedName, node, kind)
}
}
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index b620a4f9..693f2675 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -35,10 +35,9 @@ private fun isSamePackage(descriptor1: DeclarationDescriptor, descriptor2: Decla
class DocumentationBuilder(val session: ResolveSession,
val options: DocumentationOptions,
- val pendingReferences: MutableList<PendingDocumentationReference>,
+ val refGraph: NodeReferenceGraph,
val logger: DokkaLogger) {
val visibleToDocumentation = setOf(Visibilities.INTERNAL, Visibilities.PROTECTED, Visibilities.PUBLIC)
- val descriptorToNode = hashMapOf<String, DocumentationNode>()
fun parseDocumentation(descriptor: DeclarationDescriptor): Content {
val kdoc = KDocFinder.findKDoc(descriptor)
@@ -106,7 +105,7 @@ class DocumentationBuilder(val session: ResolveSession,
// assume that if an href doesn't contain '/', it's not an attempt to reference an external file
if (symbols.isNotEmpty()) {
val symbol = symbols.first()
- return ContentNodeLazyLink(href, {() -> descriptorToNode[symbol.signature()] })
+ return ContentNodeLazyLink(href, {() -> refGraph.lookup(symbol.signature()) })
}
if ("/" in href) {
return ContentExternalLink(href)
@@ -129,23 +128,17 @@ class DocumentationBuilder(val session: ResolveSession,
}
fun link(node: DocumentationNode, descriptor: DeclarationDescriptor) {
- pendingReferences.add(PendingDocumentationReference(
- {() -> node},
- {() -> descriptorToNode[descriptor.signature()]},
- DocumentationReference.Kind.Link))
+ refGraph.link(node, descriptor.signature(), DocumentationReference.Kind.Link)
}
fun link(fromDescriptor: DeclarationDescriptor?, toDescriptor: DeclarationDescriptor?, kind: DocumentationReference.Kind) {
if (fromDescriptor != null && toDescriptor != null) {
- pendingReferences.add(PendingDocumentationReference(
- {() -> descriptorToNode[fromDescriptor.signature()]},
- {() -> descriptorToNode[toDescriptor.signature()]},
- kind))
+ refGraph.link(fromDescriptor.signature(), toDescriptor.signature(), kind)
}
}
fun register(descriptor: DeclarationDescriptor, node: DocumentationNode) {
- descriptorToNode.put(descriptor.signature(), node)
+ refGraph.register(descriptor.signature(), node)
}
fun DocumentationNode<T>(descriptor: T, kind: Kind): DocumentationNode where T : DeclarationDescriptor, T : Named {
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index 01d7b206..5688e2b8 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -39,7 +39,7 @@ public class ContentCode() : ContentBlock()
public class ContentBlockCode() : ContentBlock()
public abstract class ContentNodeLink() : ContentBlock() {
- abstract val node: DocumentationNode
+ abstract val node: DocumentationNode?
}
public class ContentNodeDirectLink(override val node: DocumentationNode): ContentNodeLink() {
@@ -50,8 +50,8 @@ public class ContentNodeDirectLink(override val node: DocumentationNode): Conten
children.hashCode() * 31 + node.name.hashCode()
}
-public class ContentNodeLazyLink(val linkText: String, val lazyNode: () -> DocumentationNode): ContentNodeLink() {
- override val node: DocumentationNode get() = lazyNode()
+public class ContentNodeLazyLink(val linkText: String, val lazyNode: () -> DocumentationNode?): ContentNodeLink() {
+ override val node: DocumentationNode? get() = lazyNode()
override fun equals(other: Any?): Boolean =
super.equals(other) && other is ContentNodeLazyLink && linkText == other.linkText
diff --git a/src/Model/DocumentationReference.kt b/src/Model/DocumentationReference.kt
index 4bc819f6..73d883e6 100644
--- a/src/Model/DocumentationReference.kt
+++ b/src/Model/DocumentationReference.kt
@@ -26,3 +26,30 @@ class PendingDocumentationReference(val lazyNodeFrom: () -> DocumentationNode?,
}
}
}
+
+class NodeReferenceGraph() {
+ private val nodeMap = hashMapOf<String, DocumentationNode>()
+ val references = arrayListOf<PendingDocumentationReference>()
+
+ fun register(signature: String, node: DocumentationNode) {
+ nodeMap.put(signature, node)
+ }
+
+ fun link(fromNode: DocumentationNode, toSignature: String, kind: DocumentationReference.Kind) {
+ references.add(PendingDocumentationReference({() -> fromNode}, {() -> nodeMap[toSignature]}, kind))
+ }
+
+ fun link(fromSignature: String, toNode: DocumentationNode, kind: DocumentationReference.Kind) {
+ references.add(PendingDocumentationReference({() -> nodeMap[fromSignature]}, {() -> toNode}, kind))
+ }
+
+ fun link(fromSignature: String, toSignature: String, kind: DocumentationReference.Kind) {
+ references.add(PendingDocumentationReference({() -> nodeMap[fromSignature]}, {() -> nodeMap[toSignature]}, kind))
+ }
+
+ fun lookup(signature: String): DocumentationNode? = nodeMap[signature]
+
+ fun resolveReferences() {
+ references.forEach { it.resolve() }
+ }
+}
diff --git a/src/main.kt b/src/main.kt
index a48b4af6..242ac85a 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -195,8 +195,8 @@ fun buildDocumentationModule(environment: AnalysisEnvironment,
val fragments = fragmentFiles.map { session.getPackageFragment(it.getPackageFqName()) }.filterNotNull().distinct()
val moduleContent = Content()
- val pendingReferences = arrayListOf<PendingDocumentationReference>()
- val documentationBuilder = DocumentationBuilder(session, options, pendingReferences, logger)
+ val refGraph = NodeReferenceGraph()
+ val documentationBuilder = DocumentationBuilder(session, options, refGraph, logger)
for (include in includes) {
val file = File(include)
if (file.exists()) {
@@ -215,10 +215,10 @@ fun buildDocumentationModule(environment: AnalysisEnvironment,
}
val javaFiles = environment.getJavaSourceFiles().filter(filesToDocumentFilter)
- val javaDocumentationBuilder = JavaDocumentationBuilder(options, pendingReferences)
+ val javaDocumentationBuilder = JavaDocumentationBuilder(options, refGraph)
javaFiles.map { javaDocumentationBuilder.appendFile(it, documentationModule) }
- pendingReferences.forEach { it.resolve() }
+ refGraph.resolveReferences()
documentationModule
}