diff --git a/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt b/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt index ee8bc7cfe33..78b1bb7fa63 100644 --- a/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt +++ b/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt @@ -323,7 +323,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) { val returnType = getType(descriptor.getReturnType()) if (returnType != null) { val name = descriptor.getName() - val answer = KParameter(name, returnType) + val answer = KParameter(descriptor, name, returnType) configureComments(answer, descriptor) return answer } @@ -833,10 +833,21 @@ class KProperty(val owner: KClassOrPackage, val descriptor: PropertyDescriptor, fun toString() = "property $name" } -class KParameter(val name: String, +class KParameter(val descriptor: ValueParameterDescriptor, val name: String, var aType: KType): KAnnotated(aType.model, aType.declarationDescriptor) { fun toString() = "$name: ${aType.name}" + + fun isVarArg(): Boolean = descriptor.getVarargElementType() != null + + fun hasDefaultValue(): Boolean = descriptor.hasDefaultValue() + + fun varArgType(): KType? { + val varType = descriptor.getVarargElementType() + return if (varType != null) { + aType.model.getType(varType) + } else null + } } class KTypeParameter(val name: String, diff --git a/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt b/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt index 0bdd0300179..bd4892a05c3 100644 --- a/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt +++ b/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt @@ -43,6 +43,8 @@ from package ${link(pkg)} """) } - override fun href(f: KFunction): String = if (f.extensionClass == klass) "#${f.link}" else super.href(f) + override fun href(f: KFunction): String { + return if (f.extensionClass != null) "#${f.link}" else super.href(f) + } } diff --git a/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt b/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt index 72f817c0559..7cabfd533cc 100644 --- a/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt +++ b/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt @@ -219,10 +219,28 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() { fun printParameters(method: KFunction): Unit { print("(") var first = true + var defaultValue = false for (p in method.parameters) { + if (!p.hasDefaultValue() && defaultValue) { + print("]") + defaultValue = false + } if (first) first = false else print(", ") + if (p.hasDefaultValue() && !defaultValue) { + print(" [") + defaultValue = true + } + val pType = if (p.isVarArg()) { + print("vararg ") + p.varArgType().sure() + } else { + p.aType + } print("${p.name}: ") - print(link(p.aType)) + print(link(pType)) + } + if (defaultValue) { + print("]") } print(")") }