kdoc now has working interactive search of classes, functions, properties e.g. "map()" or "fun map" or "class Foo" etc

This commit is contained in:
James Strachan
2012-04-16 09:42:30 +01:00
parent 900c7b47ba
commit 4de778c6d6
5 changed files with 68 additions and 16 deletions
@@ -13,7 +13,7 @@ $(function(){
success: function( xmlResponse ) {
var data = $( "search", xmlResponse ).map(function() {
return {
value: $( "name", this ).text(),
value: $( "kind", this ).text() + " " + $( "name", this ).text(),
id: $( "href", this ).text()
};
}).get();
@@ -77,7 +77,7 @@
.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
.ui-autocomplete {
max-height: 100px;
max-height: 500px;
overflow-y: auto;
/* prevent horizontal scrollbar */
overflow-x: hidden;
@@ -88,9 +88,9 @@
* we use height instead, but this forces the menu to always be this tall
*/
* html .ui-autocomplete {
height: 100px;
height: 500px;
}
.NavBarCell1 label {
color: white;
}
}
@@ -691,15 +691,14 @@ class TemplateLinkRenderer(val annotated: KAnnotated, val template: KDocTemplate
// TODO really dirty hack alert!!!
// until the resolver is working, lets try adding a few prefixes :)
for (prefix in arrayList("java.lang", "java.util", "java.util.regex", "java.io", "jet"))
for (prefix in arrayList("java.lang", "java.util", "java.util.regex", "java.io", "jet")) {
if (href == null) {
href = resolveClassNameLink(prefix + "." + qualified)
if (href != null) {
break
}
}
/** TODO use break when KT-1523 is fixed
if (href != null) {
break
}
*/
}
if (href != null) {
answer.href = href
@@ -1129,6 +1128,8 @@ class KProperty(val owner: KClassOrPackage, val descriptor: PropertyDescriptor,
fun isVar(): Boolean = descriptor.isVar()
fun kind(): String = if (isVar()) "var" else "val"
fun toString() = "property $name"
}
@@ -53,6 +53,10 @@ abstract class KDocTemplate() : TextTemplate() {
return "${extensionsHref(pkg, c)}#${f.link}"
}
open fun extensionsHref(pkg: KPackage, c: KClass, f: KProperty): String {
return "${extensionsHref(pkg, c)}#${f.link}"
}
open fun sourceHref(klass: KClass): String {
if (klass.isLinkToSourceRepo()) {
return klass.sourceLink()
@@ -160,7 +164,7 @@ abstract class KDocTemplate() : TextTemplate() {
fun searchBox(): String =
""" <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1" ALIGN="right">
<label for="searchBox">Search: </label>
<input id="searchBox" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true" data-url="${relativePrefix()}search.xml">
<input id="searchBox" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true" size="50" data-url="${relativePrefix()}search.xml">
</TD>"""
@@ -5,19 +5,66 @@ import org.jetbrains.kotlin.template.*
import kotlin.io.*
import kotlin.util.*
import java.util.*
import org.jetbrains.kotlin.doc.model.KModel
import org.jetbrains.kotlin.doc.model.*
class SearchXmlTemplate(val model: KModel): KDocTemplate() {
class Search(val name: String, val href: String, val kind: String) {
fun toString() = "Search($name, $href, $kind)"
}
class SearchXmlTemplate(val model: KModel) : KDocTemplate() {
override fun render() {
val map = TreeMap<String, Search>()
fun add(name: String, href: String, kind: String): Unit {
val search = Search(name, href, kind)
if (!map.containsKey(name)) {
map.put(name, search)
}
}
fun add(owner: KClass, c: KFunction, href: String): Unit {
add("${c.name}() [${owner.name}]", href, "fun")
}
fun add(owner: KClass, c: KProperty, href: String): Unit {
add("${c.name} [${owner.name}]", href, c.kind())
}
for (c in model.classes) {
add("${c.simpleName} [${c.pkg.name}]", "${c.nameAsPath}.html", c.kind)
c.functions.forEach{ add(c, it, href(it)) }
c.properties.forEach{ add(c, it, href(it)) }
}
for (p in model.packages) {
val map = inheritedExtensionFunctions(p.functions)
val pmap = inheritedExtensionProperties(p.properties)
val classes = hashSet<KClass>()
classes.addAll(map.keySet())
classes.addAll(pmap.keySet())
for (c in classes) {
if (c != null) {
val functions = map.get(c).orEmpty()
val properties = pmap.get(c).orEmpty()
functions.forEach{ add(c, it, p.nameAsPath + "/" + extensionsHref(p, c, it)) }
functions.forEach{ add(c, it, p.nameAsPath + "/" + extensionsHref(p, c, it)) }
}
}
}
println("""<?xml version="1.0" encoding="UTF-8"?>
<searches>""")
for (c in model.classes) {
for (s in map.values()!!) {
println("""<search>
<href>${c.nameAsPath}.html</href>
<name>${c.name}</name>
<kind>${c.kind}</kind>
<href>${s.href}</href>
<name>${s.name}</name>
<kind>${s.kind}</kind>
</search>""")
}
println("""</searches>""")
}
}