aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Content.kt
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-09-29 20:54:59 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-09-29 20:54:59 +0400
commit778e2b3f7ff62971e18a49d81a8825e5dd894c2e (patch)
treef7fb9506800262ecabb9050ffee4a97e39812ccb /src/Model/Content.kt
parent2e3dc238275073a5c7a2e5a14c79337d12492dad (diff)
downloaddokka-778e2b3f7ff62971e18a49d81a8825e5dd894c2e.tar.gz
dokka-778e2b3f7ff62971e18a49d81a8825e5dd894c2e.tar.bz2
dokka-778e2b3f7ff62971e18a49d81a8825e5dd894c2e.zip
Extract content model, make doc model independent from descriptors, parse doccomments with custom parser, some tests failing due to hanging new lines.
Diffstat (limited to 'src/Model/Content.kt')
-rw-r--r--src/Model/Content.kt88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
new file mode 100644
index 00000000..eb092cb2
--- /dev/null
+++ b/src/Model/Content.kt
@@ -0,0 +1,88 @@
+package org.jetbrains.dokka
+
+import kotlin.properties.Delegates
+
+public abstract class ContentNode {
+ val children = arrayListOf<ContentNode>()
+
+ class object {
+ val empty = ContentEmpty
+ }
+
+ fun isEmpty() = children.isEmpty()
+}
+
+public object ContentEmpty : ContentNode( )
+
+public class ContentText(val text : String) : ContentNode( )
+public class ContentBlock() : ContentNode( )
+public class ContentEmphasis() : ContentNode()
+public class ContentStrong() : ContentNode()
+public class ContentList() : ContentNode()
+public class ContentSection(public val label: String) : ContentNode()
+
+public class Content() : ContentNode() {
+ public val sections: Map<String, ContentSection> by Delegates.lazy {
+ val map = hashMapOf<String, ContentSection>()
+ for (child in children) {
+ if (child is ContentSection)
+ map.put(child.label, child)
+ }
+
+ if ("\$summary" !in map && "\$description" !in map) {
+ // no explicit summary and description, convert anonymous section
+ val anonymous = map[""]
+ if (anonymous != null) {
+ map.remove("")
+ val summary = ContentSection("\$summary")
+ val description = ContentSection("\$description")
+
+ val summaryNodes = anonymous.children.take(1)
+ val descriptionNodes = anonymous.children.drop(1)
+
+ if (summaryNodes.any()) {
+ summary.children.addAll(summaryNodes)
+ map.put("\$summary", summary)
+ }
+
+ if (descriptionNodes.any()) {
+ description.children.addAll(descriptionNodes)
+ map.put("\$description", description)
+ }
+ }
+ }
+ map
+ }
+
+ public val summary: ContentNode get() = sections["\$summary"] ?: ContentNode.empty
+ public val description: ContentNode get() = sections["\$description"] ?: ContentNode.empty
+
+ override fun equals(other: Any?): Boolean {
+ if (other !is Content)
+ return false
+ if (sections.size != other.sections.size)
+ return false
+ for (keys in sections.keySet())
+ if (sections[keys] != other.sections[keys])
+ return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ return sections.map { it.hashCode() }.sum()
+ }
+
+ override fun toString(): String {
+ if (sections.isEmpty())
+ return "<empty>"
+ return sections.values().joinToString()
+ }
+
+ val isEmpty: Boolean
+ get() = sections.none()
+
+ class object {
+ val Empty = Content()
+ }
+}