added type parameter support
This commit is contained in:
+27
-10
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.model.KClass
|
|||||||
import org.jetbrains.kotlin.model.KFunction
|
import org.jetbrains.kotlin.model.KFunction
|
||||||
import org.jetbrains.kotlin.model.KAnnotation
|
import org.jetbrains.kotlin.model.KAnnotation
|
||||||
import org.jetbrains.kotlin.model.KProperty
|
import org.jetbrains.kotlin.model.KProperty
|
||||||
|
import org.jetbrains.kotlin.model.KTypeParameter
|
||||||
|
|
||||||
|
|
||||||
abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
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 {
|
fun printFunctionSummary(function: KFunction): Unit {
|
||||||
val deprecated = if (method.deprecated) "<B>Deprecated.</B>" else ""
|
val deprecated = if (function.deprecated) "<B>Deprecated.</B>" else ""
|
||||||
print("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
print("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||||
<CODE>""")
|
<CODE>""")
|
||||||
if (!method.typeParameters.isEmpty()) {
|
if (!function.typeParameters.isEmpty()) {
|
||||||
println("""<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
|
println("""<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
|
||||||
<TR ALIGN="right" VALIGN="">
|
<TR ALIGN="right" VALIGN="">
|
||||||
<TD NOWRAP><FONT SIZE="-1">
|
<TD NOWRAP><FONT SIZE="-1">
|
||||||
<CODE>""")
|
<CODE>""")
|
||||||
printTypeParameters(method)
|
printTypeParameters(function)
|
||||||
println("""<BR>""")
|
println("""<BR>""")
|
||||||
print(link(method.returnType))
|
print(link(function.returnType))
|
||||||
|
printTypeParameterNames(function.returnType.typeParameters)
|
||||||
println("""</CODE></FONT></TD>
|
println("""</CODE></FONT></TD>
|
||||||
</TR>
|
</TR>
|
||||||
</TABLE>""")
|
</TABLE>""")
|
||||||
} else {
|
} else {
|
||||||
print(link(method.returnType))
|
print(link(function.returnType))
|
||||||
}
|
}
|
||||||
println("""</CODE></FONT></TD>""")
|
println("""</CODE></FONT></TD>""")
|
||||||
print("""<TD><CODE><B><A HREF="${href(method)}">${method.name}</A></B>""")
|
print("""<TD><CODE><B><A HREF="${href(function)}">${function.name}</A></B>""")
|
||||||
printParameters(method)
|
printParameters(function)
|
||||||
println("""</CODE>""")
|
println("""</CODE>""")
|
||||||
println("""""")
|
println("""""")
|
||||||
println("""<BR>""")
|
println("""<BR>""")
|
||||||
println(""" ${deprecated} ${method.detailedDescription}</TD>""")
|
println(""" ${deprecated} ${function.detailedDescription}</TD>""")
|
||||||
println("""</TR>""")
|
println("""</TR>""")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +101,8 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
|||||||
|
|
||||||
printTypeParameters(function)
|
printTypeParameters(function)
|
||||||
print(link(function.returnType))
|
print(link(function.returnType))
|
||||||
|
printTypeParameterNames(function.returnType.typeParameters)
|
||||||
|
|
||||||
print(""" <A HREF="${sourceHref(function)}"><B>${function.name}</B></A>""")
|
print(""" <A HREF="${sourceHref(function)}"><B>${function.name}</B></A>""")
|
||||||
printParameters(function)
|
printParameters(function)
|
||||||
val exlist = function.exceptions
|
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(", ")
|
if (first) first = false else print(", ")
|
||||||
print("${p.name}: ")
|
print("${p.name}: ")
|
||||||
print(link(p.klass))
|
print(link(p.klass))
|
||||||
|
printTypeParameterNames(method.typeParameters)
|
||||||
}
|
}
|
||||||
print(")")
|
print(")")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun printTypeParameterNames(typeParameters: List<KTypeParameter>): Unit {
|
||||||
|
if (!typeParameters.isEmpty()) {
|
||||||
|
print("<")
|
||||||
|
var separator = ""
|
||||||
|
for (t in typeParameters) {
|
||||||
|
print(separator)
|
||||||
|
separator = ", "
|
||||||
|
print(t.name)
|
||||||
|
}
|
||||||
|
print(">")
|
||||||
|
}
|
||||||
|
}
|
||||||
fun printAnnotations(annotations: Collection<KAnnotation>): Unit {
|
fun printAnnotations(annotations: Collection<KAnnotation>): Unit {
|
||||||
for (a in annotations) {
|
for (a in annotations) {
|
||||||
println(link(a))
|
println(link(a))
|
||||||
|
|||||||
@@ -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.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.jet.lang.psi.JetFile
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
|
||||||
|
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
|
||||||
|
|
||||||
fun containerName(descriptor: DeclarationDescriptor): String = qualifiedName(descriptor.containingDeclaration)
|
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())
|
val returnType = getClass(descriptor.getReturnType())
|
||||||
if (returnType != null) {
|
if (returnType != null) {
|
||||||
val function = KFunction(owner, descriptor.getName() ?: "null", returnType)
|
val function = KFunction(owner, descriptor.getName() ?: "null", returnType)
|
||||||
|
addTypeParameters(function.typeParameters, descriptor.getTypeParameters())
|
||||||
function.description = commentsFor(descriptor)
|
function.description = commentsFor(descriptor)
|
||||||
val params = descriptor.getValueParameters()
|
val params = descriptor.getValueParameters()
|
||||||
for (param in params) {
|
for (param in params) {
|
||||||
@@ -231,6 +233,24 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun addTypeParameters(answer: List<KTypeParameter>, descriptors: List<TypeParameterDescriptor?>): 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? {
|
protected fun createParameter(descriptor: ValueParameterDescriptor): KParameter? {
|
||||||
val returnType = getClass(descriptor.getReturnType())
|
val returnType = getClass(descriptor.getReturnType())
|
||||||
if (returnType != null) {
|
if (returnType != null) {
|
||||||
@@ -322,23 +342,25 @@ class KPackage(val model: KModel, val descriptor: NamespaceDescriptor,
|
|||||||
|
|
||||||
fun toString() = "KPackage($name)"
|
fun toString() = "KPackage($name)"
|
||||||
|
|
||||||
fun getClass(name: String, classElement: ClassDescriptor): KClass {
|
fun getClass(name: String, descriptor: ClassDescriptor): KClass {
|
||||||
var created = false
|
var created = false
|
||||||
val klass = classMap.getOrPut(name) {
|
val klass = classMap.getOrPut(name) {
|
||||||
created = true
|
created = true
|
||||||
KClass(this, classElement, name)
|
KClass(this, descriptor, name)
|
||||||
}
|
}
|
||||||
if (created) {
|
if (created) {
|
||||||
local = true
|
local = true
|
||||||
klass.description = model.commentsFor(classElement)
|
klass.description = model.commentsFor(descriptor)
|
||||||
val superTypes = classElement.getTypeConstructor().getSupertypes()
|
val typeConstructor = descriptor.getTypeConstructor()
|
||||||
|
val superTypes = typeConstructor.getSupertypes()
|
||||||
for (st in superTypes) {
|
for (st in superTypes) {
|
||||||
val sc = model.getClass(st)
|
val sc = model.getClass(st)
|
||||||
if (sc != null) {
|
if (sc != null) {
|
||||||
klass.baseClasses.add(sc)
|
klass.baseClasses.add(sc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
model.addFunctions(klass, classElement.getDefaultType().getMemberScope())
|
model.addFunctions(klass, descriptor.getDefaultType().getMemberScope())
|
||||||
|
model.addTypeParameters(klass.typeParameters, typeConstructor.getParameters())
|
||||||
}
|
}
|
||||||
return klass
|
return klass
|
||||||
}
|
}
|
||||||
@@ -404,6 +426,7 @@ class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
|
|||||||
val simpleName: String,
|
val simpleName: String,
|
||||||
var kind: String = "class", var group: String = "Other",
|
var kind: String = "class", var group: String = "Other",
|
||||||
var annotations: List<KAnnotation> = arrayList<KAnnotation>(),
|
var annotations: List<KAnnotation> = arrayList<KAnnotation>(),
|
||||||
|
var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>(),
|
||||||
var since: String = "",
|
var since: String = "",
|
||||||
var authors: List<String> = arrayList<String>(),
|
var authors: List<String> = arrayList<String>(),
|
||||||
var baseClasses: List<KClass> = arrayList<KClass>(),
|
var baseClasses: List<KClass> = arrayList<KClass>(),
|
||||||
@@ -477,7 +500,7 @@ class KFunction(val owner: KClassOrPackage, val name: String,
|
|||||||
public val parameterTypeText: String
|
public val parameterTypeText: String
|
||||||
get() {
|
get() {
|
||||||
if (_parameterTypeText == null) {
|
if (_parameterTypeText == null) {
|
||||||
_parameterTypeText = typeParameters.map{ it.klass.name }.join(", ")
|
_parameterTypeText = typeParameters.map{ it.name }.join(", ")
|
||||||
}
|
}
|
||||||
return _parameterTypeText.sure()
|
return _parameterTypeText.sure()
|
||||||
}
|
}
|
||||||
@@ -502,12 +525,10 @@ class KParameter(val name: String,
|
|||||||
}
|
}
|
||||||
|
|
||||||
class KTypeParameter(val name: String,
|
class KTypeParameter(val name: String,
|
||||||
var klass: KClass,
|
val descriptor: TypeParameterDescriptor,
|
||||||
var extends: List<KClass> = arrayList<KClass>()) {
|
var extends: List<KClass> = arrayList<KClass>()) : KAnnotated() {
|
||||||
|
|
||||||
fun toString() = if (extends.isEmpty()) name else {
|
fun toString() = "$name"
|
||||||
"$name extends ${extends.map{it.name}.join(" & ")}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class KAnnotation(var klass: KClass) : KAnnotated() {
|
class KAnnotation(var klass: KClass) : KAnnotated() {
|
||||||
|
|||||||
Reference in New Issue
Block a user