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.util.slicedmap.WritableSlice
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils
|
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")
|
println("Generating kdoc to $outputDir")
|
||||||
run("allclasses-frame.html", AllClassesFrameTemplate(model, " target=\"classFrame\""))
|
run("allclasses-frame.html", AllClassesFrameTemplate(model, " target=\"classFrame\""))
|
||||||
run("allclasses-noframe.html", AllClassesFrameTemplate(model))
|
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) {
|
protected fun log(text: String) {
|
||||||
println(text)
|
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() {
|
class KDoc(val outputDir: File) : KModelCompilerPlugin() {
|
||||||
|
|
||||||
override fun processModel(model: KModel) {
|
override fun processModel(model: KModel) {
|
||||||
val generator = KDocGenerator(model, outputDir)
|
// TODO allow this to be configured; maybe we use configuration on the KotlinModule
|
||||||
generator.execute()
|
// 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 (descriptor is PropertyDescriptor) {
|
||||||
if (owner is KClass) {
|
if (owner is KClass) {
|
||||||
val name = descriptor.getName()
|
val name = descriptor.getName()
|
||||||
println("Found Property on owner: $owner with name: $name")
|
|
||||||
val returnType = getClass(descriptor.getReturnType())
|
val returnType = getClass(descriptor.getReturnType())
|
||||||
if (returnType != null) {
|
if (returnType != null) {
|
||||||
val property = KProperty(owner, descriptor, name, returnType)
|
val property = KProperty(owner, descriptor, name, returnType)
|
||||||
|
|||||||
Reference in New Issue
Block a user