diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-01-14 20:30:54 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-01-14 20:30:54 +0100 |
commit | 807451f9ad9664e7b26cc50c4f08a2a9bf3be538 (patch) | |
tree | 08f6e458ae15aa5796a53d4629b2ff5c16f783c9 | |
parent | 77c1f53cab3c2b143a3dafaf6c7bef49df5bcdb9 (diff) | |
parent | f36d9b0e4f336de7e35dcfa33934ab287b76d964 (diff) | |
download | dokka-807451f9ad9664e7b26cc50c4f08a2a9bf3be538.tar.gz dokka-807451f9ad9664e7b26cc50c4f08a2a9bf3be538.tar.bz2 dokka-807451f9ad9664e7b26cc50c4f08a2a9bf3be538.zip |
Merge branch 'defaut-param-values'
Conflicts:
src/Kotlin/DocumentationBuilder.kt
test/src/format/MarkdownFormatTest.kt
-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 1e09e110..6403f14c 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -17,6 +17,8 @@ import java.io.File import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiNameIdentifierOwner import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.resolve.source.getPsi +import org.jetbrains.kotlin.psi.JetParameter public data class DocumentationOptions(val includeNonPublic: Boolean = false, val sourceLinks: List<SourceLinkDefinition>) @@ -351,6 +353,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 c273ff3d..80a76791 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 293b9cb2..5a4bacb2 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -75,4 +75,10 @@ public class MarkdownFormatTest { markdownService.appendNodes(tempLocation, output, model.members.single().members) } } + + 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) + } + } + } + } + } } |