added support for properties in kdoc
This commit is contained in:
@@ -241,6 +241,7 @@ DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHO
|
|||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printPropertySummary(klass.properties)
|
||||||
printFunctionSummary(klass.functions)
|
printFunctionSummary(klass.functions)
|
||||||
printFunctionDetail(klass.functions)
|
printFunctionDetail(klass.functions)
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.jetbrains.kotlin.model.KPackage
|
|||||||
import org.jetbrains.kotlin.template.TextTemplate
|
import org.jetbrains.kotlin.template.TextTemplate
|
||||||
import org.jetbrains.kotlin.model.KFunction
|
import org.jetbrains.kotlin.model.KFunction
|
||||||
import java.util.Collection
|
import java.util.Collection
|
||||||
|
import org.jetbrains.kotlin.model.KProperty
|
||||||
|
|
||||||
abstract class KDocTemplate() : TextTemplate() {
|
abstract class KDocTemplate() : TextTemplate() {
|
||||||
fun rootHref(pkg: KPackage): String {
|
fun rootHref(pkg: KPackage): String {
|
||||||
@@ -23,11 +24,6 @@ abstract class KDocTemplate() : TextTemplate() {
|
|||||||
return "${rootHref(c.pkg)}${c.nameAsPath}.html$postfix"
|
return "${rootHref(c.pkg)}${c.nameAsPath}.html$postfix"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun extensionsHref(pkg: KPackage, c: KClass): String {
|
|
||||||
// is inside the pkg so no need to use it...
|
|
||||||
return "${c.nameAsPath}-extensions.html"
|
|
||||||
}
|
|
||||||
|
|
||||||
fun href(f: KFunction): String {
|
fun href(f: KFunction): String {
|
||||||
return if (f.owner is KClass) {
|
return if (f.owner is KClass) {
|
||||||
"${href(f.owner)}#${f.link}"
|
"${href(f.owner)}#${f.link}"
|
||||||
@@ -36,6 +32,19 @@ abstract class KDocTemplate() : TextTemplate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun href(f: KProperty): String {
|
||||||
|
return if (f.owner is KClass) {
|
||||||
|
"${href(f.owner)}#${f.link}"
|
||||||
|
} else {
|
||||||
|
"package-summary.html#${f.link}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun extensionsHref(pkg: KPackage, c: KClass): String {
|
||||||
|
// is inside the pkg so no need to use it...
|
||||||
|
return "${c.nameAsPath}-extensions.html"
|
||||||
|
}
|
||||||
|
|
||||||
fun sourceHref(f: KFunction): String {
|
fun sourceHref(f: KFunction): String {
|
||||||
return if (f.owner is KClass) {
|
return if (f.owner is KClass) {
|
||||||
"${rootHref(f.owner.pkg)}src-html/${f.owner.simpleName}.html#line.${f.sourceLine}"
|
"${rootHref(f.owner.pkg)}src-html/${f.owner.simpleName}.html#line.${f.sourceLine}"
|
||||||
|
|||||||
+86
-32
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.model.KPackage
|
|||||||
import org.jetbrains.kotlin.model.KClass
|
import org.jetbrains.kotlin.model.KClass
|
||||||
import org.jetbrains.kotlin.model.KFunction
|
import org.jetbrains.kotlin.model.KFunction
|
||||||
import org.jetbrains.kotlin.model.KAnnotation
|
import org.jetbrains.kotlin.model.KAnnotation
|
||||||
|
import org.jetbrains.kotlin.model.KProperty
|
||||||
|
|
||||||
|
|
||||||
abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||||
@@ -19,7 +20,7 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
|||||||
|
|
||||||
fun printFunctionSummary(functions: Collection<KFunction>): Unit {
|
fun printFunctionSummary(functions: Collection<KFunction>): Unit {
|
||||||
if (functions.notEmpty()) {
|
if (functions.notEmpty()) {
|
||||||
println("""<!-- ========== METHOD SUMMARY =========== -->
|
println("""<!-- ========== FUNCTION SUMMARY =========== -->
|
||||||
|
|
||||||
<A NAME="method_summary"><!-- --></A>
|
<A NAME="method_summary"><!-- --></A>
|
||||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||||
@@ -38,27 +39,6 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun printFunctionDetail(functions: Collection<KFunction>): Unit {
|
|
||||||
if (functions.notEmpty()) {
|
|
||||||
println("""
|
|
||||||
|
|
||||||
<!-- ============ METHOD DETAIL ========== -->
|
|
||||||
|
|
||||||
<A NAME="method_detail"><!-- --></A>
|
|
||||||
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
||||||
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
||||||
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
|
||||||
<B>Method Detail</B></FONT></TH>
|
|
||||||
</TR>
|
|
||||||
</TABLE>
|
|
||||||
""")
|
|
||||||
|
|
||||||
for (f in functions) {
|
|
||||||
printFunctionDetail(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun printFunctionSummary(method: KFunction): Unit {
|
fun printFunctionSummary(method: KFunction): Unit {
|
||||||
val deprecated = if (method.deprecated) "<B>Deprecated.</B>" else ""
|
val deprecated = if (method.deprecated) "<B>Deprecated.</B>" else ""
|
||||||
print("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
print("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||||
@@ -88,19 +68,40 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
|||||||
println("</TR>")
|
println("</TR>")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun printFunctionDetail(method: KFunction): Unit {
|
fun printFunctionDetail(functions: Collection<KFunction>): Unit {
|
||||||
println("<A NAME=\"${method.name}{${method.parameterTypeText}})\"><!-- --></A><A NAME=\"${method.name}(${method.typeParametersText})\"><!-- --></A><H3>")
|
if (functions.notEmpty()) {
|
||||||
println("${method.name}</H3>")
|
println("""
|
||||||
|
|
||||||
|
<!-- ============ FUNCTION DETAIL ========== -->
|
||||||
|
|
||||||
|
<A NAME="method_detail"><!-- --></A>
|
||||||
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||||
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||||
|
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
||||||
|
<B>Method Detail</B></FONT></TH>
|
||||||
|
</TR>
|
||||||
|
</TABLE>
|
||||||
|
""")
|
||||||
|
|
||||||
|
for (f in functions) {
|
||||||
|
printFunctionDetail(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printFunctionDetail(function: KFunction): Unit {
|
||||||
|
println("<A NAME=\"${function.name}{${function.parameterTypeText}})\"><!-- --></A><A NAME=\"${function.name}(${function.typeParametersText})\"><!-- --></A><H3>")
|
||||||
|
println("${function.name}</H3>")
|
||||||
println("<PRE>")
|
println("<PRE>")
|
||||||
println("<FONT SIZE=\"-1\">")
|
println("<FONT SIZE=\"-1\">")
|
||||||
printAnnotations(method.annotations)
|
printAnnotations(function.annotations)
|
||||||
print("</FONT>${method.modifiers.join(" ")} ")
|
print("</FONT>${function.modifiers.join(" ")} ")
|
||||||
|
|
||||||
printTypeParameters(method)
|
printTypeParameters(function)
|
||||||
print(link(method.returnType))
|
print(link(function.returnType))
|
||||||
print(" <A HREF=\"${sourceHref(method)}\"><B>${method.name}</B></A>")
|
print(" <A HREF=\"${sourceHref(function)}\"><B>${function.name}</B></A>")
|
||||||
printParameters(method)
|
printParameters(function)
|
||||||
val exlist = method.exceptions
|
val exlist = function.exceptions
|
||||||
var first = true
|
var first = true
|
||||||
if (!exlist.isEmpty()) {
|
if (!exlist.isEmpty()) {
|
||||||
println(" throws ");
|
println(" throws ");
|
||||||
@@ -129,6 +130,59 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
|||||||
println("<HR>")
|
println("<HR>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun printPropertySummary(properties: Collection<KProperty>): Unit {
|
||||||
|
if (properties.notEmpty()) {
|
||||||
|
println("""<!-- ========== PROPERTY SUMMARY =========== -->
|
||||||
|
|
||||||
|
<A NAME="method_summary"><!-- --></A>
|
||||||
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
||||||
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
||||||
|
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
||||||
|
<B>Property Summary</B></FONT></TH>
|
||||||
|
</TR>""")
|
||||||
|
|
||||||
|
for (f in properties) {
|
||||||
|
printPropertySummary(f)
|
||||||
|
}
|
||||||
|
println("""</TABLE>
|
||||||
|
|
||||||
|
<P>
|
||||||
|
""")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printPropertySummary(property: KProperty): Unit {
|
||||||
|
val deprecated = if (property.deprecated) "<B>Deprecated.</B>" else ""
|
||||||
|
print("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||||
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
||||||
|
<CODE>""")
|
||||||
|
/*
|
||||||
|
if (!property.typeParameters.isEmpty()) {
|
||||||
|
println("""<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
|
||||||
|
<TR ALIGN="right" VALIGN="">
|
||||||
|
<TD NOWRAP><FONT SIZE="-1">
|
||||||
|
<CODE>""")
|
||||||
|
printTypeParameters(property)
|
||||||
|
println("<BR>")
|
||||||
|
print(link(property.returnType))
|
||||||
|
println("""</CODE></FONT></TD>
|
||||||
|
</TR>
|
||||||
|
</TABLE>""")
|
||||||
|
} else {
|
||||||
|
print(link(property.returnType))
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
print(link(property.returnType))
|
||||||
|
println("</CODE></FONT></TD>")
|
||||||
|
print("<TD><CODE><B><A HREF=\"${href(property)}\">${property.name}</A></B>")
|
||||||
|
//printParameters(property)
|
||||||
|
println("</CODE>")
|
||||||
|
println("")
|
||||||
|
println("<BR>")
|
||||||
|
println(" ${deprecated} ${property.detailedDescription}</TD>")
|
||||||
|
println("</TR>")
|
||||||
|
}
|
||||||
|
|
||||||
fun printTypeParameters(method: KFunction): Unit {
|
fun printTypeParameters(method: KFunction): Unit {
|
||||||
val typeParameters = method.typeParameters
|
val typeParameters = method.typeParameters
|
||||||
if (!typeParameters.isEmpty()) {
|
if (!typeParameters.isEmpty()) {
|
||||||
|
|||||||
@@ -143,17 +143,21 @@ class KModel(var context: BindingContext, var title: String = "Documentation", v
|
|||||||
try {
|
try {
|
||||||
val descriptors = scope.getAllDescriptors()
|
val descriptors = scope.getAllDescriptors()
|
||||||
for (descriptor in descriptors) {
|
for (descriptor in descriptors) {
|
||||||
if (descriptor is CallableDescriptor) {
|
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)
|
||||||
|
owner.properties.add(property)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (descriptor is CallableDescriptor) {
|
||||||
val function = createFunction(owner, descriptor)
|
val function = createFunction(owner, descriptor)
|
||||||
if (function != null) {
|
if (function != null) {
|
||||||
list.add(function)
|
list.add(function)
|
||||||
}
|
}
|
||||||
} else if (descriptor is PropertyDescriptor) {
|
|
||||||
if (owner is KClass) {
|
|
||||||
val name = descriptor.getName()
|
|
||||||
val property = KProperty(descriptor, name)
|
|
||||||
owner.properties.add(property)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
@@ -261,7 +265,9 @@ abstract class KAnnotated {
|
|||||||
public open var description: String = ""
|
public open var description: String = ""
|
||||||
|
|
||||||
public open var detailedDescription: String = ""
|
public open var detailedDescription: String = ""
|
||||||
get() = if ($detailedDescription.notEmpty()) $detailedDescription else description
|
get() = if ($detailedDescription.notEmpty()) $detailedDescription else description
|
||||||
|
|
||||||
|
public open var deprecated: Boolean = false
|
||||||
}
|
}
|
||||||
|
|
||||||
class KPackage(val model: KModel, val descriptor: NamespaceDescriptor,
|
class KPackage(val model: KModel, val descriptor: NamespaceDescriptor,
|
||||||
@@ -401,7 +407,6 @@ class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
|
|||||||
|
|
||||||
class KFunction(val owner: KClassOrPackage, val name: String,
|
class KFunction(val owner: KClassOrPackage, val name: String,
|
||||||
var returnType: KClass,
|
var returnType: KClass,
|
||||||
var deprecated: Boolean = false,
|
|
||||||
var extensionClass: KClass? = null,
|
var extensionClass: KClass? = null,
|
||||||
var modifiers: List<String> = arrayList<String>(),
|
var modifiers: List<String> = arrayList<String>(),
|
||||||
var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>(),
|
var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>(),
|
||||||
@@ -422,7 +427,6 @@ class KFunction(val owner: KClassOrPackage, val name: String,
|
|||||||
|
|
||||||
fun toString() = "fun ($name)"
|
fun toString() = "fun ($name)"
|
||||||
|
|
||||||
/** TODO generate a link with the argument type names */
|
|
||||||
public val link: String = "$name($parameterTypeText)"
|
public val link: String = "$name($parameterTypeText)"
|
||||||
|
|
||||||
/** Returns a list of generic type parameter names kinds like "A, I" */
|
/** Returns a list of generic type parameter names kinds like "A, I" */
|
||||||
@@ -440,10 +444,13 @@ class KFunction(val owner: KClassOrPackage, val name: String,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class KProperty(var descriptor: PropertyDescriptor, var name: String) : KAnnotated(), Comparable<KProperty> {
|
class KProperty(val owner: KClassOrPackage, val descriptor: PropertyDescriptor, val name: String,
|
||||||
|
val returnType: KClass) : KAnnotated(), Comparable<KProperty> {
|
||||||
|
|
||||||
override fun compareTo(other: KProperty): Int = name.compareTo(other.name)
|
override fun compareTo(other: KProperty): Int = name.compareTo(other.name)
|
||||||
|
|
||||||
|
public val link: String = "$name"
|
||||||
|
|
||||||
fun equals(other: KFunction) = name == other.name
|
fun equals(other: KFunction) = name == other.name
|
||||||
|
|
||||||
fun toString() = "property $name}"
|
fun toString() = "property $name}"
|
||||||
|
|||||||
Reference in New Issue
Block a user