From c540bc28a79092b212e575fa18d33399faee83b9 Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Fri, 11 Jul 2014 17:44:02 +0400 Subject: Building model from nodes with references. --- src/DocumentationModel.kt | 65 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/DocumentationModel.kt b/src/DocumentationModel.kt index 77b38d79..3391c277 100644 --- a/src/DocumentationModel.kt +++ b/src/DocumentationModel.kt @@ -3,19 +3,72 @@ package com.jetbrains.dokka import com.intellij.psi.PsiFile import org.jetbrains.jet.lang.resolve.BindingContext -public class DocumentationNode { - val name = "fn" - val doc = "doc" +public enum class DocumentationNodeKind { + Package + Class + Function + Property + Parameter + TypeParameter + Exception + + Page + Module +} + +public enum class DocumentationReferenceKind { + Member + Detail + Owner + Link + Override +} + +public 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 } + + public fun addReferenceTo(to: DocumentationNode, kind: DocumentationReferenceKind) { + references.add(DocumentationReference(this, to, kind)) + } + + public fun references(kind: DocumentationReferenceKind): List = references.filter { it.kind == kind } } public class DocumentationModel { + private val items = arrayListOf() + fun merge(other: DocumentationModel): DocumentationModel { - return DocumentationModel() + val model = DocumentationModel() + model.addNodes(other.nodes) + model.addNodes(this.nodes) + return model + } + + public fun addNode(node: DocumentationNode) { + items.add(node) } - val items : List = listOf(DocumentationNode()) + public fun addNodes(nodes: List) { + items.addAll(nodes) + } + + public val nodes: List + get() = items } +public data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: DocumentationReferenceKind) + fun BindingContext.createDocumentation(file: PsiFile): DocumentationModel { - return DocumentationModel() + val model = DocumentationModel() + model.addNode(DocumentationNode("fn", "doc", DocumentationNodeKind.Function)) + return model } \ No newline at end of file -- cgit