improved the kdoc format so it looks a bit more like kotlin code
This commit is contained in:
@@ -98,7 +98,7 @@ class KDocConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
protected class LongestFirstStringComparator() : Comparator<String> {
|
||||
private class LongestFirstStringComparator() : Comparator<String> {
|
||||
override fun compare(s1: String?, s2: String?): Int {
|
||||
return compareBy(s1, s2, { (s: String) -> s.length() }, { (s: String) -> s })
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.descriptors.ClassKind
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiDirectory
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities
|
||||
|
||||
|
||||
/**
|
||||
@@ -254,7 +255,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
protected fun addFunctions(owner: KClassOrPackage, scope: JetScope): Unit {
|
||||
fun addFunctions(owner: KClassOrPackage, scope: JetScope): Unit {
|
||||
try {
|
||||
val descriptors = scope.getAllDescriptors()
|
||||
for (descriptor in descriptors) {
|
||||
@@ -303,14 +304,16 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
||||
configureComments(function, descriptor)
|
||||
val receiver = descriptor.getReceiverParameter()
|
||||
if (receiver is ExtensionReceiver) {
|
||||
function.extensionClass = getType(receiver.getType())?.klass
|
||||
val receiverType = getType(receiver.getType())
|
||||
function.receiverType = receiverType
|
||||
function.extensionClass = receiverType?.klass
|
||||
}
|
||||
return function
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
protected fun addTypeParameters(answer: List<KTypeParameter>, descriptors: List<TypeParameterDescriptor?>): Unit {
|
||||
fun addTypeParameters(answer: List<KTypeParameter>, descriptors: List<TypeParameterDescriptor?>): Unit {
|
||||
for (typeParam in descriptors) {
|
||||
if (typeParam != null) {
|
||||
val p = createTypeParameter(typeParam)
|
||||
@@ -340,7 +343,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
||||
}
|
||||
|
||||
|
||||
protected fun fileFor(descriptor: DeclarationDescriptor): String? {
|
||||
fun fileFor(descriptor: DeclarationDescriptor): String? {
|
||||
val psiElement = getPsiElement(descriptor)
|
||||
return psiElement?.getContainingFile()?.getName()
|
||||
}
|
||||
@@ -844,7 +847,7 @@ class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
|
||||
|
||||
fun isApi(): Boolean {
|
||||
val visibility = descriptor.getVisibility()
|
||||
return visibility.isAPI()
|
||||
return visibility.isPublicAPI()
|
||||
}
|
||||
|
||||
val kind: String
|
||||
@@ -870,9 +873,9 @@ class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
|
||||
val visibility: String
|
||||
get() {
|
||||
val v = descriptor.getVisibility()
|
||||
return if (v == Visibility.PUBLIC) "public"
|
||||
else if (v == Visibility.PROTECTED) "protected"
|
||||
else if (v == Visibility.PRIVATE) "private"
|
||||
return if (v == Visibilities.PUBLIC) "public"
|
||||
else if (v == Visibilities.PROTECTED) "protected"
|
||||
else if (v == Visibilities.PRIVATE) "private"
|
||||
else ""
|
||||
}
|
||||
|
||||
@@ -911,6 +914,7 @@ class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
|
||||
class KFunction(val descriptor: CallableDescriptor, val owner: KClassOrPackage, val name: String,
|
||||
var returnType: KType,
|
||||
var parameters: List<KParameter>,
|
||||
var receiverType: KType? = null,
|
||||
var extensionClass: KClass? = null,
|
||||
var modifiers: List<String> = arrayList<String>(),
|
||||
var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>(),
|
||||
@@ -954,6 +958,8 @@ class KProperty(val owner: KClassOrPackage, val descriptor: PropertyDescriptor,
|
||||
|
||||
fun equals(other: KFunction) = name == other.name
|
||||
|
||||
fun isVar(): Boolean = descriptor.isVar()
|
||||
|
||||
fun toString() = "property $name"
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -95,9 +95,9 @@ function windowTitle()
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
||||
SUMMARY: <A HREF="#nested_class_summary">NESTED</A> | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
|
||||
SUMMARY: <A HREF="#nested_class_summary">NESTED</A> | PROPERTY | CONSTR | <A HREF="#method_summary">FUNCTION</A></FONT></TD>
|
||||
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
||||
DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
|
||||
DETAIL: PROPERTY | CONSTR | <A HREF="#method_detail">FUNCTION</A></FONT></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<A NAME="skip-navbar_top"></A>
|
||||
@@ -151,9 +151,9 @@ DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHO
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
||||
SUMMARY: <A HREF="#nested_class_summary">NESTED</A> | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
|
||||
SUMMARY: <A HREF="#nested_class_summary">NESTED</A> | PROPERTY | CONSTR | <A HREF="#method_summary">FUNCTION</A></FONT></TD>
|
||||
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
||||
DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
|
||||
DETAIL: PROPERTY | CONSTR | <A HREF="#method_detail">FUNCTION</A></FONT></TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<A NAME="skip-navbar_bottom"></A>
|
||||
|
||||
Vendored
+38
-12
@@ -18,6 +18,11 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||
|
||||
protected override fun relativePrefix(): String = pkg.nameAsRelativePath
|
||||
|
||||
val funKeyword = keyword("fun")
|
||||
val valKeyword = keyword("val")
|
||||
val varKeyword = keyword("var")
|
||||
|
||||
protected fun keyword(name: String): String = "<B>$name</B>"
|
||||
|
||||
fun printFunctionSummary(functions: Collection<KFunction>): Unit {
|
||||
if (functions.notEmpty()) {
|
||||
@@ -40,6 +45,7 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun printFunctionSummary(function: KFunction): Unit {
|
||||
val deprecated = if (function.deprecated) "<B>Deprecated.</B>" else ""
|
||||
print("""<TR BGCOLOR="white" CLASS="TableRowColor">
|
||||
@@ -50,18 +56,22 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||
<TR ALIGN="right" VALIGN="">
|
||||
<TD NOWRAP><FONT SIZE="-1">
|
||||
<CODE>""")
|
||||
print("$funKeyword ")
|
||||
printTypeParameters(function)
|
||||
println("""<BR>""")
|
||||
print(link(function.returnType))
|
||||
printReceiverType(function, "<BR>")
|
||||
println("""</CODE></FONT></TD>
|
||||
</TR>
|
||||
</TABLE>""")
|
||||
} else {
|
||||
print(link(function.returnType))
|
||||
print(funKeyword)
|
||||
printReceiverType(function)
|
||||
}
|
||||
// print receiver type
|
||||
println("""</CODE></FONT></TD>""")
|
||||
print("""<TD><CODE><B><A HREF="${href(function)}">${function.name}</A></B>""")
|
||||
printParameters(function)
|
||||
print(": ")
|
||||
print(link(function.returnType))
|
||||
println("""</CODE>""")
|
||||
println("")
|
||||
if (true) {
|
||||
@@ -75,6 +85,18 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||
println("""</TR>""")
|
||||
}
|
||||
|
||||
|
||||
fun printReceiverType(function: KFunction, prefix: String = " ", postfix: String = "", none: String = ""): Unit {
|
||||
val receiverType = function.receiverType
|
||||
if (receiverType != null) {
|
||||
print(prefix)
|
||||
print(link(receiverType))
|
||||
print(postfix)
|
||||
} else {
|
||||
print(none)
|
||||
}
|
||||
}
|
||||
|
||||
fun printFunctionDetail(functions: Collection<KFunction>): Unit {
|
||||
if (functions.notEmpty()) {
|
||||
println("""
|
||||
@@ -102,13 +124,15 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||
println("""<PRE>""")
|
||||
println("""<FONT SIZE="-1">""")
|
||||
printAnnotations(function.annotations)
|
||||
print("""</FONT>${function.modifiers.join(" ")} """)
|
||||
print("""</FONT>${function.modifiers.join(" ")} $funKeyword""")
|
||||
|
||||
printTypeParameters(function)
|
||||
printTypeParameters(function, " ")
|
||||
printReceiverType(function, " ", ".", " ")
|
||||
print("""<A HREF="${sourceHref(function)}"><B>${function.name}</B></A>""")
|
||||
printParameters(function)
|
||||
print(": ")
|
||||
print(link(function.returnType))
|
||||
|
||||
print(""" <A HREF="${sourceHref(function)}"><B>${function.name}</B></A>""")
|
||||
printParameters(function)
|
||||
val exlist = function.exceptions
|
||||
var first = true
|
||||
if (!exlist.isEmpty()) {
|
||||
@@ -163,8 +187,9 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||
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">
|
||||
<TD ALIGN="right" WIDTH="1%"><FONT SIZE="-1">
|
||||
<CODE>""")
|
||||
print(if (property.isVar()) varKeyword else valKeyword)
|
||||
/*
|
||||
if (!property.typeParameters.isEmpty()) {
|
||||
println("""<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
|
||||
@@ -181,9 +206,9 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||
print(link(property.returnType))
|
||||
}
|
||||
*/
|
||||
print(link(property.returnType))
|
||||
println("""</CODE></FONT></TD>""")
|
||||
print("""<TD><CODE><B><A HREF="${href(property)}">${property.name}</A></B>""")
|
||||
print("""<TD><CODE><B><A HREF="${href(property)}">${property.name}</A></B>: """)
|
||||
print(link(property.returnType))
|
||||
//printParameters(property)
|
||||
println("""</CODE>""")
|
||||
println("""""")
|
||||
@@ -192,9 +217,10 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||
println("""</TR>""")
|
||||
}
|
||||
|
||||
fun printTypeParameters(method: KFunction): Unit {
|
||||
fun printTypeParameters(method: KFunction, separator: String = ""): Unit {
|
||||
val typeParameters = method.typeParameters
|
||||
if (!typeParameters.isEmpty()) {
|
||||
print(separator)
|
||||
print("<")
|
||||
var separator = ""
|
||||
for (t in typeParameters) {
|
||||
@@ -212,7 +238,7 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() {
|
||||
}
|
||||
}
|
||||
}
|
||||
print("> ")
|
||||
print(">")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user