improved kdoc to avoid showing duplicate functions of the same name & to show more detail in the function summary table

This commit is contained in:
James Strachan
2012-03-09 11:28:19 +00:00
parent e5e227b57b
commit beafb561bb
3 changed files with 57 additions and 32 deletions
@@ -33,6 +33,21 @@ import org.pegdown.Extensions
import org.jetbrains.kotlin.doc.templates.KDocTemplate import org.jetbrains.kotlin.doc.templates.KDocTemplate
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl
/**
* Returns the collection of functions with duplicate function names filtered out
* so only the first one is included
*/
fun filterDuplicateNames(functions: Collection<KFunction>): Collection<KFunction> {
var lastName = ""
return functions.filter{
val name = it.name
val answer = name != lastName
lastName = name
answer
}
}
fun containerName(descriptor: DeclarationDescriptor): String = qualifiedName(descriptor.getContainingDeclaration()) fun containerName(descriptor: DeclarationDescriptor): String = qualifiedName(descriptor.getContainingDeclaration())
fun qualifiedName(descriptor: DeclarationDescriptor?): String { fun qualifiedName(descriptor: DeclarationDescriptor?): String {
@@ -313,7 +328,6 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
} }
protected fun commentsFor(descriptor: DeclarationDescriptor): String { protected fun commentsFor(descriptor: DeclarationDescriptor): String {
val psiElement = try { val psiElement = try {
BindingContextUtils.descriptorToDeclaration(context, descriptor) BindingContextUtils.descriptorToDeclaration(context, descriptor)
@@ -494,7 +508,7 @@ class TemplateLinkRenderer(val annotated: KAnnotated, val template: KDocTemplate
protected fun resolveToQualifiedName(text: String): String { protected fun resolveToQualifiedName(text: String): String {
// TODO use the CompletionContributors maybe to figure out what local names are imported??? // TODO use the CompletionContributors maybe to figure out what local names are imported???
return text return text
/* /*
val scope = findWritableScope(annotated.declarationDescriptor) val scope = findWritableScope(annotated.declarationDescriptor)
if (scope != null) { if (scope != null) {
val classifierDescriptor = scope.getClassifier(text) val classifierDescriptor = scope.getClassifier(text)
@@ -519,7 +533,7 @@ class TemplateLinkRenderer(val annotated: KAnnotated, val template: KDocTemplate
} }
return null return null
*/ */
} }
override fun render(node : RefLinkNode?, url : String?, title : String?, text : String?) : Rendering? { override fun render(node : RefLinkNode?, url : String?, title : String?, text : String?) : Rendering? {
@@ -661,7 +675,7 @@ class KPackage(model: KModel, val descriptor: NamespaceDescriptor,
} }
class KType(val jetType: JetType, model: KModel, val klass: KClass?, val arguments: List<KType> = ArrayList<KType>()) class KType(val jetType: JetType, model: KModel, val klass: KClass?, val arguments: List<KType> = ArrayList<KType>())
: KNamed(klass?.name ?: jetType.toString(), model, jetType.getConstructor().getDeclarationDescriptor().sure()) { : KNamed(klass?.name ?: jetType.toString(), model, jetType.getConstructor().getDeclarationDescriptor().sure()) {
{ {
if (klass != null) { if (klass != null) {
this.wikiDescription = klass.wikiDescription this.wikiDescription = klass.wikiDescription
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.doc.model.KPackage
import org.jetbrains.kotlin.doc.model.KClass import org.jetbrains.kotlin.doc.model.KClass
import org.jetbrains.kotlin.doc.model.KFunction import org.jetbrains.kotlin.doc.model.KFunction
import org.jetbrains.kotlin.doc.model.extensionFunctions import org.jetbrains.kotlin.doc.model.extensionFunctions
import org.jetbrains.kotlin.doc.model.filterDuplicateNames
class PackageFrameTemplate(val model: KModel, p: KPackage) : PackageTemplateSupport(p) { class PackageFrameTemplate(val model: KModel, p: KPackage) : PackageTemplateSupport(p) {
override fun render() { override fun render() {
@@ -65,16 +66,22 @@ ${pkg.name} (${model.title})
} }
protected fun printFunctions(): Unit { protected fun printFunctions(): Unit {
val functions = pkg.packageFunctions() val functions = filterDuplicateNames(pkg.packageFunctions())
if (! functions.isEmpty()) { if (! functions.isEmpty()) {
println("""<TABLE BORDER="0" WIDTH="100%" SUMMARY=""> println("""<TABLE BORDER="0" WIDTH="100%" SUMMARY="">
<TR> <TR>
<TD NOWRAP><FONT size="+1" CLASS="FrameHeadingFont">Functions</FONT>&nbsp; <TD NOWRAP><FONT size="+1" CLASS="FrameHeadingFont">Functions</FONT>&nbsp;
<FONT CLASS="FrameItemFont"> <FONT CLASS="FrameItemFont">
<BR>""") <BR>""")
var lastName = ""
for (c in functions) { for (c in functions) {
// only show the first function with a given name
if (c.name != lastName) {
println("""<A HREF="${href(c)}" title="function in ${pkg.name}" target="classFrame"><I>${c.name}</I></A> println("""<A HREF="${href(c)}" title="function in ${pkg.name}" target="classFrame"><I>${c.name}</I></A>
<BR>""") <BR>""")
}
lastName = c.name
} }
println("""</TR> println("""</TR>
</TABLE>""") </TABLE>""")
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.doc.model.KPackage
import org.jetbrains.kotlin.doc.model.KClass import org.jetbrains.kotlin.doc.model.KClass
import org.jetbrains.kotlin.doc.model.extensionFunctions import org.jetbrains.kotlin.doc.model.extensionFunctions
import org.jetbrains.kotlin.doc.model.inheritedExtensionFunctions import org.jetbrains.kotlin.doc.model.inheritedExtensionFunctions
import org.jetbrains.kotlin.doc.model.filterDuplicateNames
class PackageSummaryTemplate(val model: KModel, pkg: KPackage) : PackageTemplateSupport(pkg) { class PackageSummaryTemplate(val model: KModel, pkg: KPackage) : PackageTemplateSupport(pkg) {
override fun render() { override fun render() {
@@ -119,7 +120,8 @@ ${pkg.description(this)}
printClasses("annotation", "Annotations") printClasses("annotation", "Annotations")
printClasses("exception", "Exceptions") printClasses("exception", "Exceptions")
printFunctions() printFunctionSummary(pkg.packageFunctions())
//printFunctions()
printExtensionFunctions() printExtensionFunctions()
println("""<A NAME="package_description"><!-- --></A><H2> println("""<A NAME="package_description"><!-- --></A><H2>
@@ -240,6 +242,7 @@ Copyright &#169; 2010-2012. All Rights Reserved.
} }
} }
// TODO delete
protected fun printFunctions(): Unit { protected fun printFunctions(): Unit {
val functions = pkg.functions.filter{ it.extensionClass == null } val functions = pkg.functions.filter{ it.extensionClass == null }
if (! functions.isEmpty()) { if (! functions.isEmpty()) {
@@ -280,7 +283,8 @@ Copyright &#169; 2010-2012. All Rights Reserved.
<TD>""") <TD>""")
val list = e?.getValue() val list = e?.getValue()
if (list != null) { if (list != null) {
for (f in list) { val functions = filterDuplicateNames(list)
for (f in functions) {
println("""<A HREF="${extensionsHref(pkg, c, f)}">${f.name}<A> """) println("""<A HREF="${extensionsHref(pkg, c, f)}">${f.name}<A> """)
} }
} }