From 3de1182033ca5a5db374e16a6ab3555627faa79b Mon Sep 17 00:00:00 2001 From: Szymon Świstun Date: Mon, 16 Mar 2020 13:08:29 +0100 Subject: Add default values for parameters --- .../DefaultDescriptorToDocumentableTranslator.kt | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 44679d8d..6d834f9c 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -19,16 +19,19 @@ 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.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.components.isVararg import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic -import org.jetbrains.kotlin.resolve.descriptorUtil.* +import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass +import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperclassesWithoutAny +import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny +import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.resolve.source.KotlinSourceElement import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjection -import org.jetbrains.dokka.model.Variance -import org.jetbrains.kotlin.idea.kdoc.findKDoc class DefaultDescriptorToDocumentableTranslator( private val context: DokkaContext @@ -367,7 +370,12 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv type = descriptor.type.toBound(), documentation = descriptor.resolveDescriptorData(platformData), platformData = listOf(platformData), - extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) + extra = PropertyContainer.withAll( + listOfNotNull( + descriptor.additionalExtras(), + descriptor.getAnnotations(), + descriptor.getDefaultValue()?.let { DefaultValue(it) }) + ) ) private fun MemberScope.functions(parent: DRIWithPlatformInfo): List = @@ -523,6 +531,10 @@ 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 + } + data class ClassInfo(val supertypes: List, val docs: PlatformDependent) private fun Visibility.toDokkaVisibility(): org.jetbrains.dokka.model.Visibility = when (this) { -- cgit