basic working kdoc for packages, classes, methods. Still needs work for extension methods, comments, value and type parameters and modifiers, but its a start ;)
This commit is contained in:
@@ -36,6 +36,78 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../dist/kotlinc/lib/annotations.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../dist/kotlinc/lib/asm-commons.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../dist/kotlinc/lib/asm-util-3.3.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../dist/kotlinc/lib/asm.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../dist/kotlinc/lib/cli-10.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../dist/kotlinc/lib/guava-11.0.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../dist/kotlinc/lib/picocontainer.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../dist/kotlinc/lib/trove4j.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -14,6 +14,13 @@ import java.util.HashSet
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.model.KMethod
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.kotlin.model.KClass
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor
|
||||
|
||||
class KDoc(val outputDir: File) : KDocSupport() {
|
||||
val model = KModel()
|
||||
@@ -39,24 +46,73 @@ class KDoc(val outputDir: File) : KDocSupport() {
|
||||
|
||||
override fun addClass(namespace: NamespaceDescriptor?, classElement: ClassDescriptor?) {
|
||||
if (namespace != null && classElement != null) {
|
||||
//val docComment = getDocCommentFor(classElement.sure()) ?: "";
|
||||
val name = classElement.getName()
|
||||
val namespaceName = namespace.getName() ?: ""
|
||||
val pkg = model.getPackage(namespaceName)
|
||||
if (name != null) {
|
||||
println("Found namespace ${namespaceName} class: ${name}")
|
||||
pkg.getClass(name)
|
||||
val klass = getOrCreateClass(classElement)
|
||||
if (klass != null) {
|
||||
klass.pkg.local = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun generate() {
|
||||
/*
|
||||
for (classElement in allClasses) {
|
||||
if (classElement != null) {
|
||||
protected fun containerName(descriptor: DeclarationDescriptor): String {
|
||||
val container = descriptor.containingDeclaration
|
||||
if (container == null || container is ModuleDescriptor || container is JavaNamespaceDescriptor) {
|
||||
return ""
|
||||
} else {
|
||||
val parent = containerName(container)
|
||||
val name = container.getName() ?: ""
|
||||
val answer = if (parent.length() > 0) parent + "." + name else name
|
||||
return if (answer.startsWith(".")) answer.substring(1) else answer
|
||||
}
|
||||
}
|
||||
|
||||
protected fun getOrCreateClass(classElement: ClassDescriptor): KClass? {
|
||||
//val docComment = getDocCommentFor(classElement.sure()) ?: "";
|
||||
val container = classElement.containingDeclaration
|
||||
val namespaceName = containerName(classElement)
|
||||
val pkg = model.getPackage(namespaceName)
|
||||
val name = classElement.getName()
|
||||
if (name != null) {
|
||||
val klass = pkg.getClass(name)
|
||||
klass.initialise {
|
||||
val descriptors = classElement.getDefaultType().getMemberScope().getAllDescriptors()
|
||||
for (descriptor in descriptors) {
|
||||
if (descriptor is CallableDescriptor) {
|
||||
val method = createMethod(descriptor)
|
||||
if (method != null) {
|
||||
klass.methods.add(method)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
return klass
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
protected fun createMethod(descriptor: CallableDescriptor): KMethod? {
|
||||
val returnType = getType(descriptor.getReturnType())
|
||||
if (returnType != null) {
|
||||
val method = KMethod(descriptor.getName() ?: "null", returnType)
|
||||
val params = descriptor.getValueParameters()
|
||||
for (param in params) {
|
||||
|
||||
}
|
||||
return method
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
protected fun getType(aType: JetType?): KClass? {
|
||||
if (aType != null) {
|
||||
val classifierDescriptor = aType.constructor.declarationDescriptor
|
||||
if (classifierDescriptor is ClassDescriptor) {
|
||||
return getOrCreateClass(classifierDescriptor)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun generate() {
|
||||
if (!model.packages.isEmpty()) {
|
||||
val generator = KDocGenerator(model, outputDir)
|
||||
generator.execute()
|
||||
@@ -79,6 +135,7 @@ class KDoc(val outputDir: File) : KDocSupport() {
|
||||
class KDocGenerator(val model: KModel, val outputDir: File) {
|
||||
|
||||
fun execute(): Unit {
|
||||
println("Generating kdoc to $outputDir")
|
||||
run("allclasses-frame.html", AllClassesFrameTemplate(model, " target=\"classFrame\""))
|
||||
run("allclasses-noframe.html", AllClassesFrameTemplate(model))
|
||||
// run("constant-values.html", ConstantValuesTemplate(model))
|
||||
|
||||
@@ -35,7 +35,10 @@ import java.util.Set;
|
||||
* TODO This class is written in Java for now to work around a few gremlins in Kotlin...
|
||||
*/
|
||||
public abstract class KDocSupport implements CompilerPlugin {
|
||||
protected BindingContext context;
|
||||
|
||||
public void processFiles(BindingContext context, List<JetFile> sources) {
|
||||
this.context = context;
|
||||
Set<NamespaceDescriptor> allNamespaces = new HashSet<NamespaceDescriptor>();
|
||||
for (JetFile source : sources) {
|
||||
// We retrieve a descriptor by a PSI element from the context
|
||||
|
||||
@@ -285,21 +285,24 @@ Copyright © 2010-2012. All Rights Reserved.
|
||||
|
||||
fun printMethodSummary(method: KMethod): Unit {
|
||||
val deprecated = if (method.deprecated) "<B>Deprecated.</B>" else ""
|
||||
println("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
print("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>
|
||||
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
|
||||
<TR ALIGN="right" VALIGN="">
|
||||
<TD NOWRAP><FONT SIZE="-1">
|
||||
<CODE>""")
|
||||
printTypeParameters(method)
|
||||
|
||||
println("<BR>")
|
||||
print(link(method.returnType))
|
||||
println("""</CODE></FONT></TD>
|
||||
if (!method.typeParameters.isEmpty()) {
|
||||
println("""<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
|
||||
<TR ALIGN="right" VALIGN="">
|
||||
<TD NOWRAP><FONT SIZE="-1">
|
||||
<CODE>""")
|
||||
printTypeParameters(method)
|
||||
println("<BR>")
|
||||
print(link(method.returnType))
|
||||
println("""</CODE></FONT></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</CODE></FONT></TD>""")
|
||||
</TABLE>""")
|
||||
} else {
|
||||
print(link(method.returnType))
|
||||
}
|
||||
println("</CODE></FONT></TD>")
|
||||
print("<TD><CODE><B><A HREF=\"${pkg.nameAsRelativePath}${klass.nameAsPath}.html#${method.link}\">${method.name}</A></B>")
|
||||
printParameters(method)
|
||||
println("</CODE>")
|
||||
@@ -312,9 +315,9 @@ println("""</CODE></FONT></TD>
|
||||
|
||||
fun printMethodDetail(method: KMethod): Unit {
|
||||
println("<A NAME=\"${method.name}{${method.parameters.map{it.klass.name}})\"><!-- --></A><A NAME=\"${method.name}(${method.typeParametersText})\"><!-- --></A><H3>")
|
||||
println("${method.name}</H3>")
|
||||
println("<PRE>")
|
||||
println("<FONT SIZE=\"-1\">")
|
||||
println("${method.name}</H3>")
|
||||
println("<PRE>")
|
||||
println("<FONT SIZE=\"-1\">")
|
||||
printAnnotations(method.annotations)
|
||||
print("</FONT>${method.modifiers.join(" ")} ")
|
||||
|
||||
@@ -348,7 +351,7 @@ println("<FONT SIZE=\"-1\">")
|
||||
</DD>
|
||||
</DL>
|
||||
*/
|
||||
println("<HR>")
|
||||
println("<HR>")
|
||||
}
|
||||
|
||||
fun printTypeParameters(method: KMethod): Unit {
|
||||
|
||||
@@ -11,7 +11,12 @@ class KModel(var title: String = "Documentation", var version: String = "TODO")
|
||||
//val packages = sortedMap<String,KPackage>()
|
||||
public val packageMap: SortedMap<String,KPackage> = TreeMap<String,KPackage>()
|
||||
|
||||
public val packages: Collection<KPackage> = packageMap.values().sure()
|
||||
public val allPackages: Collection<KPackage>
|
||||
get() = packageMap.values().sure()
|
||||
|
||||
/** Returns the local packages */
|
||||
public val packages: Collection<KPackage>
|
||||
get() = allPackages.filter{ it.local }
|
||||
|
||||
public val classes: Collection<KClass>
|
||||
get() = packages.flatMap{ it.classes }
|
||||
@@ -43,7 +48,8 @@ class KModel(var title: String = "Documentation", var version: String = "TODO")
|
||||
}
|
||||
|
||||
class KPackage(val model: KModel, val name: String, var external: Boolean = false,
|
||||
var description: String = "", var detailedDescription: String = "") : Comparable<KPackage> {
|
||||
var description: String = "", var detailedDescription: String = "",
|
||||
var local: Boolean = false) : Comparable<KPackage> {
|
||||
override fun compareTo(other: KPackage): Int = name.compareTo(other.name)
|
||||
|
||||
fun equals(other: KPackage) = name == other.name
|
||||
@@ -124,6 +130,16 @@ class KClass(val pkg: KPackage, val simpleName: String,
|
||||
var nestedClasses: List<KClass> = arrayList<KClass>(),
|
||||
var sourceLine: Int = 2) : Comparable<KClass> {
|
||||
|
||||
private var _initialised = false
|
||||
|
||||
/** Runs the initialisation block if this class has not yet been initialised */
|
||||
fun initialise(fn: () -> Unit): Unit {
|
||||
if (!_initialised) {
|
||||
_initialised = true
|
||||
fn()
|
||||
}
|
||||
}
|
||||
|
||||
override fun compareTo(other: KClass): Int = name.compareTo(other.name)
|
||||
|
||||
fun equals(other: KClass) = name == other.name
|
||||
|
||||
Reference in New Issue
Block a user