diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocGenerator.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocGenerator.kt index 1e76af44ce9..a5f3f1dbecc 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocGenerator.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocGenerator.kt @@ -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)) + } + } + } + } diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt index b4a8eaaba32..6e28887791c 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/ClassExtensionsTemplate.kt @@ -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) : ClassTemplate(m, p, k) { +class ClassExtensionsTemplate(m: KModel, p: KPackage, k: KClass, var functions: Collection) : ClassTemplate(m, p, k) { override fun pageTitle(): String = "${klass.name} Extensions fom ${pkg.name} (${model.title})" diff --git a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt index 08f199efc9e..322e3420bae 100644 --- a/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt +++ b/kdoc/src/main/kotlin/org/jetbrains/kotlin/model/KotlinModel.kt @@ -33,16 +33,45 @@ fun qualifiedName(descriptor: DeclarationDescriptor?): String { } } -fun extensionFunctions(functions: Collection): SortedMap> { +// TODO for some reason the SortedMap causes kotlin to freak out a little :) +fun inheritedExtensionFunctions(functions: Collection): Map> { + //fun inheritedExtensionFunctions(functions: Collection): SortedMap> { + 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>() + 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): Map> { + //fun extensionFunctions(functions: Collection): SortedMap> { val map = TreeMap>() 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 = LinkedHashSet()): Set { + answer.addAll(baseClasses) + for (b in baseClasses) { + b.descendants(answer) + } + return answer + } } class KFunction(val owner: KClassOrPackage, val name: String,