diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-01-14 19:38:58 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-01-14 19:38:58 +0100 |
commit | f36d9b0e4f336de7e35dcfa33934ab287b76d964 (patch) | |
tree | 9beb706729788f4126f1270c4abfe3e0bcb71481 | |
parent | 60e610ebdd86663bedf113d2235ac3c8364171d0 (diff) | |
download | dokka-f36d9b0e4f336de7e35dcfa33934ab287b76d964.tar.gz dokka-f36d9b0e4f336de7e35dcfa33934ab287b76d964.tar.bz2 dokka-f36d9b0e4f336de7e35dcfa33934ab287b76d964.zip |
show default values of parameters in generated documentation
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 11 | ||||
-rw-r--r-- | src/Kotlin/KotlinLanguageService.kt | 5 | ||||
-rw-r--r-- | test/data/format/functionWithDefaultParameter.kt | 1 | ||||
-rw-r--r-- | test/data/format/functionWithDefaultParameter.md | 12 | ||||
-rw-r--r-- | test/data/functions/functionWithDefaultParameter.kt | 1 | ||||
-rw-r--r-- | test/src/format/MarkdownFormatTest.kt | 6 | ||||
-rw-r--r-- | test/src/model/FunctionTest.kt | 14 |
7 files changed, 50 insertions, 0 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 0b978370..5af4c9f1 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -12,6 +12,8 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor +import org.jetbrains.kotlin.resolve.source.getPsi +import org.jetbrains.kotlin.psi.JetParameter public data class DocumentationOptions(val includeNonPublic: Boolean = false) @@ -307,6 +309,15 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati } else { node.appendType(getType()) } + if (hasDefaultValue()) { + val psi = getSource().getPsi() as? JetParameter + if (psi != null) { + val defaultValueText = psi.getDefaultValue()?.getText() + if (defaultValueText != null) { + node.append(DocumentationNode(defaultValueText, Content.Empty, Kind.Value), DocumentationReference.Kind.Detail) + } + } + } node.appendAnnotations(this) register(this, node) return node diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index 8795aba6..3e9192c4 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -133,6 +133,11 @@ class KotlinLanguageService : LanguageService { symbol(": ") val parameterType = node.detail(DocumentationNode.Kind.Type) renderType(parameterType) + val valueNode = node.details(DocumentationNode.Kind.Value).firstOrNull() + if (valueNode != null) { + symbol(" = ") + text(valueNode.name) + } } private fun ContentNode.renderTypeParametersForNode(node: DocumentationNode) { diff --git a/test/data/format/functionWithDefaultParameter.kt b/test/data/format/functionWithDefaultParameter.kt new file mode 100644 index 00000000..3a3a102f --- /dev/null +++ b/test/data/format/functionWithDefaultParameter.kt @@ -0,0 +1 @@ +fun f(x: String = "") {} diff --git a/test/data/format/functionWithDefaultParameter.md b/test/data/format/functionWithDefaultParameter.md new file mode 100644 index 00000000..1acab0ef --- /dev/null +++ b/test/data/format/functionWithDefaultParameter.md @@ -0,0 +1,12 @@ +[test](out.md) / [](out.md) / [f](out.md) + + +# f + + +``` +fun f(x: String = ""): Unit +``` + + + diff --git a/test/data/functions/functionWithDefaultParameter.kt b/test/data/functions/functionWithDefaultParameter.kt new file mode 100644 index 00000000..3a3a102f --- /dev/null +++ b/test/data/functions/functionWithDefaultParameter.kt @@ -0,0 +1 @@ +fun f(x: String = "") {} diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index 580acd7c..65713891 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -69,4 +69,10 @@ public class MarkdownFormatTest { } } + + Test fun functionWithDefaultParameter() { + verifyOutput("test/data/format/functionWithDefaultParameter.kt", ".md") { model, output -> + markdownService.appendNodes(tempLocation, output, model.members.single().members) + } + } } diff --git a/test/src/model/FunctionTest.kt b/test/src/model/FunctionTest.kt index 299f33a8..c648cb55 100644 --- a/test/src/model/FunctionTest.kt +++ b/test/src/model/FunctionTest.kt @@ -194,4 +194,18 @@ Documentation""", content.description.toTestString()) } } } + + Test fun functionWithDefaultParameter() { + verifyModel("test/data/functions/functionWithDefaultParameter.kt") { model -> + with(model.members.single().members.single()) { + with(details.elementAt(2)) { + val value = details(DocumentationNode.Kind.Value) + assertEquals(1, value.count()) + with(value[0]) { + assertEquals("\"\"", name) + } + } + } + } + } } |