aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Formats/StructuredFormatService.kt2
-rw-r--r--src/Kotlin/ContentBuilder.kt19
-rw-r--r--src/Kotlin/DocumentationBuilder.kt6
-rw-r--r--src/Kotlin/KotlinLanguageService.kt32
-rw-r--r--src/Model/Content.kt33
5 files changed, 46 insertions, 46 deletions
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index 6ec75379..ec4cff89 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -69,7 +69,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi
is ContentBlockCode -> {
appendBlockCode(this, formatText(location, content.children))
}
- else -> append(formatText(location, content.children))
+ is ContentBlock -> append(formatText(location, content.children))
}
}.toString()
}
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt
index 60b0e9e9..3d44c11b 100644
--- a/src/Kotlin/ContentBuilder.kt
+++ b/src/Kotlin/ContentBuilder.kt
@@ -16,9 +16,9 @@ public fun DocumentationBuilder.buildContent(tree: MarkdownNode): Content {
return result
}
-public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: ContentNode) {
+public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: ContentBlock) {
// println(tree.toTestString())
- val nodeStack = ArrayDeque<ContentNode>()
+ val nodeStack = ArrayDeque<ContentBlock>()
nodeStack.push(target)
tree.visit {(node, processChildren) ->
@@ -85,16 +85,13 @@ public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: Conte
MarkdownTokenTypes.WHITE_SPACE,
MarkdownTokenTypes.EOL -> {
if (keepWhitespace(nodeStack.peek()) && node.parent?.children?.last() != node) {
- nodeStack.push(ContentText(node.text))
- processChildren()
- parent.append(nodeStack.pop())
+ parent.append(ContentText(node.text))
}
}
- MarkdownTokenTypes.TEXT -> {
- nodeStack.push(ContentText(node.text))
- processChildren()
- parent.append(nodeStack.pop())
- }
+
+ MarkdownTokenTypes.TEXT ->
+ parent.append(ContentText(node.text))
+
MarkdownTokenTypes.CODE -> {
val block = ContentBlockCode()
block.append(ContentText(node.text))
@@ -124,7 +121,7 @@ public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: Conte
private fun keepWhitespace(node: ContentNode) = node is ContentParagraph || node is ContentSection
-public fun DocumentationBuilder.buildInlineContentTo(tree: MarkdownNode, target: ContentNode) {
+public fun DocumentationBuilder.buildInlineContentTo(tree: MarkdownNode, target: ContentBlock) {
val inlineContent = tree.children.singleOrNull { it.type == MarkdownElementTypes.PARAGRAPH }?.children ?: listOf(tree)
inlineContent.forEach {
buildContentTo(it, target)
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index d166fa82..f1be8a50 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -558,7 +558,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
return descriptor
}
- fun resolveContentLinks(node: DocumentationNode, content: ContentNode) {
+ fun resolveContentLinks(node: DocumentationNode, content: ContentBlock) {
val resolvedContentChildren = content.children.map { resolveContentLink(node, it) }
content.children.clear()
content.children.addAll(resolvedContentChildren)
@@ -577,7 +577,9 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
return contentLink
}
}
- resolveContentLinks(node, content)
+ if (content is ContentBlock) {
+ resolveContentLinks(node, content)
+ }
return content
}
}
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt
index 43854381..26eee435 100644
--- a/src/Kotlin/KotlinLanguageService.kt
+++ b/src/Kotlin/KotlinLanguageService.kt
@@ -42,13 +42,13 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderPackage(node: DocumentationNode) {
+ private fun ContentBlock.renderPackage(node: DocumentationNode) {
keyword("package")
text(" ")
identifier(node.name)
}
- private fun ContentNode.renderList(nodes: List<DocumentationNode>, separator: String = ", ", renderItem: (DocumentationNode) -> Unit) {
+ private fun ContentBlock.renderList(nodes: List<DocumentationNode>, separator: String = ", ", renderItem: (DocumentationNode) -> Unit) {
if (nodes.none())
return
renderItem(nodes.first())
@@ -58,7 +58,7 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderLinked(node: DocumentationNode, body: ContentNode.(DocumentationNode)->Unit) {
+ private fun ContentBlock.renderLinked(node: DocumentationNode, body: ContentNode.(DocumentationNode)->Unit) {
val to = node.links.firstOrNull()
if (to == null)
body(node)
@@ -68,7 +68,7 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderType(node: DocumentationNode) {
+ private fun ContentBlock.renderType(node: DocumentationNode) {
val typeArguments = node.details(DocumentationNode.Kind.Type)
if (node.name == "Function${typeArguments.count() - 1}") {
// lambda
@@ -108,7 +108,7 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderModifier(node: DocumentationNode) {
+ private fun ContentBlock.renderModifier(node: DocumentationNode) {
when (node.name) {
"final", "internal", "var" -> {}
else -> {
@@ -118,7 +118,7 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderTypeParameter(node: DocumentationNode) {
+ private fun ContentBlock.renderTypeParameter(node: DocumentationNode) {
val constraints = node.details(DocumentationNode.Kind.UpperBound)
identifier(node.name)
if (constraints.any()) {
@@ -129,7 +129,7 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderParameter(node: DocumentationNode) {
+ private fun ContentBlock.renderParameter(node: DocumentationNode) {
renderAnnotationsForNode(node)
identifier(node.name)
symbol(": ")
@@ -142,7 +142,7 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderTypeParametersForNode(node: DocumentationNode) {
+ private fun ContentBlock.renderTypeParametersForNode(node: DocumentationNode) {
val typeParameters = node.details(DocumentationNode.Kind.TypeParameter)
if (typeParameters.any()) {
symbol("<")
@@ -153,7 +153,7 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderSupertypesForNode(node: DocumentationNode) {
+ private fun ContentBlock.renderSupertypesForNode(node: DocumentationNode) {
val supertypes = node.details(DocumentationNode.Kind.Supertype)
if (supertypes.any()) {
symbol(" : ")
@@ -163,7 +163,7 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderModifiersForNode(node: DocumentationNode) {
+ private fun ContentBlock.renderModifiersForNode(node: DocumentationNode) {
val modifiers = node.details(DocumentationNode.Kind.Modifier)
for (it in modifiers) {
if (node.kind == org.jetbrains.dokka.DocumentationNode.Kind.Interface && it.name == "abstract")
@@ -172,13 +172,13 @@ class KotlinLanguageService : LanguageService {
}
}
- private fun ContentNode.renderAnnotationsForNode(node: DocumentationNode) {
+ private fun ContentBlock.renderAnnotationsForNode(node: DocumentationNode) {
node.annotations.forEach {
renderAnnotation(it)
}
}
- private fun ContentNode.renderAnnotation(node: DocumentationNode) {
+ private fun ContentBlock.renderAnnotation(node: DocumentationNode) {
identifier(node.name)
val parameters = node.details(DocumentationNode.Kind.Parameter)
if (!parameters.isEmpty()) {
@@ -191,7 +191,7 @@ class KotlinLanguageService : LanguageService {
text(" ")
}
- private fun ContentNode.renderClass(node: DocumentationNode) {
+ private fun ContentBlock.renderClass(node: DocumentationNode) {
renderModifiersForNode(node)
renderAnnotationsForNode(node)
when (node.kind) {
@@ -209,7 +209,7 @@ class KotlinLanguageService : LanguageService {
renderSupertypesForNode(node)
}
- private fun ContentNode.renderFunction(node: DocumentationNode) {
+ private fun ContentBlock.renderFunction(node: DocumentationNode) {
renderModifiersForNode(node)
renderAnnotationsForNode(node)
when (node.kind) {
@@ -246,7 +246,7 @@ class KotlinLanguageService : LanguageService {
else -> true
}
- private fun ContentNode.renderProperty(node: DocumentationNode) {
+ private fun ContentBlock.renderProperty(node: DocumentationNode) {
renderModifiersForNode(node)
renderAnnotationsForNode(node)
when (node.kind) {
@@ -269,7 +269,7 @@ class KotlinLanguageService : LanguageService {
fun DocumentationNode.getPropertyKeyword() =
if (details(DocumentationNode.Kind.Modifier).any { it.name == "var" }) "var" else "val"
- fun ContentNode.identifierOrDeprecated(node: DocumentationNode) {
+ fun ContentBlock.identifierOrDeprecated(node: DocumentationNode) {
if (node.deprecation != null) {
val strike = ContentStrikethrough()
strike.identifier(node.name)
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index bb0ff00f..165865a0 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -3,11 +3,15 @@ package org.jetbrains.dokka
import kotlin.properties.Delegates
public abstract class ContentNode {
- val children = arrayListOf<ContentNode>()
-
class object {
val empty = ContentEmpty
}
+}
+
+public object ContentEmpty : ContentNode()
+
+public open class ContentBlock() : ContentNode() {
+ val children = arrayListOf<ContentNode>()
fun append(node : ContentNode) {
children.add(node)
@@ -16,13 +20,10 @@ public abstract class ContentNode {
fun isEmpty() = children.isEmpty()
}
-public object ContentEmpty : ContentNode()
-public open class ContentBlock() : ContentNode()
-
-public class ContentText(val text: String) : ContentNode()
-public class ContentKeyword(val text: String) : ContentNode()
-public class ContentIdentifier(val text: String) : ContentNode()
-public class ContentSymbol(val text: String) : ContentNode()
+public data class ContentText(val text: String) : ContentNode()
+public data class ContentKeyword(val text: String) : ContentNode()
+public data class ContentIdentifier(val text: String) : ContentNode()
+public data class ContentSymbol(val text: String) : ContentNode()
public class ContentParagraph() : ContentBlock()
public class ContentEmphasis() : ContentBlock()
@@ -36,24 +37,24 @@ public class ContentList() : ContentBlock()
public class ContentListItem() : ContentBlock()
public class ContentSection(public val tag: String, public val subjectName: String?) : ContentBlock()
-fun content(body: ContentNode.() -> Unit): ContentNode {
+fun content(body: ContentBlock.() -> Unit): ContentBlock {
val block = ContentBlock()
block.body()
return block
}
-fun ContentNode.text(value: String) = append(ContentText(value))
-fun ContentNode.keyword(value: String) = append(ContentKeyword(value))
-fun ContentNode.symbol(value: String) = append(ContentSymbol(value))
-fun ContentNode.identifier(value: String) = append(ContentIdentifier(value))
+fun ContentBlock.text(value: String) = append(ContentText(value))
+fun ContentBlock.keyword(value: String) = append(ContentKeyword(value))
+fun ContentBlock.symbol(value: String) = append(ContentSymbol(value))
+fun ContentBlock.identifier(value: String) = append(ContentIdentifier(value))
-fun ContentNode.link(to: DocumentationNode, body: ContentNode.() -> Unit) {
+fun ContentBlock.link(to: DocumentationNode, body: ContentNode.() -> Unit) {
val block = ContentNodeLink(to)
block.body()
append(block)
}
-public class Content() : ContentNode() {
+public class Content() : ContentBlock() {
private val sectionList = arrayListOf<ContentSection>()
public val sections: List<ContentSection>
get() = sectionList