aboutsummaryrefslogtreecommitdiff
path: root/src/Kotlin
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-12-16 21:41:32 +0300
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-12-16 21:41:32 +0300
commitbd6cddd932c308519ce386197b93de145462bec2 (patch)
tree5cb04a2cd8f7dfd7e1c679f16977a51d5d966faa /src/Kotlin
parent9535260e7b9f1483fbbfcf0abf4c171311fd92b7 (diff)
downloaddokka-bd6cddd932c308519ce386197b93de145462bec2.tar.gz
dokka-bd6cddd932c308519ce386197b93de145462bec2.tar.bz2
dokka-bd6cddd932c308519ce386197b93de145462bec2.zip
Process short links.
Diffstat (limited to 'src/Kotlin')
-rw-r--r--src/Kotlin/ContentBuilder.kt64
-rw-r--r--src/Kotlin/DocumentationBuilder.kt52
2 files changed, 67 insertions, 49 deletions
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt
index 8079fb4c..462e886e 100644
--- a/src/Kotlin/ContentBuilder.kt
+++ b/src/Kotlin/ContentBuilder.kt
@@ -5,17 +5,16 @@ import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.jet.lang.resolve.*
import org.jetbrains.jet.lang.resolve.scopes.*
import org.jetbrains.jet.lang.resolve.name.*
-import net.nicoulaj.idea.markdown.lang.*
+import org.intellij.markdown.*
public fun DocumentationBuilder.buildContent(tree: MarkdownNode, descriptor: DeclarationDescriptor): Content {
+// println(tree.toTestString())
val nodeStack = ArrayDeque<ContentNode>()
nodeStack.push(Content())
tree.visit {(node, processChildren) ->
val parent = nodeStack.peek()!!
- val nodeType = node.type
- val nodeText = tree.text
- when (nodeType) {
+ when (node.type) {
MarkdownElementTypes.UNORDERED_LIST -> {
nodeStack.push(ContentList())
processChildren()
@@ -46,33 +45,40 @@ public fun DocumentationBuilder.buildContent(tree: MarkdownNode, descriptor: Dec
processChildren()
parent.append(nodeStack.pop())
}
- /* MarkdownElementTypes.ANONYMOUS_SECTION -> {
- nodeStack.push(ContentSection(""))
- 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 = tree.findChildByType(node, MarkdownElementTypes.SECTION_NAME)?.let { tree.getNodeText(it) } ?: ""
- nodeStack.push(ContentSection(label))
- processChildren()
- parent.append(nodeStack.pop())
- }*/
- MarkdownElementTypes.INLINE_LINK -> {
- val target = node.child(MarkdownElementTypes.LINK_TITLE)?.let { it.text } ?: ""
- val href = node.child(MarkdownElementTypes.LINK_DESTINATION)?.let { it.text }
- val link = if (href != null) ContentExternalLink(href) else ContentExternalLink(target)
- link.append(ContentText(target))
- parent.append(link)
+/*
+ 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.SECTION -> {
+ val label = node.child(MarkdownTokenTypes.SECTION_ID)?.let { it.text.trimLeading("$").trim("{","}") } ?: ""
+ nodeStack.push(ContentSection(label))
+ processChildren()
+ parent.append(nodeStack.pop())
+ }
+ MarkdownElementTypes.SHORT_REFERENCE_LINK -> {
+ val label = node.child(MarkdownElementTypes.LINK_LABEL)
+ val target = label?.child(MarkdownTokenTypes.TEXT)
+ if (target != null) {
+ val link = ContentExternalLink(target.text)
+ link.append(ContentText(target.text))
+ parent.append(link)
+ }
+ }
+ MarkdownTokenTypes.WHITE_SPACE,
+ MarkdownTokenTypes.EOL -> {
+ if (nodeStack.peek() is ContentParagraph && node.parent?.children?.last() != node) {
+ nodeStack.push(ContentText(node.text))
+ processChildren()
+ parent.append(nodeStack.pop())
+ }
}
MarkdownTokenTypes.TEXT -> {
- nodeStack.push(ContentText(nodeText))
+ nodeStack.push(ContentText(node.text))
processChildren()
parent.append(nodeStack.pop())
}
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index d8be9d5a..c2d28312 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -4,7 +4,6 @@ import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.dokka.DocumentationNode.*
import org.jetbrains.jet.lang.types.*
import org.jetbrains.jet.lang.types.lang.*
-import org.jetbrains.jet.lang.resolve.scopes.*
import org.jetbrains.jet.lang.resolve.name.*
import org.jetbrains.jet.lang.resolve.lazy.*
@@ -218,6 +217,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
fun ValueParameterDescriptor.build(): DocumentationNode {
val node = DocumentationNode(this, Kind.Parameter)
node.appendType(getType())
+ register(this, node)
return node
}
@@ -301,9 +301,9 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
}
}
- fun getResolutionScope(node: DocumentationNode): JetScope {
+ fun getResolutionScope(node: DocumentationNode): DeclarationDescriptor {
val descriptor = nodeToDescriptor[node] ?: throw IllegalArgumentException("Node is not known to this context")
- return getResolutionScope(descriptor)
+ return descriptor
}
fun resolveContentLinks(node: DocumentationNode, content: ContentNode) {
@@ -311,26 +311,38 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
for (child in snapshot) {
if (child is ContentExternalLink) {
val referenceText = child.href
- if (Name.isValidIdentifier(referenceText)) {
- val scope = getResolutionScope(node)
- val symbolName = Name.guess(referenceText)
- val symbol = scope.getLocalVariable(symbolName) ?:
- scope.getProperties(symbolName).firstOrNull() ?:
- scope.getFunctions(symbolName).firstOrNull() ?:
- scope.getClassifier(symbolName)
-
- if (symbol != null) {
- val targetNode = descriptorToNode[symbol]
- val contentLink = if (targetNode != null) ContentNodeLink(targetNode) else ContentExternalLink("#")
-
- val index = content.children.indexOf(child)
- content.children.remove(index)
- contentLink.children.addAll(child.children)
- content.children.add(index, contentLink)
- }
+ val symbol = resolveReference(getResolutionScope(node), referenceText)
+ if (symbol != null) {
+ val targetNode = descriptorToNode[symbol]
+ val contentLink = if (targetNode != null) ContentNodeLink(targetNode) else ContentExternalLink("#")
+
+ val index = content.children.indexOf(child)
+ content.children.remove(index)
+ contentLink.children.addAll(child.children)
+ content.children.add(index, contentLink)
}
+
}
resolveContentLinks(node, child)
}
}
+
+ private fun resolveReference(context: DeclarationDescriptor, reference: String): DeclarationDescriptor? {
+ if (Name.isValidIdentifier(reference)) {
+ val scope = getResolutionScope(context)
+ val symbolName = Name.guess(reference)
+ return scope.getLocalVariable(symbolName) ?:
+ scope.getProperties(symbolName).firstOrNull() ?:
+ scope.getFunctions(symbolName).firstOrNull() ?:
+ scope.getClassifier(symbolName)
+
+ }
+
+ val names = reference.split('.')
+ val result = names.fold<String, DeclarationDescriptor?>(context) {(nextContext, name) ->
+ nextContext?.let { resolveReference(it, name) }
+ }
+
+ return result
+ }
} \ No newline at end of file