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:
@@ -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)
|
||||||
@@ -341,7 +355,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
|||||||
var text = lines[i] ?: ""
|
var text = lines[i] ?: ""
|
||||||
text = text.trim()
|
text = text.trim()
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
text = text.trimLeading("/**").trimLeading("/*")
|
text = text.trimLeading("/**").trimLeading("/*")
|
||||||
} else {
|
} else {
|
||||||
buffer.append("\n")
|
buffer.append("\n")
|
||||||
}
|
}
|
||||||
@@ -469,7 +483,7 @@ class TemplateLinkRenderer(val annotated: KAnnotated, val template: KDocTemplate
|
|||||||
val idx = qualifiedName.lastIndexOf('.')
|
val idx = qualifiedName.lastIndexOf('.')
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
val className = qualifiedName.substring(0, idx)
|
val className = qualifiedName.substring(0, idx)
|
||||||
val c = model.getClass(className)
|
val c = model.getClass(className)
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
// lets try find method...
|
// lets try find method...
|
||||||
val remaining = qualifiedName.substring(idx + 1)
|
val remaining = qualifiedName.substring(idx + 1)
|
||||||
@@ -494,32 +508,32 @@ 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)
|
||||||
if (classifierDescriptor == null) {
|
if (classifierDescriptor == null) {
|
||||||
val o = scope.getObjectDescriptor(text)
|
val o = scope.getObjectDescriptor(text)
|
||||||
println("Attempt to resolve HREF: $text Found objectDescriptor $o")
|
println("Attempt to resolve HREF: $text Found objectDescriptor $o")
|
||||||
} else {
|
} else {
|
||||||
println("Attempt to resolve HREF: $text Found classifierDescriptor $classifierDescriptor")
|
println("Attempt to resolve HREF: $text Found classifierDescriptor $classifierDescriptor")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun findWritableScope(declarationDescriptor: DeclarationDescriptor) : WritableScopeImpl? {
|
protected fun findWritableScope(declarationDescriptor: DeclarationDescriptor) : WritableScopeImpl? {
|
||||||
val container = declarationDescriptor.getContainingDeclaration()
|
val container = declarationDescriptor.getContainingDeclaration()
|
||||||
if (container is NamespaceDescriptor) {
|
if (container is NamespaceDescriptor) {
|
||||||
val scope = container.getMemberScope()
|
val scope = container.getMemberScope()
|
||||||
if (scope is WritableScopeImpl) {
|
if (scope is WritableScopeImpl) {
|
||||||
return scope
|
return scope
|
||||||
}
|
}
|
||||||
} else if (container != null) {
|
} else if (container != null) {
|
||||||
return findWritableScope(container)
|
return findWritableScope(container)
|
||||||
}
|
}
|
||||||
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
-3
@@ -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>
|
<TD NOWRAP><FONT size="+1" CLASS="FrameHeadingFont">Functions</FONT>
|
||||||
<FONT CLASS="FrameItemFont">
|
<FONT CLASS="FrameItemFont">
|
||||||
<BR>""")
|
<BR>""")
|
||||||
|
|
||||||
|
var lastName = ""
|
||||||
for (c in functions) {
|
for (c in functions) {
|
||||||
println("""<A HREF="${href(c)}" title="function in ${pkg.name}" target="classFrame"><I>${c.name}</I></A>
|
// only show the first function with a given name
|
||||||
<BR>""")
|
if (c.name != lastName) {
|
||||||
|
println("""<A HREF="${href(c)}" title="function in ${pkg.name}" target="classFrame"><I>${c.name}</I></A>
|
||||||
|
<BR>""")
|
||||||
|
}
|
||||||
|
lastName = c.name
|
||||||
}
|
}
|
||||||
println("""</TR>
|
println("""</TR>
|
||||||
</TABLE>""")
|
</TABLE>""")
|
||||||
|
|||||||
Vendored
+6
-2
@@ -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 © 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 © 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> """)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user