added summary of methods and extension functions to kdoc
This commit is contained in:
@@ -2,50 +2,32 @@ package org.jetbrains.kotlin.doc
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.doc.templates.*
|
import org.jetbrains.kotlin.doc.templates.*
|
||||||
import org.jetbrains.kotlin.template.TextTemplate
|
import org.jetbrains.kotlin.template.TextTemplate
|
||||||
import org.jetbrains.kotlin.model.KModel
|
import org.jetbrains.kotlin.model.*
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.List
|
||||||
|
import java.util.HashSet
|
||||||
|
import java.util.Collection
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||||
import org.jetbrains.jet.compiler.CompilerPlugin
|
import org.jetbrains.jet.compiler.CompilerPlugin
|
||||||
import java.util.List
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor
|
||||||
import java.util.HashSet
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.model.KMethod
|
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.jet.lang.types.JetType
|
import org.jetbrains.jet.lang.types.JetType
|
||||||
import org.jetbrains.kotlin.model.KClass
|
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor
|
import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.model.KParameter
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver
|
||||||
|
|
||||||
class KDoc(val outputDir: File) : KDocSupport() {
|
class KDoc(val outputDir: File) : KDocSupport() {
|
||||||
val model = KModel()
|
val model = KModel()
|
||||||
|
|
||||||
/** TODO compile errors so lets use Java for this bit for now...
|
|
||||||
override fun processFiles(context: BindingContext, files: List<JetFile?>?) {
|
|
||||||
println("==== KDoc running! Generating to $outputDir")
|
|
||||||
if (context != null) {
|
|
||||||
val namespaces = HashSet<NamespaceDescriptor>()
|
|
||||||
if (files != null) {
|
|
||||||
for (source in files) {
|
|
||||||
if (source != null) {
|
|
||||||
val namespaceDescriptor = context.get(BindingContext.NAMESPACE, source)
|
|
||||||
if (namespaceDescriptor != null) {
|
|
||||||
namespaces.add(namespaceDescriptor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
override fun addClass(namespace: NamespaceDescriptor?, classElement: ClassDescriptor?) {
|
override fun addClass(namespace: NamespaceDescriptor?, classElement: ClassDescriptor?) {
|
||||||
if (namespace != null && classElement != null) {
|
if (namespace != null && classElement != null) {
|
||||||
val klass = getOrCreateClass(classElement)
|
val klass = getOrCreateClass(classElement)
|
||||||
@@ -72,41 +54,64 @@ class KDoc(val outputDir: File) : KDocSupport() {
|
|||||||
val container = classElement.containingDeclaration
|
val container = classElement.containingDeclaration
|
||||||
val namespaceName = containerName(classElement)
|
val namespaceName = containerName(classElement)
|
||||||
val pkg = model.getPackage(namespaceName)
|
val pkg = model.getPackage(namespaceName)
|
||||||
|
pkg.initialise{
|
||||||
|
if (container is NamespaceDescriptor) {
|
||||||
|
addFunctions(pkg, pkg.functions, container.getMemberScope())
|
||||||
|
}
|
||||||
|
}
|
||||||
val name = classElement.getName()
|
val name = classElement.getName()
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
val klass = pkg.getClass(name)
|
val klass = pkg.getClass(name)
|
||||||
klass.initialise {
|
klass.initialise {
|
||||||
|
if (klass.pkg.description.length() == 0) {
|
||||||
|
klass.pkg.description = commentsFor(container)
|
||||||
|
}
|
||||||
klass.description = commentsFor(classElement)
|
klass.description = commentsFor(classElement)
|
||||||
val descriptors = classElement.getDefaultType().getMemberScope().getAllDescriptors()
|
val superTypes = classElement.getTypeConstructor().getSupertypes()
|
||||||
for (descriptor in descriptors) {
|
for (st in superTypes) {
|
||||||
if (descriptor is CallableDescriptor) {
|
val sc = getType(st)
|
||||||
val method = createMethod(descriptor)
|
if (sc != null) {
|
||||||
if (method != null) {
|
klass.baseClasses.add(sc)
|
||||||
klass.methods.add(method)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addFunctions(klass, klass.functions, classElement.getDefaultType().getMemberScope())
|
||||||
}
|
}
|
||||||
return klass
|
return klass
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun createMethod(descriptor: CallableDescriptor): KMethod? {
|
protected fun addFunctions(owner: KClassOrPackage, list: Collection<KFunction>, scope: JetScope): Unit {
|
||||||
|
val descriptors = scope.getAllDescriptors()
|
||||||
|
for (descriptor in descriptors) {
|
||||||
|
if (descriptor is CallableDescriptor) {
|
||||||
|
val function = createFunction(owner, descriptor)
|
||||||
|
if (function != null) {
|
||||||
|
list.add(function)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun createFunction(owner: KClassOrPackage, descriptor: CallableDescriptor): KFunction? {
|
||||||
val returnType = getType(descriptor.getReturnType())
|
val returnType = getType(descriptor.getReturnType())
|
||||||
if (returnType != null) {
|
if (returnType != null) {
|
||||||
val method = KMethod(descriptor.getName() ?: "null", returnType)
|
val function = KFunction(owner, descriptor.getName() ?: "null", returnType)
|
||||||
method.description = commentsFor(descriptor)
|
function.description = commentsFor(descriptor)
|
||||||
val params = descriptor.getValueParameters()
|
val params = descriptor.getValueParameters()
|
||||||
for (param in params) {
|
for (param in params) {
|
||||||
if (param != null) {
|
if (param != null) {
|
||||||
val p = createParameter(param)
|
val p = createParameter(param)
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
method.parameters.add(p)
|
function.parameters.add(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return method
|
val receiver = descriptor.getReceiverParameter()
|
||||||
|
if (receiver is ExtensionReceiver) {
|
||||||
|
function.extensionClass = getType(receiver.getType())
|
||||||
|
}
|
||||||
|
return function
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.*
|
|||||||
import org.jetbrains.kotlin.model.KModel
|
import org.jetbrains.kotlin.model.KModel
|
||||||
import org.jetbrains.kotlin.model.KPackage
|
import org.jetbrains.kotlin.model.KPackage
|
||||||
import org.jetbrains.kotlin.model.KClass
|
import org.jetbrains.kotlin.model.KClass
|
||||||
import org.jetbrains.kotlin.model.KMethod
|
import org.jetbrains.kotlin.model.KFunction
|
||||||
import org.jetbrains.kotlin.model.KAnnotation
|
import org.jetbrains.kotlin.model.KAnnotation
|
||||||
|
|
||||||
class ClassTemplate(val model: KModel, pkg: KPackage, val klass: KClass) : PackageTemplateSupport(pkg) {
|
class ClassTemplate(val model: KModel, pkg: KPackage, val klass: KClass) : PackageTemplateSupport(pkg) {
|
||||||
@@ -110,9 +110,7 @@ DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHO
|
|||||||
println("Class ${klass.simpleName}</H2>")
|
println("Class ${klass.simpleName}</H2>")
|
||||||
println("<PRE>")
|
println("<PRE>")
|
||||||
|
|
||||||
// TODO base class...
|
for (bc in klass.baseClasses) {
|
||||||
val bc = klass.baseClass
|
|
||||||
if (bc != null) {
|
|
||||||
println(link(bc, true))
|
println(link(bc, true))
|
||||||
}
|
}
|
||||||
println(" <IMG SRC=\"${pkg.nameAsRelativePath}resources/inherit.gif\" ALT=\"extended by \"><B>${klass.name}</B>")
|
println(" <IMG SRC=\"${pkg.nameAsRelativePath}resources/inherit.gif\" ALT=\"extended by \"><B>${klass.name}</B>")
|
||||||
@@ -122,9 +120,11 @@ DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHO
|
|||||||
print("<DT><PRE><FONT SIZE=\"-1\">")
|
print("<DT><PRE><FONT SIZE=\"-1\">")
|
||||||
printAnnotations(klass.annotations)
|
printAnnotations(klass.annotations)
|
||||||
print("</FONT>public class <A HREF=\"${pkg.nameAsRelativePath}src-html/${klass.nameAsPath}.html#line.${klass.sourceLine}\"><B>${klass.simpleName}</B></A><DT>")
|
print("</FONT>public class <A HREF=\"${pkg.nameAsRelativePath}src-html/${klass.nameAsPath}.html#line.${klass.sourceLine}\"><B>${klass.simpleName}</B></A><DT>")
|
||||||
if (bc != null) {
|
if (!klass.baseClasses.isEmpty()) {
|
||||||
print("extends ")
|
print("extends ")
|
||||||
println(link(bc))
|
for (bc in klass.baseClasses) {
|
||||||
|
println(link(bc))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
println("</DL>")
|
println("</DL>")
|
||||||
println("""</PRE>
|
println("""</PRE>
|
||||||
@@ -181,9 +181,7 @@ DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHO
|
|||||||
<B>Method Summary</B></FONT></TH>
|
<B>Method Summary</B></FONT></TH>
|
||||||
</TR>""")
|
</TR>""")
|
||||||
|
|
||||||
for (method in klass.methods) {
|
printFunctionSummary(klass.functions)
|
||||||
printMethodSummary(method)
|
|
||||||
}
|
|
||||||
|
|
||||||
println("""</TABLE>
|
println("""</TABLE>
|
||||||
|
|
||||||
@@ -199,9 +197,7 @@ DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHO
|
|||||||
</TR>
|
</TR>
|
||||||
</TABLE>
|
</TABLE>
|
||||||
""")
|
""")
|
||||||
for (method in klass.methods) {
|
printFunctionDetail(klass.functions)
|
||||||
printMethodDetail(method)
|
|
||||||
}
|
|
||||||
|
|
||||||
println("""<!-- ========= END OF CLASS DATA ========= -->
|
println("""<!-- ========= END OF CLASS DATA ========= -->
|
||||||
<HR>
|
<HR>
|
||||||
@@ -283,115 +279,4 @@ Copyright © 2010-2012. All Rights Reserved.
|
|||||||
println("""</FONT></TD>""")
|
println("""</FONT></TD>""")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun printMethodSummary(method: KMethod): Unit {
|
|
||||||
val deprecated = if (method.deprecated) "<B>Deprecated.</B>" else ""
|
|
||||||
print("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
||||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
||||||
<CODE>""")
|
|
||||||
if (!method.typeParameters.isEmpty()) {
|
|
||||||
println("""<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
|
|
||||||
<TR ALIGN="right" VALIGN="">
|
|
||||||
<TD NOWRAP><FONT SIZE="-1">
|
|
||||||
<CODE>""")
|
|
||||||
printTypeParameters(method)
|
|
||||||
println("<BR>")
|
|
||||||
print(link(method.returnType))
|
|
||||||
println("""</CODE></FONT></TD>
|
|
||||||
</TR>
|
|
||||||
</TABLE>""")
|
|
||||||
} else {
|
|
||||||
print(link(method.returnType))
|
|
||||||
}
|
|
||||||
println("</CODE></FONT></TD>")
|
|
||||||
print("<TD><CODE><B><A HREF=\"${pkg.nameAsRelativePath}${klass.nameAsPath}.html#${method.link}\">${method.name}</A></B>")
|
|
||||||
printParameters(method)
|
|
||||||
println("</CODE>")
|
|
||||||
println("")
|
|
||||||
println("<BR>")
|
|
||||||
println(" ${deprecated} ${method.detailedDescription}</TD>")
|
|
||||||
println("</TR>")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun printMethodDetail(method: KMethod): Unit {
|
|
||||||
println("<A NAME=\"${method.name}{${method.parameters.map{it.klass.name}})\"><!-- --></A><A NAME=\"${method.name}(${method.typeParametersText})\"><!-- --></A><H3>")
|
|
||||||
println("${method.name}</H3>")
|
|
||||||
println("<PRE>")
|
|
||||||
println("<FONT SIZE=\"-1\">")
|
|
||||||
printAnnotations(method.annotations)
|
|
||||||
print("</FONT>${method.modifiers.join(" ")} ")
|
|
||||||
|
|
||||||
printTypeParameters(method)
|
|
||||||
print(link(method.returnType))
|
|
||||||
print(" <A HREF=\"${pkg.nameAsRelativePath}src-html/${klass.nameAsPath}.html#line.${klass.sourceLine}\"><B>${method.name}</B></A>")
|
|
||||||
printParameters(method)
|
|
||||||
val exlist = method.exceptions
|
|
||||||
var first = true
|
|
||||||
if (!exlist.isEmpty()) {
|
|
||||||
println(" throws ");
|
|
||||||
for (ex in exlist) {
|
|
||||||
if (first) first = false else print(", ")
|
|
||||||
print(link(ex))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println("</PRE>")
|
|
||||||
|
|
||||||
/* TODO
|
|
||||||
println("""<DL>
|
|
||||||
<DD><B>Deprecated.</B> TODO text
|
|
||||||
<P>
|
|
||||||
<DD><b>Deprecated.</b>
|
|
||||||
<P>
|
|
||||||
<DD>
|
|
||||||
<DL>
|
|
||||||
<DT><B>Throws:</B>
|
|
||||||
<DD><CODE>${link(ex}</CODE><DT><B>Since:</B></DT>
|
|
||||||
<DD>${since}</DD>
|
|
||||||
</DL>
|
|
||||||
</DD>
|
|
||||||
</DL>
|
|
||||||
*/
|
|
||||||
println("<HR>")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun printTypeParameters(method: KMethod): Unit {
|
|
||||||
val typeParameters = method.typeParameters
|
|
||||||
if (!typeParameters.isEmpty()) {
|
|
||||||
print("<")
|
|
||||||
var separator = ""
|
|
||||||
for (t in typeParameters) {
|
|
||||||
print(separator)
|
|
||||||
separator = ", "
|
|
||||||
print(t.name)
|
|
||||||
val elist = t.extends
|
|
||||||
if (!elist.isEmpty()) {
|
|
||||||
print(" extends ")
|
|
||||||
var esep = ""
|
|
||||||
for (e in elist) {
|
|
||||||
print(esep)
|
|
||||||
esep = " & "
|
|
||||||
print(link(e))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print(">")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun printParameters(method: KMethod): Unit {
|
|
||||||
print("(")
|
|
||||||
var first = true
|
|
||||||
for (p in method.parameters) {
|
|
||||||
if (first) first = false else print(", ")
|
|
||||||
print("${p.name}: ")
|
|
||||||
print(link(p.klass))
|
|
||||||
}
|
|
||||||
print(")")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun printAnnotations(annotations: Collection<KAnnotation>): Unit {
|
|
||||||
for (a in annotations) {
|
|
||||||
println(link(a))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-10
@@ -4,6 +4,8 @@ import org.jetbrains.kotlin.model.KClass
|
|||||||
import org.jetbrains.kotlin.model.KAnnotation
|
import org.jetbrains.kotlin.model.KAnnotation
|
||||||
import org.jetbrains.kotlin.model.KPackage
|
import org.jetbrains.kotlin.model.KPackage
|
||||||
import org.jetbrains.kotlin.template.TextTemplate
|
import org.jetbrains.kotlin.template.TextTemplate
|
||||||
|
import org.jetbrains.kotlin.model.KFunction
|
||||||
|
import java.util.Collection
|
||||||
|
|
||||||
abstract class KDocTemplate() : TextTemplate() {
|
abstract class KDocTemplate() : TextTemplate() {
|
||||||
fun href(pkg: KPackage): String {
|
fun href(pkg: KPackage): String {
|
||||||
@@ -18,6 +20,24 @@ abstract class KDocTemplate() : TextTemplate() {
|
|||||||
return "${href(c.pkg)}${c.nameAsPath}.html$postfix"
|
return "${href(c.pkg)}${c.nameAsPath}.html$postfix"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun href(f: KFunction): String {
|
||||||
|
return if (f.owner is KClass) {
|
||||||
|
"${href(f.owner)}#${f.link}"
|
||||||
|
} else {
|
||||||
|
// TODO how to find the function in a package???
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun sourceHref(f: KFunction): String {
|
||||||
|
return if (f.owner is KClass) {
|
||||||
|
"${href(f.owner.pkg)}src-html/${f.owner.simpleName}.html#line.${f.sourceLine}"
|
||||||
|
} else {
|
||||||
|
// TODO how to find the function in a package???
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun link(c: KClass, fullName: Boolean = false): String {
|
fun link(c: KClass, fullName: Boolean = false): String {
|
||||||
// TODO if a class is a generic type parameter, just return the name...
|
// TODO if a class is a generic type parameter, just return the name...
|
||||||
val prefix = if (c.isAnnotation()) "@" else ""
|
val prefix = if (c.isAnnotation()) "@" else ""
|
||||||
@@ -32,13 +52,3 @@ abstract class KDocTemplate() : TextTemplate() {
|
|||||||
|
|
||||||
protected open fun relativePrefix(): String = ""
|
protected open fun relativePrefix(): String = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class PackageTemplateSupport(private val _pkg: KPackage) : KDocTemplate() {
|
|
||||||
|
|
||||||
// TODO this verbosity is to work around this bug: http://youtrack.jetbrains.com/issue/KT-1398
|
|
||||||
public val pkg: KPackage
|
|
||||||
get() = _pkg
|
|
||||||
|
|
||||||
protected override fun relativePrefix(): String = pkg.nameAsRelativePath
|
|
||||||
|
|
||||||
}
|
|
||||||
+43
-2
@@ -7,6 +7,9 @@ import std.util.*
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import org.jetbrains.kotlin.model.KModel
|
import org.jetbrains.kotlin.model.KModel
|
||||||
import org.jetbrains.kotlin.model.KPackage
|
import org.jetbrains.kotlin.model.KPackage
|
||||||
|
import org.jetbrains.kotlin.model.KClass
|
||||||
|
import org.jetbrains.kotlin.model.KFunction
|
||||||
|
import org.jetbrains.kotlin.model.extensionFunctions
|
||||||
|
|
||||||
class PackageFrameTemplate(val model: KModel, p: KPackage) : PackageTemplateSupport(p) {
|
class PackageFrameTemplate(val model: KModel, p: KPackage) : PackageTemplateSupport(p) {
|
||||||
override fun render() {
|
override fun render() {
|
||||||
@@ -22,8 +25,8 @@ class PackageFrameTemplate(val model: KModel, p: KPackage) : PackageTemplateSupp
|
|||||||
println("""</TITLE>
|
println("""</TITLE>
|
||||||
|
|
||||||
<META NAME="date" CONTENT="2012-01-09">""")
|
<META NAME="date" CONTENT="2012-01-09">""")
|
||||||
println("<LINK REL =\"stylesheet\" TYPE=\"text/css\" HREF=\"${pkg.nameAsRelativePath}stylesheet.css\" TITLE=\"Style\">")
|
println("<LINK REL =\"stylesheet\" TYPE=\"text/css\" HREF=\"${pkg.nameAsRelativePath}stylesheet.css\" TITLE=\"Style\">")
|
||||||
println("""
|
println("""
|
||||||
</HEAD>
|
</HEAD>
|
||||||
|
|
||||||
<BODY BGCOLOR="white">
|
<BODY BGCOLOR="white">
|
||||||
@@ -35,6 +38,8 @@ println("""
|
|||||||
printClasses("enum", "Enums")
|
printClasses("enum", "Enums")
|
||||||
printClasses("annotation", "Annotations")
|
printClasses("annotation", "Annotations")
|
||||||
printClasses("exception", "Exceptions")
|
printClasses("exception", "Exceptions")
|
||||||
|
printFunctions()
|
||||||
|
printExtensionFunctions()
|
||||||
|
|
||||||
println("""</BODY>
|
println("""</BODY>
|
||||||
</HTML>""")
|
</HTML>""")
|
||||||
@@ -58,6 +63,42 @@ println("""
|
|||||||
println("""</TR>
|
println("""</TR>
|
||||||
</TABLE>""")
|
</TABLE>""")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun printFunctions(): Unit {
|
||||||
|
val functions = pkg.functions.filter{ it.extensionClass == null }
|
||||||
|
if (! functions.isEmpty()) {
|
||||||
|
println("""<TABLE BORDER="0" WIDTH="100%" SUMMARY="">
|
||||||
|
<TR>
|
||||||
|
<TD NOWRAP><FONT size="+1" CLASS="FrameHeadingFont">Functions</FONT>
|
||||||
|
<FONT CLASS="FrameItemFont">
|
||||||
|
<BR>""")
|
||||||
|
for (c in functions) {
|
||||||
|
println("<A HREF=\"${c.name}.html\" title=\"function in ${pkg.name}\" target=\"classFrame\"><I>${c.name}</I></A>")
|
||||||
|
println("<BR>")
|
||||||
|
}
|
||||||
|
println("""</TR>
|
||||||
|
</TABLE>""")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun printExtensionFunctions(): Unit {
|
||||||
|
val map = extensionFunctions(pkg.functions)
|
||||||
|
if (! map.isEmpty()) {
|
||||||
|
println("""<TABLE BORDER="0" WIDTH="100%" SUMMARY="">
|
||||||
|
<TR>
|
||||||
|
<TD NOWRAP><FONT size="+1" CLASS="FrameHeadingFont">Extensions</FONT>
|
||||||
|
<FONT CLASS="FrameItemFont">
|
||||||
|
<BR>""")
|
||||||
|
for (e in map.entrySet()) {
|
||||||
|
val c = e?.getKey()
|
||||||
|
if (c != null) {
|
||||||
|
println("<A HREF=\"${c.name}.html\" title=\"function in ${pkg.name}\" target=\"classFrame\"><I>${c.name}</I></A>")
|
||||||
|
println("<BR>")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println("""</TR>
|
||||||
|
</TABLE>""")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-1
@@ -8,6 +8,7 @@ import java.util.*
|
|||||||
import org.jetbrains.kotlin.model.KModel
|
import org.jetbrains.kotlin.model.KModel
|
||||||
import org.jetbrains.kotlin.model.KPackage
|
import org.jetbrains.kotlin.model.KPackage
|
||||||
import org.jetbrains.kotlin.model.KClass
|
import org.jetbrains.kotlin.model.KClass
|
||||||
|
import org.jetbrains.kotlin.model.extensionFunctions
|
||||||
|
|
||||||
class PackageSummaryTemplate(val model: KModel, pkg: KPackage) : PackageTemplateSupport(pkg) {
|
class PackageSummaryTemplate(val model: KModel, pkg: KPackage) : PackageTemplateSupport(pkg) {
|
||||||
override fun render() {
|
override fun render() {
|
||||||
@@ -120,6 +121,9 @@ function windowTitle()
|
|||||||
printClasses("annotation", "Annotations")
|
printClasses("annotation", "Annotations")
|
||||||
printClasses("exception", "Exceptions")
|
printClasses("exception", "Exceptions")
|
||||||
|
|
||||||
|
printFunctions()
|
||||||
|
printExtensionFunctions()
|
||||||
|
|
||||||
println("""<A NAME="package_description"><!-- --></A><H2>""")
|
println("""<A NAME="package_description"><!-- --></A><H2>""")
|
||||||
println("Package ${pkg.name} Description")
|
println("Package ${pkg.name} Description")
|
||||||
println("""</H2>
|
println("""</H2>
|
||||||
@@ -237,9 +241,58 @@ Copyright © 2010-2012. All Rights Reserved.
|
|||||||
<P>
|
<P>
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun printFunctions(): Unit {
|
||||||
|
val functions = pkg.functions.filter{ it.extensionClass == null }
|
||||||
|
if (! functions.isEmpty()) {
|
||||||
|
print("""<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||||
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||||
|
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||||
|
<B>Functions Summary</B></FONT></TH>
|
||||||
|
</TR>""")
|
||||||
|
|
||||||
|
for (c in functions) {
|
||||||
|
println("""<TR BGCOLOR="white" CLASS="TableRowColor">""")
|
||||||
|
println("<TD WIDTH=\"15%\"><B><A HREF=\"${pkg.nameAsRelativePath}${c.name}.html\" title=\"function in ${pkg.name}\">${c.name}</A></B></TD>")
|
||||||
|
println("<TD>${c.description}</TD>")
|
||||||
|
println("</TR>")
|
||||||
|
}
|
||||||
|
println("""</TABLE>
|
||||||
|
|
||||||
|
|
||||||
|
<P>
|
||||||
|
""")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun printExtensionFunctions(): Unit {
|
||||||
|
val map = extensionFunctions(pkg.functions)
|
||||||
|
if (! map.isEmpty()) {
|
||||||
|
print("""<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||||
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||||
|
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||||
|
<B>Extensions Summary</B></FONT></TH>
|
||||||
|
</TR>""")
|
||||||
|
|
||||||
|
for (e in map.entrySet()) {
|
||||||
|
val c = e?.getKey()
|
||||||
|
if (c != null) {
|
||||||
|
println("""<TR BGCOLOR="white" CLASS="TableRowColor">""")
|
||||||
|
println("<TD WIDTH=\"15%\"><B><A HREF=\"${pkg.nameAsRelativePath}${c.name}.html\" title=\"extensions on ${pkg.name}\">${c.name}</A></B></TD>")
|
||||||
|
println("<TD>${c.description}</TD>")
|
||||||
|
println("</TR>")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println("""</TABLE>
|
||||||
|
|
||||||
|
|
||||||
|
<P>
|
||||||
|
""")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected fun printNextPrevPackages(): Unit {
|
protected fun printNextPrevPackages(): Unit {
|
||||||
println("""<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">""")
|
println("""<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">""")
|
||||||
val prev = model.previous(pkg)
|
val prev = model.previous(pkg)
|
||||||
|
|||||||
+146
@@ -0,0 +1,146 @@
|
|||||||
|
package org.jetbrains.kotlin.doc.templates
|
||||||
|
|
||||||
|
import std.*
|
||||||
|
import org.jetbrains.kotlin.template.*
|
||||||
|
import std.io.*
|
||||||
|
import std.util.*
|
||||||
|
import java.util.*
|
||||||
|
import org.jetbrains.kotlin.model.KModel
|
||||||
|
import org.jetbrains.kotlin.model.KPackage
|
||||||
|
import org.jetbrains.kotlin.model.KClass
|
||||||
|
import org.jetbrains.kotlin.model.KFunction
|
||||||
|
import org.jetbrains.kotlin.model.KAnnotation
|
||||||
|
|
||||||
|
|
||||||
|
abstract class PackageTemplateSupport(private val _pkg: KPackage) : KDocTemplate() {
|
||||||
|
|
||||||
|
// TODO this verbosity is to work around this bug: http://youtrack.jetbrains.com/issue/KT-1398
|
||||||
|
public val pkg: KPackage
|
||||||
|
get() = _pkg
|
||||||
|
|
||||||
|
protected override fun relativePrefix(): String = pkg.nameAsRelativePath
|
||||||
|
|
||||||
|
|
||||||
|
fun printFunctionSummary(functions: Collection<KFunction>): Unit {
|
||||||
|
for (f in functions) {
|
||||||
|
printFunctionSummary(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printFunctionDetail(functions: Collection<KFunction>): Unit {
|
||||||
|
for (f in functions) {
|
||||||
|
printFunctionDetail(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printFunctionSummary(method: KFunction): Unit {
|
||||||
|
val deprecated = if (method.deprecated) "<B>Deprecated.</B>" else ""
|
||||||
|
print("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||||
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||||
|
<CODE>""")
|
||||||
|
if (!method.typeParameters.isEmpty()) {
|
||||||
|
println("""<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
|
||||||
|
<TR ALIGN="right" VALIGN="">
|
||||||
|
<TD NOWRAP><FONT SIZE="-1">
|
||||||
|
<CODE>""")
|
||||||
|
printTypeParameters(method)
|
||||||
|
println("<BR>")
|
||||||
|
print(link(method.returnType))
|
||||||
|
println("""</CODE></FONT></TD>
|
||||||
|
</TR>
|
||||||
|
</TABLE>""")
|
||||||
|
} else {
|
||||||
|
print(link(method.returnType))
|
||||||
|
}
|
||||||
|
println("</CODE></FONT></TD>")
|
||||||
|
print("<TD><CODE><B><A HREF=\"${href(method)}\">${method.name}</A></B>")
|
||||||
|
printParameters(method)
|
||||||
|
println("</CODE>")
|
||||||
|
println("")
|
||||||
|
println("<BR>")
|
||||||
|
println(" ${deprecated} ${method.detailedDescription}</TD>")
|
||||||
|
println("</TR>")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printFunctionDetail(method: KFunction): Unit {
|
||||||
|
println("<A NAME=\"${method.name}{${method.parameterTypeText}})\"><!-- --></A><A NAME=\"${method.name}(${method.typeParametersText})\"><!-- --></A><H3>")
|
||||||
|
println("${method.name}</H3>")
|
||||||
|
println("<PRE>")
|
||||||
|
println("<FONT SIZE=\"-1\">")
|
||||||
|
printAnnotations(method.annotations)
|
||||||
|
print("</FONT>${method.modifiers.join(" ")} ")
|
||||||
|
|
||||||
|
printTypeParameters(method)
|
||||||
|
print(link(method.returnType))
|
||||||
|
print(" <A HREF=\"${sourceHref(method)}\"><B>${method.name}</B></A>")
|
||||||
|
printParameters(method)
|
||||||
|
val exlist = method.exceptions
|
||||||
|
var first = true
|
||||||
|
if (!exlist.isEmpty()) {
|
||||||
|
println(" throws ");
|
||||||
|
for (ex in exlist) {
|
||||||
|
if (first) first = false else print(", ")
|
||||||
|
print(link(ex))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println("</PRE>")
|
||||||
|
|
||||||
|
/* TODO
|
||||||
|
println("""<DL>
|
||||||
|
<DD><B>Deprecated.</B> TODO text
|
||||||
|
<P>
|
||||||
|
<DD><b>Deprecated.</b>
|
||||||
|
<P>
|
||||||
|
<DD>
|
||||||
|
<DL>
|
||||||
|
<DT><B>Throws:</B>
|
||||||
|
<DD><CODE>${link(ex}</CODE><DT><B>Since:</B></DT>
|
||||||
|
<DD>${since}</DD>
|
||||||
|
</DL>
|
||||||
|
</DD>
|
||||||
|
</DL>
|
||||||
|
*/
|
||||||
|
println("<HR>")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printTypeParameters(method: KFunction): Unit {
|
||||||
|
val typeParameters = method.typeParameters
|
||||||
|
if (!typeParameters.isEmpty()) {
|
||||||
|
print("<")
|
||||||
|
var separator = ""
|
||||||
|
for (t in typeParameters) {
|
||||||
|
print(separator)
|
||||||
|
separator = ", "
|
||||||
|
print(t.name)
|
||||||
|
val elist = t.extends
|
||||||
|
if (!elist.isEmpty()) {
|
||||||
|
print(" extends ")
|
||||||
|
var esep = ""
|
||||||
|
for (e in elist) {
|
||||||
|
print(esep)
|
||||||
|
esep = " & "
|
||||||
|
print(link(e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print(">")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printParameters(method: KFunction): Unit {
|
||||||
|
print("(")
|
||||||
|
var first = true
|
||||||
|
for (p in method.parameters) {
|
||||||
|
if (first) first = false else print(", ")
|
||||||
|
print("${p.name}: ")
|
||||||
|
print(link(p.klass))
|
||||||
|
}
|
||||||
|
print(")")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printAnnotations(annotations: Collection<KAnnotation>): Unit {
|
||||||
|
for (a in annotations) {
|
||||||
|
println(link(a))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,20 +6,30 @@ import std.util.*
|
|||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
fun extensionFunctions(functions: Collection<KFunction>): SortedMap<KClass, List<KFunction>> {
|
||||||
|
val map = TreeMap<KClass, List<KFunction>>()
|
||||||
|
functions.filter{ it.extensionClass != null }.groupBy(map){ it.extensionClass.sure() }
|
||||||
|
return map
|
||||||
|
}
|
||||||
|
|
||||||
|
trait KClassOrPackage {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class KModel(var title: String = "Documentation", var version: String = "TODO") {
|
class KModel(var title: String = "Documentation", var version: String = "TODO") {
|
||||||
// TODO generates java.lang.NoSuchMethodError: std.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap;
|
// TODO generates java.lang.NoSuchMethodError: std.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap;
|
||||||
//val packages = sortedMap<String,KPackage>()
|
//val packages = sortedMap<String,KPackage>()
|
||||||
public val packageMap: SortedMap<String,KPackage> = TreeMap<String,KPackage>()
|
public val packageMap: SortedMap<String, KPackage> = TreeMap<String, KPackage>()
|
||||||
|
|
||||||
public val allPackages: Collection<KPackage>
|
public val allPackages: Collection<KPackage>
|
||||||
get() = packageMap.values().sure()
|
get() = packageMap.values().sure()
|
||||||
|
|
||||||
/** Returns the local packages */
|
/** Returns the local packages */
|
||||||
public val packages: Collection<KPackage>
|
public val packages: Collection<KPackage>
|
||||||
get() = allPackages.filter{ it.local }
|
get() = allPackages.filter{ it.local }
|
||||||
|
|
||||||
public val classes: Collection<KClass>
|
public val classes: Collection<KClass>
|
||||||
get() = packages.flatMap{ it.classes }
|
get() = packages.flatMap{ it.classes }
|
||||||
|
|
||||||
/* Returns the package for the given name, creating one if its not already been create yet */
|
/* Returns the package for the given name, creating one if its not already been create yet */
|
||||||
fun getPackage(name: String): KPackage {
|
fun getPackage(name: String): KPackage {
|
||||||
@@ -49,39 +59,51 @@ class KModel(var title: String = "Documentation", var version: String = "TODO")
|
|||||||
|
|
||||||
class KPackage(val model: KModel, val name: String, var external: Boolean = false,
|
class KPackage(val model: KModel, val name: String, var external: Boolean = false,
|
||||||
var description: String = "", var detailedDescription: String = "",
|
var description: String = "", var detailedDescription: String = "",
|
||||||
var local: Boolean = false) : Comparable<KPackage> {
|
var functions: SortedSet<KFunction> = TreeSet<KFunction>(),
|
||||||
|
var local: Boolean = false) : Comparable<KPackage>, KClassOrPackage {
|
||||||
override fun compareTo(other: KPackage): Int = name.compareTo(other.name)
|
override fun compareTo(other: KPackage): Int = name.compareTo(other.name)
|
||||||
|
|
||||||
|
|
||||||
fun equals(other: KPackage) = name == other.name
|
fun equals(other: KPackage) = name == other.name
|
||||||
|
|
||||||
fun toString() = "KPackage($name)"
|
fun toString() = "KPackage($name)"
|
||||||
|
|
||||||
|
private var _initialised = false
|
||||||
|
|
||||||
|
/** Runs the initialisation block if this class has not yet been initialised */
|
||||||
|
fun initialise(fn: () -> Unit): Unit {
|
||||||
|
if (!_initialised) {
|
||||||
|
_initialised = true
|
||||||
|
fn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the name as a directory using '/' instead of '.' */
|
/** Returns the name as a directory using '/' instead of '.' */
|
||||||
public val nameAsPath: String
|
public val nameAsPath: String
|
||||||
get() = name.replace('.', '/')
|
get() = name.replace('.', '/')
|
||||||
|
|
||||||
/** Returns a list of all the paths in the package name */
|
/** Returns a list of all the paths in the package name */
|
||||||
public val namePaths: List<String>
|
public val namePaths: List<String>
|
||||||
get() {
|
get() {
|
||||||
val answer = ArrayList<String>()
|
val answer = ArrayList<String>()
|
||||||
for (n in name.split("\\.")) {
|
for (n in name.split("\\.")) {
|
||||||
if (n != null) {
|
if (n != null) {
|
||||||
answer.add(n)
|
answer.add(n)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return answer;
|
|
||||||
}
|
}
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns a relative path like ../.. for each path in the name */
|
/** Returns a relative path like ../.. for each path in the name */
|
||||||
public val nameAsRelativePath: String
|
public val nameAsRelativePath: String
|
||||||
get() {
|
get() {
|
||||||
val answer = namePaths.map{ ".." }.join("/")
|
val answer = namePaths.map{ ".." }.join("/")
|
||||||
return if (answer.length == 0) "" else answer + "/"
|
return if (answer.length == 0) "" else answer + "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO generates java.lang.NoSuchMethodError: std.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap;
|
// TODO generates java.lang.NoSuchMethodError: std.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap;
|
||||||
//val classes = sortedMap<String,KClass>()
|
//val classes = sortedMap<String,KClass>()
|
||||||
public val classMap: SortedMap<String,KClass> = TreeMap<String,KClass>()
|
public val classMap: SortedMap<String, KClass> = TreeMap<String, KClass>()
|
||||||
|
|
||||||
public val classes: Collection<KClass> = classMap.values().sure()
|
public val classes: Collection<KClass> = classMap.values().sure()
|
||||||
|
|
||||||
@@ -91,8 +113,7 @@ class KPackage(val model: KModel, val name: String, var external: Boolean = fals
|
|||||||
/* Returns the class for the given name, creating one if its not already been create yet */
|
/* Returns the class for the given name, creating one if its not already been create yet */
|
||||||
fun getClass(simpleName: String): KClass {
|
fun getClass(simpleName: String): KClass {
|
||||||
return classMap.getOrPut(simpleName) {
|
return classMap.getOrPut(simpleName) {
|
||||||
val base = if (simpleName == "Object" && name == "java.lang") null else model.getClass("java.lang.Object")
|
KClass(this, simpleName) }
|
||||||
KClass(this, simpleName, base) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun qualifiedName(simpleName: String): String {
|
fun qualifiedName(simpleName: String): String {
|
||||||
@@ -114,21 +135,21 @@ class KPackage(val model: KModel, val name: String, var external: Boolean = fals
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun groupClassMap(): Map<String,List<KClass>> {
|
fun groupClassMap(): Map<String, List<KClass>> {
|
||||||
return classes.groupBy(TreeMap<String,List<KClass>>()){it.group}
|
return classes.groupBy(TreeMap<String, List<KClass>>()){it.group}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class KClass(val pkg: KPackage, val simpleName: String,
|
class KClass(val pkg: KPackage, val simpleName: String,
|
||||||
var baseClass: KClass? = null,
|
|
||||||
var kind: String = "class", var group: String = "Other",
|
var kind: String = "class", var group: String = "Other",
|
||||||
var description: String = "", var detailedDescription: String = "",
|
var description: String = "", var detailedDescription: String = "",
|
||||||
var annotations: List<KAnnotation> = arrayList<KAnnotation>(),
|
var annotations: List<KAnnotation> = arrayList<KAnnotation>(),
|
||||||
var since: String = "",
|
var since: String = "",
|
||||||
var authors: List<String> = arrayList<String>(),
|
var authors: List<String> = arrayList<String>(),
|
||||||
var methods: List<KMethod> = arrayList<KMethod>(),
|
var functions: SortedSet<KFunction> = TreeSet<KFunction>(),
|
||||||
|
var baseClasses: List<KClass> = arrayList<KClass>(),
|
||||||
var nestedClasses: List<KClass> = arrayList<KClass>(),
|
var nestedClasses: List<KClass> = arrayList<KClass>(),
|
||||||
var sourceLine: Int = 2) : Comparable<KClass> {
|
var sourceLine: Int = 2) : Comparable<KClass>, KClassOrPackage {
|
||||||
|
|
||||||
private var _initialised = false
|
private var _initialised = false
|
||||||
|
|
||||||
@@ -148,46 +169,63 @@ class KClass(val pkg: KPackage, val simpleName: String,
|
|||||||
|
|
||||||
/** Link to the type which is relative if its a local type but could be a type in a different library or null if no link */
|
/** Link to the type which is relative if its a local type but could be a type in a different library or null if no link */
|
||||||
public var url: String? = null
|
public var url: String? = null
|
||||||
get() {
|
get() {
|
||||||
if ($url == null) $url = "${nameAsPath}.html"
|
if ($url == null) $url = "${nameAsPath}.html"
|
||||||
return $url
|
return $url
|
||||||
}
|
}
|
||||||
|
|
||||||
public val name: String = pkg.qualifiedName(simpleName)
|
public val name: String = pkg.qualifiedName(simpleName)
|
||||||
public val packageName: String = pkg.name
|
public val packageName: String = pkg.name
|
||||||
|
|
||||||
/** Returns the name as a directory using '/' instead of '.' */
|
/** Returns the name as a directory using '/' instead of '.' */
|
||||||
public val nameAsPath: String
|
public val nameAsPath: String
|
||||||
get() = name.replace('.', '/')
|
get() = name.replace('.', '/')
|
||||||
|
|
||||||
|
|
||||||
fun isAnnotation() = kind == "annotation"
|
fun isAnnotation() = kind == "annotation"
|
||||||
fun isInterface() = kind == "interface"
|
fun isInterface() = kind == "interface"
|
||||||
}
|
}
|
||||||
|
|
||||||
class KMethod(val name: String,
|
class KFunction(val owner: KClassOrPackage, val name: String,
|
||||||
var returnType: KClass,
|
var returnType: KClass,
|
||||||
var description: String = "", var detailedDescription: String = "",
|
var description: String = "", var detailedDescription: String = "",
|
||||||
var deprecated: Boolean = false,
|
var deprecated: Boolean = false,
|
||||||
|
var extensionClass: KClass? = null,
|
||||||
var modifiers: List<String> = arrayList<String>(),
|
var modifiers: List<String> = arrayList<String>(),
|
||||||
var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>(),
|
var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>(),
|
||||||
var parameters: List<KParameter> = arrayList<KParameter>(),
|
var parameters: List<KParameter> = arrayList<KParameter>(),
|
||||||
var exceptions: List<KClass> = arrayList<KClass>(),
|
var exceptions: List<KClass> = arrayList<KClass>(),
|
||||||
var annotations: List<KAnnotation> = arrayList<KAnnotation>()) : Comparable<KMethod> {
|
var annotations: List<KAnnotation> = arrayList<KAnnotation>(),
|
||||||
// TODO compare other things than just name :)
|
var sourceLine: Int = 2) : Comparable<KFunction> {
|
||||||
|
|
||||||
override fun compareTo(other: KMethod): Int = name.compareTo(other.name)
|
override fun compareTo(other: KFunction): Int {
|
||||||
|
var answer = name.compareTo(other.name)
|
||||||
|
if (answer == 0) {
|
||||||
|
answer = parameterTypeText.compareTo(other.parameterTypeText)
|
||||||
|
}
|
||||||
|
return answer
|
||||||
|
}
|
||||||
|
|
||||||
fun equals(other: KMethod) = name == other.name
|
fun equals(other: KFunction) = name == other.name
|
||||||
|
|
||||||
fun toString() = "fun ($name)"
|
fun toString() = "fun ($name)"
|
||||||
|
|
||||||
/** TODO generate a link with the argument type names */
|
/** TODO generate a link with the argument type names */
|
||||||
public val link: String = name
|
public val link: String = "$name($parameterTypeText)"
|
||||||
|
|
||||||
/** Returns a list of generic type parameter names kinds like "A, I" */
|
/** Returns a list of generic type parameter names kinds like "A, I" */
|
||||||
public val typeParametersText: String
|
public val typeParametersText: String
|
||||||
get() = typeParameters.map{ it.name }.join(", ")
|
get() = typeParameters.map{ it.name }.join(", ")
|
||||||
|
|
||||||
|
/** Returns a list of parameter value types */
|
||||||
|
private var _parameterTypeText: String? = null
|
||||||
|
public val parameterTypeText: String
|
||||||
|
get() {
|
||||||
|
if (_parameterTypeText == null) {
|
||||||
|
_parameterTypeText = typeParameters.map{ it.klass.name }.join(", ")
|
||||||
|
}
|
||||||
|
return _parameterTypeText.sure()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class KParameter(val name: String,
|
class KParameter(val name: String,
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package test.kotlin.doc;
|
|
||||||
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class KDocTestAll {
|
|
||||||
public static TestSuite suite() {
|
|
||||||
return new TestSuite("test.kotlin.doc.ModelTest");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package test.kotlin.doc
|
|
||||||
|
|
||||||
import std.*
|
|
||||||
import std.util.*
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.model.*
|
|
||||||
|
|
||||||
import junit.framework.TestCase
|
|
||||||
|
|
||||||
// TODO should use the ktest library really for nicer asserts
|
|
||||||
import junit.framework.Assert.assertEquals
|
|
||||||
import org.jetbrains.kotlin.doc.KDocGenerator
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class ModelTest : TestCase() {
|
|
||||||
val model = KModel()
|
|
||||||
|
|
||||||
fun testGetClassViaPackage() {
|
|
||||||
val p = model.getPackage("foo.bar")
|
|
||||||
val c = p.getClass("Cheese")
|
|
||||||
|
|
||||||
println("Got class: $c")
|
|
||||||
|
|
||||||
assertEquals("foo.bar.Cheese", c.name)
|
|
||||||
assertEquals("foo.bar", c.packageName)
|
|
||||||
assertEquals("Cheese", c.simpleName)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testGetClassViaQualifiedName() {
|
|
||||||
val c = model.getClass("something.else.Foo")
|
|
||||||
|
|
||||||
println("Got class: $c")
|
|
||||||
|
|
||||||
assertEquals("something.else.Foo", c.name)
|
|
||||||
assertEquals("something.else", c.packageName)
|
|
||||||
assertEquals("Foo", c.simpleName)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testModelWalk() {
|
|
||||||
val a = model.getClass("something.else.Aaa")
|
|
||||||
val z = model.getClass("something.else.Zzz")
|
|
||||||
val c = model.getClass("another.Cheese")
|
|
||||||
|
|
||||||
c.methods.add(KMethod("addFoo", a, "add some foos"))
|
|
||||||
val m1 = KMethod("addZzzz", z, "add some zzz")
|
|
||||||
m1.parameters.add(KParameter("myz", z))
|
|
||||||
c.methods.add(m1)
|
|
||||||
|
|
||||||
// now lets iterate through the model
|
|
||||||
println("Walking the model...")
|
|
||||||
for (p in model.packages) {
|
|
||||||
println("Package ${p.name}")
|
|
||||||
for (c in p.classes) {
|
|
||||||
println(" ${c.simpleName}")
|
|
||||||
}
|
|
||||||
println()
|
|
||||||
}
|
|
||||||
|
|
||||||
val processor = KDocGenerator(model, File("target/test-data/ModelTest"))
|
|
||||||
processor.execute()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user