updated kdoc so it highlights parameters with default values and varargs
This commit is contained in:
@@ -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,
|
||||
|
||||
Vendored
+3
-1
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
+19
-1
@@ -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(")")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user