From 197a6e486d16d2e3689e900b45c65ef8d598f3b7 Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Fri, 11 Jul 2014 20:54:26 +0400 Subject: Rename Documentation folder to Model --- src/Model/DocumentationModel.kt | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/Model/DocumentationModel.kt (limited to 'src/Model/DocumentationModel.kt') diff --git a/src/Model/DocumentationModel.kt b/src/Model/DocumentationModel.kt new file mode 100644 index 00000000..0113eb18 --- /dev/null +++ b/src/Model/DocumentationModel.kt @@ -0,0 +1,67 @@ +package org.jetbrains.dokka + +import org.jetbrains.jet.lang.resolve.BindingContext +import org.jetbrains.jet.lang.psi.JetFile + +public enum class DocumentationNodeKind { + Unknown + + Package + Class + Object + Constructor + Function + Property + Parameter + TypeParameter + Exception + + Page + Model +} + +public enum class DocumentationReferenceKind { + Member + Detail + Owner + Link + Override +} + +public open class DocumentationNode(val name: String, val doc: String, val kind: DocumentationNodeKind) { + private val references = arrayListOf() + + public val owner: DocumentationNode + get() = references(DocumentationReferenceKind.Owner).single().to + public val details: List + get() = references(DocumentationReferenceKind.Detail).map { it.to } + public val members: List + get() = references(DocumentationReferenceKind.Member).map { it.to } + public val links: List + get() = references(DocumentationReferenceKind.Link).map { it.to } + + // TODO: Should we allow node mutation? Model merge will copy by ref, so references are transparent, which could nice + public fun addReferenceTo(to: DocumentationNode, kind: DocumentationReferenceKind) { + references.add(DocumentationReference(this, to, kind)) + } + + public fun addAllReferencesFrom(other: DocumentationNode) { + references.addAll(other.references) + } + + public fun references(kind: DocumentationReferenceKind): List = references.filter { it.kind == kind } +} + +public class DocumentationModel : DocumentationNode("model", "", DocumentationNodeKind.Model) { + fun merge(other: DocumentationModel): DocumentationModel { + val model = DocumentationModel() + model.addAllReferencesFrom(other) + model.addAllReferencesFrom(this) + return model + } + + public val nodes: List + get() = members +} + +public data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: DocumentationReferenceKind) -- cgit