From f2ffd4116edd2aa2a1c79848881b3581a07ab727 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Thu, 1 Mar 2012 12:10:16 +0000 Subject: [PATCH] fixes KT-1467 to use nicer syntax for tuples and functions --- .../kotlin/doc/templates/KDocTemplate.kt | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt index 714ed6d630c..ddbebeb99dd 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/KDocTemplate.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.model.KFunction import java.util.Collection import org.jetbrains.kotlin.model.KProperty import org.jetbrains.kotlin.model.KType +import java.util.List abstract class KDocTemplate() : TextTemplate() { open fun rootHref(pkg: KPackage): String { @@ -62,7 +63,6 @@ abstract class KDocTemplate() : TextTemplate() { } open fun link(c: KClass, fullName: Boolean = false): String { - // TODO if a class is a generic type parameter, just return the name... val prefix = if (c.isAnnotation()) "@" else "" val name = if (fullName) c.name else c.simpleName return "$prefix$name" @@ -70,18 +70,32 @@ abstract class KDocTemplate() : TextTemplate() { open fun link(t: KType, fullName: Boolean = false): String { val c = t.klass + val arguments = t.arguments return if (c != null) { val prefix = if (c.isAnnotation()) "@" else "" - val name = if (fullName) c.name else c.simpleName - "$prefix$name${typeArguments(t)}" + if (c.name.startsWith("jet.Function") && arguments.notEmpty()) { + val rt = arguments.last() + // TODO use drop() + val rest = arguments.subList(0, arguments.size - 1).notNull() + "${typeArguments(rest, "(", ")")} -> ${link(rt)}" + } else if (c.name.startsWith("jet.Tuple")) { + if (arguments.isEmpty()) { + "Unit" + } else { + "#${typeArguments(arguments, "(", ")")}" + } + } else { + val name = if (fullName) c.name else c.simpleName + "$prefix$name${typeArguments(arguments)}" + } } else { - "${t.name}${typeArguments(t)}" + "${t.name}${typeArguments(arguments)}" } } - open fun typeArguments(t: KType): String { - val text = t.arguments.map() { link(it) }.join(", ") - return if (text.length() == 0) "" else "<$text>" + open fun typeArguments(arguments: List, val prefix: String = "<", val postfix: String = ">"): String { + val text = arguments.map() { link(it) }.join(", ") + return if (text.length() == 0) "" else "$prefix$text$postfix" } open fun link(p: KPackage): String {