diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt
index 34d096890c8..ef19d6a32b7 100644
--- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt
+++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.model.KClass
import org.jetbrains.kotlin.model.KFunction
import org.jetbrains.kotlin.model.KAnnotation
import org.jetbrains.kotlin.model.KProperty
+import org.jetbrains.kotlin.model.KTypeParameter
abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
@@ -39,32 +40,33 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
}
}
- fun printFunctionSummary(method: KFunction): Unit {
- val deprecated = if (method.deprecated) "Deprecated." else ""
+ fun printFunctionSummary(function: KFunction): Unit {
+ val deprecated = if (function.deprecated) "Deprecated." else ""
print("""
""")
- if (!method.typeParameters.isEmpty()) {
+ if (!function.typeParameters.isEmpty()) {
println("""
""")
- printTypeParameters(method)
+ printTypeParameters(function)
println(""" """)
- print(link(method.returnType))
+ print(link(function.returnType))
+ printTypeParameterNames(function.returnType.typeParameters)
println(""" |
""")
} else {
- print(link(method.returnType))
+ print(link(function.returnType))
}
println(""" | """)
- print("""${method.name}""")
- printParameters(method)
+ print("""${function.name}""")
+ printParameters(function)
println("""""")
println("""""")
println(""" """)
- println(""" ${deprecated} ${method.detailedDescription} | """)
+ println(""" ${deprecated} ${function.detailedDescription} | """)
println("""
""")
}
@@ -99,6 +101,8 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
printTypeParameters(function)
print(link(function.returnType))
+ printTypeParameterNames(function.returnType.typeParameters)
+
print(""" ${function.name}""")
printParameters(function)
val exlist = function.exceptions
@@ -204,7 +208,7 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
}
}
}
- print(">")
+ print("> ")
}
}
@@ -215,10 +219,23 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
if (first) first = false else print(", ")
print("${p.name}: ")
print(link(p.klass))
+ printTypeParameterNames(method.typeParameters)
}
print(")")
}
+ fun printTypeParameterNames(typeParameters: List): Unit {
+ if (!typeParameters.isEmpty()) {
+ print("<")
+ var separator = ""
+ for (t in typeParameters) {
+ print(separator)
+ separator = ", "
+ print(t.name)
+ }
+ print(">")
+ }
+ }
fun printAnnotations(annotations: Collection): Unit {
for (a in annotations) {
println(link(a))
diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt
index 82f75520ab0..603e097218d 100644
--- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt
+++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt
@@ -20,6 +20,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
import org.jetbrains.jet.lang.psi.JetFile
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
+import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
fun containerName(descriptor: DeclarationDescriptor): String = qualifiedName(descriptor.containingDeclaration)
@@ -212,6 +213,7 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
val returnType = getClass(descriptor.getReturnType())
if (returnType != null) {
val function = KFunction(owner, descriptor.getName() ?: "null", returnType)
+ addTypeParameters(function.typeParameters, descriptor.getTypeParameters())
function.description = commentsFor(descriptor)
val params = descriptor.getValueParameters()
for (param in params) {
@@ -231,6 +233,24 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
return null
}
+ protected fun addTypeParameters(answer: List, descriptors: List): Unit {
+ for (typeParam in descriptors) {
+ if (typeParam != null) {
+ val p = createTypeParameter(typeParam)
+ if (p != null){
+ answer.add(p)
+ }
+ }
+ }
+ }
+
+ protected fun createTypeParameter(descriptor: TypeParameterDescriptor): KTypeParameter? {
+ val name = descriptor.getName()
+ val answer = KTypeParameter(name, descriptor)
+ answer.description = commentsFor(descriptor)
+ return answer
+ }
+
protected fun createParameter(descriptor: ValueParameterDescriptor): KParameter? {
val returnType = getClass(descriptor.getReturnType())
if (returnType != null) {
@@ -322,23 +342,25 @@ class KPackage(val model: KModel, val descriptor: NamespaceDescriptor,
fun toString() = "KPackage($name)"
- fun getClass(name: String, classElement: ClassDescriptor): KClass {
+ fun getClass(name: String, descriptor: ClassDescriptor): KClass {
var created = false
val klass = classMap.getOrPut(name) {
created = true
- KClass(this, classElement, name)
+ KClass(this, descriptor, name)
}
if (created) {
local = true
- klass.description = model.commentsFor(classElement)
- val superTypes = classElement.getTypeConstructor().getSupertypes()
+ klass.description = model.commentsFor(descriptor)
+ val typeConstructor = descriptor.getTypeConstructor()
+ val superTypes = typeConstructor.getSupertypes()
for (st in superTypes) {
val sc = model.getClass(st)
if (sc != null) {
klass.baseClasses.add(sc)
}
}
- model.addFunctions(klass, classElement.getDefaultType().getMemberScope())
+ model.addFunctions(klass, descriptor.getDefaultType().getMemberScope())
+ model.addTypeParameters(klass.typeParameters, typeConstructor.getParameters())
}
return klass
}
@@ -404,6 +426,7 @@ class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
val simpleName: String,
var kind: String = "class", var group: String = "Other",
var annotations: List = arrayList(),
+ var typeParameters: List = arrayList(),
var since: String = "",
var authors: List = arrayList(),
var baseClasses: List = arrayList(),
@@ -477,7 +500,7 @@ class KFunction(val owner: KClassOrPackage, val name: String,
public val parameterTypeText: String
get() {
if (_parameterTypeText == null) {
- _parameterTypeText = typeParameters.map{ it.klass.name }.join(", ")
+ _parameterTypeText = typeParameters.map{ it.name }.join(", ")
}
return _parameterTypeText.sure()
}
@@ -502,12 +525,10 @@ class KParameter(val name: String,
}
class KTypeParameter(val name: String,
- var klass: KClass,
- var extends: List = arrayList()) {
+ val descriptor: TypeParameterDescriptor,
+ var extends: List = arrayList()) : KAnnotated() {
- fun toString() = if (extends.isEmpty()) name else {
- "$name extends ${extends.map{it.name}.join(" & ")}"
- }
+ fun toString() = "$name"
}
class KAnnotation(var klass: KClass) : KAnnotated() {