diff options
Diffstat (limited to 'src/Model/Content.kt')
-rw-r--r-- | src/Model/Content.kt | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/src/Model/Content.kt b/src/Model/Content.kt index 0bb78454..45d42a2d 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -1,10 +1,14 @@ package org.jetbrains.dokka -public abstract class ContentNode +public interface ContentNode { + val textLength: Int +} -public object ContentEmpty : ContentNode() +public object ContentEmpty : ContentNode { + override val textLength: Int get() = 0 +} -public open class ContentBlock() : ContentNode() { +public open class ContentBlock() : ContentNode { val children = arrayListOf<ContentNode>() fun append(node : ContentNode) { @@ -18,21 +22,58 @@ public open class ContentBlock() : ContentNode() { override fun hashCode(): Int = children.hashCode() + + override val textLength: Int + get() = children.sumBy { it.textLength } } enum class IdentifierKind { TypeName, ParameterName, AnnotationName, + SummarizedTypeName, Other } -public data class ContentText(val text: String) : ContentNode() -public data class ContentKeyword(val text: String) : ContentNode() -public data class ContentIdentifier(val text: String, val kind: IdentifierKind = IdentifierKind.Other) : ContentNode() -public data class ContentSymbol(val text: String) : ContentNode() -public data class ContentEntity(val text: String) : ContentNode() -public object ContentNonBreakingSpace: ContentNode() +public data class ContentText(val text: String) : ContentNode { + override val textLength: Int + get() = text.length +} + +public data class ContentKeyword(val text: String) : ContentNode { + override val textLength: Int + get() = text.length +} + +public data class ContentIdentifier(val text: String, val kind: IdentifierKind = IdentifierKind.Other) : ContentNode { + override val textLength: Int + get() = text.length +} + +public data class ContentSymbol(val text: String) : ContentNode { + override val textLength: Int + get() = text.length +} + +public data class ContentEntity(val text: String) : ContentNode { + override val textLength: Int + get() = text.length +} + +public object ContentNonBreakingSpace: ContentNode { + override val textLength: Int + get() = 1 +} + +public object ContentSoftLineBreak: ContentNode { + override val textLength: Int + get() = 0 +} + +public object ContentIndentedSoftLineBreak: ContentNode { + override val textLength: Int + get() = 0 +} public class ContentParagraph() : ContentBlock() public class ContentEmphasis() : ContentBlock() @@ -101,6 +142,9 @@ fun ContentBlock.keyword(value: String) = append(ContentKeyword(value)) fun ContentBlock.symbol(value: String) = append(ContentSymbol(value)) fun ContentBlock.identifier(value: String, kind: IdentifierKind = IdentifierKind.Other) = append(ContentIdentifier(value, kind)) fun ContentBlock.nbsp() = append(ContentNonBreakingSpace) +fun ContentBlock.softLineBreak() = append(ContentSoftLineBreak) +fun ContentBlock.indentedSoftLineBreak() = append(ContentIndentedSoftLineBreak) + fun ContentBlock.strong(body: ContentBlock.() -> Unit) { val strong = ContentStrong() strong.body() @@ -171,9 +215,6 @@ public open class MutableContent() : Content() { return "<empty>" return (listOf(summary, description) + sections).joinToString() } - - val isEmpty: Boolean - get() = sections.none() } fun javadocSectionDisplayName(sectionName: String?): String? = |