aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/model/defaultValues.kt8
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt8
-rw-r--r--plugins/base/src/test/kotlin/model/FunctionsTest.kt37
3 files changed, 25 insertions, 28 deletions
diff --git a/core/src/main/kotlin/model/defaultValues.kt b/core/src/main/kotlin/model/defaultValues.kt
index 63b69cbb..10f6d16d 100644
--- a/core/src/main/kotlin/model/defaultValues.kt
+++ b/core/src/main/kotlin/model/defaultValues.kt
@@ -5,13 +5,7 @@ import org.jetbrains.dokka.model.properties.MergeStrategy
import java.lang.IllegalStateException
class DefaultValue(val value: String): ExtraProperty<DParameter> {
- companion object : ExtraProperty.Key<DParameter, DefaultValue> {
- override fun mergeStrategyFor(left: DefaultValue, right: DefaultValue): MergeStrategy<DParameter> = if (left.value == right.value)
- MergeStrategy.Replace(left)
- else
- MergeStrategy.Fail {throw IllegalStateException("Default values need to be the same")}
-
- }
+ companion object : ExtraProperty.Key<DParameter, DefaultValue>
override val key: ExtraProperty.Key<DParameter, *>
get() = Companion
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index 6d834f9c..ae623ff2 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -19,7 +19,8 @@ import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies
import org.jetbrains.kotlin.idea.kdoc.findKDoc
-import org.jetbrains.kotlin.psi.KtConstantExpression
+import org.jetbrains.kotlin.psi.KtExpression
+import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.components.isVararg
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
@@ -531,9 +532,8 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv
)
}.let(::Annotations)
- fun ValueParameterDescriptor.getDefaultValue(): String? = (source as? KotlinSourceElement)?.let {
- it.psi.children.find { it is KtConstantExpression }?.text
- }
+ fun ValueParameterDescriptor.getDefaultValue(): String? =
+ (source as? KotlinSourceElement)?.psi?.children?.find { it is KtExpression }?.text
data class ClassInfo(val supertypes: List<DRI>, val docs: PlatformDependent<DocumentationNode>)
diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt
index 068c2895..e00e51fc 100644
--- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt
+++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt
@@ -315,7 +315,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
}
@Test
- fun functionWithDefaultParameter() {
+ fun functionWithDefaultStringParameter() {
inlineModelTest(
"""
|/src/main/kotlin/function/Test.kt
@@ -323,31 +323,34 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
|fun f(x: String = "") {}
"""
) {
- // TODO add default value data
-
with((this / "function" / "f").cast<DFunction>()) {
parameters.forEach { p ->
p.name equals "x"
p.type.name.assertNotNull("Parameter type: ") equals "String"
- assert(false) { "No default value data" }
+ p.extra[DefaultValue]?.value equals "\"\""
}
}
}
}
-// @Test fun functionWithDefaultParameter() {
-// checkSourceExistsAndVerifyModel("testdata/functions/functionWithDefaultParameter.kt", defaultModelConfig) { model ->
-// with(model.members.single().members.single()) {
-// with(details.elementAt(3)) {
-// val value = details(NodeKind.Value)
-// assertEquals(1, value.count())
-// with(value[0]) {
-// assertEquals("\"\"", name)
-// }
-// }
-// }
-// }
-// }
+ @Test
+ fun functionWithDefaultFloatParameter() {
+ inlineModelTest(
+ """
+ |/src/main/kotlin/function/Test.kt
+ |package function
+ |fun f(x: Float = 3.14f) {}
+ """
+ ) {
+ with((this / "function" / "f").cast<DFunction>()) {
+ parameters.forEach { p ->
+ p.name equals "x"
+ p.type.name.assertNotNull("Parameter type: ") equals "Float"
+ p.extra[DefaultValue]?.value equals "3.14f"
+ }
+ }
+ }
+ }
@Test
fun sinceKotlin() {