From 778e2b3f7ff62971e18a49d81a8825e5dd894c2e Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Mon, 29 Sep 2014 20:54:59 +0400 Subject: Extract content model, make doc model independent from descriptors, parse doccomments with custom parser, some tests failing due to hanging new lines. --- src/Model/Content.kt | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/Model/Content.kt (limited to 'src/Model/Content.kt') 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() + + 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 by Delegates.lazy { + val map = hashMapOf() + 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 "" + return sections.values().joinToString() + } + + val isEmpty: Boolean + get() = sections.none() + + class object { + val Empty = Content() + } +} -- cgit