include all inherited extension functions; so Collection / List extension page shows all available methods
This commit is contained in:
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.model.*
|
||||
import java.io.File
|
||||
import java.util.List
|
||||
import java.util.HashSet
|
||||
import java.util.Collection
|
||||
import java.util.*
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
@@ -47,9 +47,6 @@ class KDocGenerator(val model: KModel, val outputDir: File) {
|
||||
run("overview-tree.html", OverviewTreeTemplate(model))
|
||||
run("package-list", PackageListTemplate(model))
|
||||
// run("serialized-form.html", SerializedFormTemplate(model))
|
||||
/**
|
||||
TODO
|
||||
*/
|
||||
for (p in model.packages) {
|
||||
run("${p.nameAsPath}/package-frame.html", PackageFrameTemplate(model, p))
|
||||
run("${p.nameAsPath}/package-summary.html", PackageSummaryTemplate(model, p))
|
||||
@@ -59,14 +56,7 @@ class KDocGenerator(val model: KModel, val outputDir: File) {
|
||||
run("${c.nameAsPath}.html", ClassTemplate(model, p, c))
|
||||
}
|
||||
|
||||
val map = extensionFunctions(p.functions)
|
||||
for (e in map.entrySet()) {
|
||||
val c = e?.getKey()
|
||||
val functions = e?.getValue()
|
||||
if (c != null && functions != null) {
|
||||
run("${p.nameAsPath}/${c.simpleName}-extensions.html", ClassExtensionsTemplate(model, p, c, functions))
|
||||
}
|
||||
}
|
||||
generateExtensionFunctions(p)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,4 +72,15 @@ class KDocGenerator(val model: KModel, val outputDir: File) {
|
||||
println(text)
|
||||
}
|
||||
|
||||
protected fun generateExtensionFunctions(p: KPackage): Unit {
|
||||
val map = inheritedExtensionFunctions(p.functions)
|
||||
for (e in map.entrySet()) {
|
||||
val c = e?.getKey()
|
||||
val functions = e?.getValue()
|
||||
if (c != null && functions != null) {
|
||||
run("${p.nameAsPath}/${c.simpleName}-extensions.html", ClassExtensionsTemplate(model, p, c, functions))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.model.KClass
|
||||
import org.jetbrains.kotlin.model.KFunction
|
||||
import org.jetbrains.kotlin.model.KAnnotation
|
||||
|
||||
class ClassExtensionsTemplate(m: KModel, p: KPackage, k: KClass, var functions: List<KFunction>) : ClassTemplate(m, p, k) {
|
||||
class ClassExtensionsTemplate(m: KModel, p: KPackage, k: KClass, var functions: Collection<KFunction>) : ClassTemplate(m, p, k) {
|
||||
|
||||
override fun pageTitle(): String = "${klass.name} Extensions fom ${pkg.name} (${model.title})"
|
||||
|
||||
|
||||
@@ -33,16 +33,45 @@ fun qualifiedName(descriptor: DeclarationDescriptor?): String {
|
||||
}
|
||||
}
|
||||
|
||||
fun extensionFunctions(functions: Collection<KFunction>): SortedMap<KClass, List<KFunction>> {
|
||||
// TODO for some reason the SortedMap causes kotlin to freak out a little :)
|
||||
fun inheritedExtensionFunctions(functions: Collection<KFunction>): Map<KClass, SortedSet<KFunction>> {
|
||||
//fun inheritedExtensionFunctions(functions: Collection<KFunction>): SortedMap<KClass, SortedSet<KFunction>> {
|
||||
val map = extensionFunctions(functions)
|
||||
// for each class, lets walk its base classes and add any other extension functions from base classes
|
||||
val classes = map.keySet().toList()
|
||||
val answer = TreeMap<KClass, SortedSet<KFunction>>()
|
||||
for (c in map.keySet()) {
|
||||
val allFunctions = map.get(c).notNull().toSortedSet()
|
||||
answer.put(c, allFunctions)
|
||||
val des = c.descendants()
|
||||
for (b in des) {
|
||||
val list = map.get(b)
|
||||
if (list != null) {
|
||||
if (allFunctions != null) {
|
||||
for (f in list) {
|
||||
if (f != null) {
|
||||
// add the methods from the base class if we don't have a matching method
|
||||
if (!allFunctions.any{ it.name == f.name && it.parameterTypeText == f.parameterTypeText}) {
|
||||
allFunctions.add(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return answer
|
||||
}
|
||||
|
||||
// TODO for some reason the SortedMap causes kotlin to freak out a little :)
|
||||
fun extensionFunctions(functions: Collection<KFunction>): Map<KClass, List<KFunction>> {
|
||||
//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 context: BindingContext, var title: String = "Documentation", var version: String = "TODO") {
|
||||
@@ -346,6 +375,15 @@ class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
|
||||
|
||||
fun isAnnotation() = kind == "annotation"
|
||||
fun isInterface() = kind == "interface"
|
||||
|
||||
/** Returns all of the base classes and all of their descendants */
|
||||
fun descendants(answer: Set<KClass> = LinkedHashSet<KClass>()): Set<KClass> {
|
||||
answer.addAll(baseClasses)
|
||||
for (b in baseClasses) {
|
||||
b.descendants(answer)
|
||||
}
|
||||
return answer
|
||||
}
|
||||
}
|
||||
|
||||
class KFunction(val owner: KClassOrPackage, val name: String,
|
||||
|
||||
Reference in New Issue
Block a user