refactored the kdoc implementation to introduce a Doclet trait so its easy to plugin new documentation generators or use different templates etc
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package org.jetbrains.kotlin.doc
|
||||
|
||||
import org.jetbrains.kotlin.model.KModel
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* A simple plugin to KDoc to generate information from the model into a directory
|
||||
* which can be implemented using any kind of layout or format.
|
||||
*/
|
||||
trait Doclet {
|
||||
fun generate(model: KModel, outputDir: File): Unit
|
||||
}
|
||||
+23
-20
@@ -31,9 +31,30 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils
|
||||
|
||||
class KDocGenerator(val model: KModel, val outputDir: File) {
|
||||
/** Creates JavaDoc style HTML output from the model */
|
||||
class JavadocStyleHtmlDoclet() : Doclet {
|
||||
|
||||
override fun generate(model: KModel, outputDir: File): Unit {
|
||||
fun run(fileName: String, template: TextTemplate): Unit {
|
||||
val file = File(outputDir, fileName)
|
||||
file.getParentFile()?.mkdirs()
|
||||
|
||||
log("Generating $fileName")
|
||||
template.renderTo(file)
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun execute(): Unit {
|
||||
println("Generating kdoc to $outputDir")
|
||||
run("allclasses-frame.html", AllClassesFrameTemplate(model, " target=\"classFrame\""))
|
||||
run("allclasses-noframe.html", AllClassesFrameTemplate(model))
|
||||
@@ -60,27 +81,9 @@ class KDocGenerator(val model: KModel, val outputDir: File) {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun run(fileName: String, template: TextTemplate): Unit {
|
||||
val file = File(outputDir, fileName)
|
||||
file.getParentFile()?.mkdirs()
|
||||
|
||||
log("Generating $fileName")
|
||||
template.renderTo(file)
|
||||
}
|
||||
|
||||
protected fun log(text: String) {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,9 @@ import org.jetbrains.jet.lang.resolve.BindingContextUtils
|
||||
class KDoc(val outputDir: File) : KModelCompilerPlugin() {
|
||||
|
||||
override fun processModel(model: KModel) {
|
||||
val generator = KDocGenerator(model, outputDir)
|
||||
generator.execute()
|
||||
// TODO allow this to be configured; maybe we use configuration on the KotlinModule
|
||||
// to define what doclets to use?
|
||||
val generator = JavadocStyleHtmlDoclet()
|
||||
generator.generate(model, outputDir)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,6 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
|
||||
if (descriptor is PropertyDescriptor) {
|
||||
if (owner is KClass) {
|
||||
val name = descriptor.getName()
|
||||
println("Found Property on owner: $owner with name: $name")
|
||||
val returnType = getClass(descriptor.getReturnType())
|
||||
if (returnType != null) {
|
||||
val property = KProperty(owner, descriptor, name, returnType)
|
||||
|
||||
Reference in New Issue
Block a user