aboutsummaryrefslogtreecommitdiff
path: root/src/Kotlin
diff options
context:
space:
mode:
authorDmitry Jemerov <intelliyole@gmail.com>2014-12-30 16:34:47 +0100
committerDmitry Jemerov <intelliyole@gmail.com>2014-12-30 16:34:47 +0100
commit5f47bc17630ef1457b36054dc8b19011d9d14132 (patch)
tree876215d35aa29f49d25645ad92edfe190f3364e6 /src/Kotlin
parent7db96f8da4317cd290ccc9f988c534f10923dbbb (diff)
parent3fc3e33a0eff0198ed89cc94197cb21653bf1ca2 (diff)
downloaddokka-5f47bc17630ef1457b36054dc8b19011d9d14132.tar.gz
dokka-5f47bc17630ef1457b36054dc8b19011d9d14132.tar.bz2
dokka-5f47bc17630ef1457b36054dc8b19011d9d14132.zip
Merge pull request #8 from orangy/class-object
Include class object properties and functions in the list of class members
Diffstat (limited to 'src/Kotlin')
-rw-r--r--src/Kotlin/ContentBuilder.kt19
-rw-r--r--src/Kotlin/DocumentationBuilder.kt15
-rw-r--r--src/Kotlin/KotlinLanguageService.kt12
3 files changed, 36 insertions, 10 deletions
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt
index 0c82a522..0143feed 100644
--- a/src/Kotlin/ContentBuilder.kt
+++ b/src/Kotlin/ContentBuilder.kt
@@ -101,6 +101,17 @@ public fun DocumentationBuilder.buildContent(tree: MarkdownNode, descriptor: Dec
processChildren()
parent.append(nodeStack.pop())
}
+ MarkdownTokenTypes.COLON -> {
+ // TODO fix markdown parser
+ if (!isColonAfterSectionLabel(node)) {
+ parent.append(ContentText(node.text))
+ }
+ }
+ MarkdownTokenTypes.DOUBLE_QUOTE,
+ MarkdownTokenTypes.LT,
+ MarkdownTokenTypes.GT -> {
+ parent.append(ContentText(node.text))
+ }
else -> {
processChildren()
}
@@ -147,4 +158,10 @@ private fun DocumentationBuilder.resolveInScope(functionName: String, scope: Jet
}
return symbol
-} \ No newline at end of file
+}
+
+private fun isColonAfterSectionLabel(node: MarkdownNode): Boolean {
+ val parent = node.parent
+ return parent != null && parent.type == MarkdownElementTypes.SECTION && parent.children.size() >= 2 &&
+ node == parent.children[1];
+}
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index d2c07200..aeea4a55 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -161,11 +161,13 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
if (getKind() != ClassKind.OBJECT) {
node.appendChildren(getTypeConstructor().getParameters(), DocumentationReference.Kind.Detail)
node.appendChildren(getConstructors(), DocumentationReference.Kind.Member)
- val classObjectDescriptor = getClassObjectDescriptor()
- if (classObjectDescriptor != null)
- node.appendChild(classObjectDescriptor, DocumentationReference.Kind.Member)
}
node.appendChildren(getDefaultType().getMemberScope().getAllDescriptors(), DocumentationReference.Kind.Member)
+ val classObjectDescriptor = getClassObjectDescriptor()
+ if (classObjectDescriptor != null) {
+ node.appendChildren(classObjectDescriptor.getDefaultType().getMemberScope().getAllDescriptors(),
+ DocumentationReference.Kind.Member)
+ }
register(this, node)
return node
}
@@ -177,8 +179,11 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
return node
}
+ private fun DeclarationDescriptor.inClassObject() =
+ getContainingDeclaration().let { it is ClassDescriptor && it.getKind() == ClassKind.CLASS_OBJECT }
+
fun FunctionDescriptor.build(): DocumentationNode {
- val node = DocumentationNode(this, Kind.Function)
+ val node = DocumentationNode(this, if (inClassObject()) Kind.ClassObjectFunction else Kind.Function)
node.appendChildren(getTypeParameters(), DocumentationReference.Kind.Detail)
getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) }
@@ -201,7 +206,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati
}
fun PropertyDescriptor.build(): DocumentationNode {
- val node = DocumentationNode(this, Kind.Property)
+ val node = DocumentationNode(this, if (inClassObject()) Kind.ClassObjectProperty else Kind.Property)
node.appendChildren(getTypeParameters(), DocumentationReference.Kind.Detail)
getExtensionReceiverParameter()?.let { node.appendChild(it, DocumentationReference.Kind.Detail) }
node.appendType(getReturnType())
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt
index c9275879..a4016849 100644
--- a/src/Kotlin/KotlinLanguageService.kt
+++ b/src/Kotlin/KotlinLanguageService.kt
@@ -31,8 +31,10 @@ class KotlinLanguageService : LanguageService {
DocumentationNode.Kind.Modifier -> renderModifier(node)
DocumentationNode.Kind.Constructor,
- DocumentationNode.Kind.Function -> renderFunction(node)
- DocumentationNode.Kind.Property -> renderProperty(node)
+ DocumentationNode.Kind.Function,
+ DocumentationNode.Kind.ClassObjectFunction -> renderFunction(node)
+ DocumentationNode.Kind.Property,
+ DocumentationNode.Kind.ClassObjectProperty -> renderProperty(node)
else -> ContentText("${node.kind}: ${node.name}")
}
}
@@ -189,7 +191,8 @@ class KotlinLanguageService : LanguageService {
renderModifiersForNode(node)
when (node.kind) {
DocumentationNode.Kind.Constructor -> identifier(node.owner!!.name)
- DocumentationNode.Kind.Function -> keyword("fun ")
+ DocumentationNode.Kind.Function,
+ DocumentationNode.Kind.ClassObjectFunction -> keyword("fun ")
else -> throw IllegalArgumentException("Node $node is not a function-like object")
}
renderTypeParametersForNode(node)
@@ -216,7 +219,8 @@ class KotlinLanguageService : LanguageService {
private fun ContentNode.renderProperty(node: DocumentationNode) {
renderModifiersForNode(node)
when (node.kind) {
- DocumentationNode.Kind.Property -> keyword("val ")
+ DocumentationNode.Kind.Property,
+ DocumentationNode.Kind.ClassObjectProperty -> keyword("val ")
else -> throw IllegalArgumentException("Node $node is not a property")
}
renderTypeParametersForNode(node)