diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-02-10 18:32:12 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-02-10 18:32:12 +0100 |
commit | 0d0fc1f2bf8f09106e53626bc024298dc91361b8 (patch) | |
tree | 7364f5a98dacdad3524389c0d818b32ab2641009 /src/Kotlin | |
parent | 92075236fb1356fe6023edff1e43fe3125b76c18 (diff) | |
download | dokka-0d0fc1f2bf8f09106e53626bc024298dc91361b8.tar.gz dokka-0d0fc1f2bf8f09106e53626bc024298dc91361b8.tar.bz2 dokka-0d0fc1f2bf8f09106e53626bc024298dc91361b8.zip |
distinguish ContentBlock (a ContentNode that has children) from leaf nodes
Diffstat (limited to 'src/Kotlin')
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 19 | ||||
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 6 | ||||
-rw-r--r-- | src/Kotlin/KotlinLanguageService.kt | 32 |
3 files changed, 28 insertions, 29 deletions
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) |