diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-10-13 18:22:02 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-10-13 18:22:02 +0400 |
commit | ad14ea91a52563c83a3aba0c7d279cd5535b77e4 (patch) | |
tree | d78275d4d0ff3e51f604f059aee1b485028156f4 /src/Kotlin/ContentBuilder.kt | |
parent | 498448826d8762add15a524097e91e96b545a631 (diff) | |
download | dokka-ad14ea91a52563c83a3aba0c7d279cd5535b77e4.tar.gz dokka-ad14ea91a52563c83a3aba0c7d279cd5535b77e4.tar.bz2 dokka-ad14ea91a52563c83a3aba0c7d279cd5535b77e4.zip |
Fixing formats and started work on inline function body.
Diffstat (limited to 'src/Kotlin/ContentBuilder.kt')
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 9de3001a..58e41bec 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -2,15 +2,18 @@ package org.jetbrains.dokka import org.jetbrains.markdown.MarkdownElementTypes import java.util.ArrayDeque +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor +import org.jetbrains.jet.lang.resolve.name.Name +import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils -public fun MarkdownTree.toContent(): Content { +public fun DocumentationBuilder.buildContent(tree: MarkdownTree, descriptor: DeclarationDescriptor): Content { val nodeStack = ArrayDeque<ContentNode>() nodeStack.push(Content()) - visit {(node, text, processChildren) -> + tree.visit {(node, text, processChildren) -> val parent = nodeStack.peek()!! val nodeType = node.getTokenType() - val nodeText = getNodeText(node) + val nodeText = tree.getNodeText(node) when (nodeType) { MarkdownElementTypes.BULLET_LIST -> { nodeStack.push(ContentList()) @@ -49,15 +52,22 @@ public fun MarkdownTree.toContent(): Content { processChildren() parent.append(nodeStack.pop()) } + MarkdownElementTypes.DIRECTIVE -> { + val name = tree.findChildByType(node, MarkdownElementTypes.DIRECTIVE_NAME)?.let { tree.getNodeText(it) } ?: "" + val params = tree.findChildByType(node, MarkdownElementTypes.DIRECTIVE_PARAMS)?.let { tree.getNodeText(it) } ?: "" + when (name) { + "code" -> parent.append(functionBody(descriptor, params)) + } + } MarkdownElementTypes.NAMED_SECTION -> { - val label = findChildByType(node, MarkdownElementTypes.SECTION_NAME)?.let { getNodeText(it) } ?: "" + val label = tree.findChildByType(node, MarkdownElementTypes.SECTION_NAME)?.let { tree.getNodeText(it) } ?: "" nodeStack.push(ContentSection(label)) processChildren() parent.append(nodeStack.pop()) } MarkdownElementTypes.LINK -> { - val target = findChildByType(node, MarkdownElementTypes.TARGET)?.let { getNodeText(it) } ?: "" - val href = findChildByType(node, MarkdownElementTypes.HREF)?.let { getNodeText(it) } + val target = tree.findChildByType(node, MarkdownElementTypes.TARGET)?.let { tree.getNodeText(it) } ?: "" + val href = tree.findChildByType(node, MarkdownElementTypes.HREF)?.let { tree.getNodeText(it) } val link = if (href != null) ContentExternalLink(href) else ContentExternalLink(target) link.append(ContentText(target)) parent.append(link) @@ -76,7 +86,7 @@ public fun MarkdownTree.toContent(): Content { processChildren() } MarkdownElementTypes.PARA -> { - nodeStack.push(ContentBlock()) + nodeStack.push(ContentParagraph()) processChildren() parent.append(nodeStack.pop()) } @@ -89,3 +99,30 @@ public fun MarkdownTree.toContent(): Content { } +fun DocumentationBuilder.functionBody(descriptor: DeclarationDescriptor, functionName: String): ContentNode { + var scope = context.getResolutionScope(descriptor) + val parts = functionName.split('.') + var symbol: DeclarationDescriptor? = null + + for (part in parts) { + // short name + val symbolName = Name.guess(part) + val partSymbol = scope.getLocalVariable(symbolName) ?: + scope.getProperties(symbolName).firstOrNull() ?: + scope.getFunctions(symbolName).firstOrNull() ?: + scope.getClassifier(symbolName) ?: + scope.getPackage(symbolName) + + if (partSymbol == null) + break + scope = context.getResolutionScope(partSymbol) + symbol = partSymbol + } + + if (symbol != null) { + val psi = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) + + + } + return ContentCode().let() { it.append(ContentText("inline")); it } +}
\ No newline at end of file |