aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 17:44:02 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 17:44:02 +0400
commitc540bc28a79092b212e575fa18d33399faee83b9 (patch)
tree48b7bdd02b3d948b2dae3950aa44cf57ef46d4f6
parentdeae3bfbe0a5bda997f3033693879042a058de3a (diff)
downloaddokka-c540bc28a79092b212e575fa18d33399faee83b9.tar.gz
dokka-c540bc28a79092b212e575fa18d33399faee83b9.tar.bz2
dokka-c540bc28a79092b212e575fa18d33399faee83b9.zip
Building model from nodes with references.
-rw-r--r--src/DocumentationModel.kt65
-rw-r--r--test/src/DiscoveryTest.kt15
-rw-r--r--test/src/TopLevelFunctionTest.kt20
3 files changed, 79 insertions, 21 deletions
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<DocumentationReference>()
+
+ public val owner: DocumentationNode
+ get() = references(DocumentationReferenceKind.Owner).single().to
+ public val details: List<DocumentationNode>
+ get() = references(DocumentationReferenceKind.Detail).map { it.to }
+ public val members: List<DocumentationNode>
+ get() = references(DocumentationReferenceKind.Member).map { it.to }
+ public val links: List<DocumentationNode>
+ 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<DocumentationReference> = references.filter { it.kind == kind }
}
public class DocumentationModel {
+ private val items = arrayListOf<DocumentationNode>()
+
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<DocumentationNode> = listOf(DocumentationNode())
+ public fun addNodes(nodes: List<DocumentationNode>) {
+ items.addAll(nodes)
+ }
+
+ public val nodes: List<DocumentationNode>
+ 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
diff --git a/test/src/DiscoveryTest.kt b/test/src/DiscoveryTest.kt
deleted file mode 100644
index f854b4d6..00000000
--- a/test/src/DiscoveryTest.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.jetbrains.dokka.tests
-
-import org.junit.Test
-import kotlin.test.*
-
-
-public class FunctionTest {
- Test fun function() {
- verifyFiles("test/data/function.kt") { model ->
- val item = model.items.single()
- assertEquals("fn", item.name)
- assertEquals("doc", item.doc)
- }
- }
-} \ No newline at end of file
diff --git a/test/src/TopLevelFunctionTest.kt b/test/src/TopLevelFunctionTest.kt
new file mode 100644
index 00000000..a51b7bdd
--- /dev/null
+++ b/test/src/TopLevelFunctionTest.kt
@@ -0,0 +1,20 @@
+package com.jetbrains.dokka.tests
+
+import org.junit.Test
+import kotlin.test.*
+import com.jetbrains.dokka.*
+
+
+public class TopLevelFunctionTest {
+ Test fun function() {
+ verifyFiles("test/data/function.kt") { model ->
+ val item = model.nodes.single()
+ assertEquals(DocumentationNodeKind.Function, item.kind)
+ assertEquals("fn", item.name)
+ assertEquals("doc", item.doc)
+ assertTrue(item.details.none())
+ assertTrue(item.members.none())
+ assertTrue(item.links.none())
+ }
+ }
+} \ No newline at end of file