show traits and class visibility properly in kdoc and hide non API stuff (i.e. public and protected is shown)

This commit is contained in:
James Strachan
2012-03-26 17:07:23 +01:00
parent 1c36fdf23c
commit 5ece48e3cc
9 changed files with 64 additions and 26 deletions
@@ -32,6 +32,8 @@ import org.pegdown.ast.ExpLinkNode
import org.pegdown.Extensions import org.pegdown.Extensions
import org.jetbrains.kotlin.doc.templates.KDocTemplate import org.jetbrains.kotlin.doc.templates.KDocTemplate
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl
import org.jetbrains.jet.lang.descriptors.Visibility
import org.jetbrains.jet.lang.descriptors.ClassKind
/** /**
@@ -645,7 +647,8 @@ class KPackage(model: KModel, val descriptor: NamespaceDescriptor,
//val classes = sortedMap<String,KClass>() //val classes = sortedMap<String,KClass>()
public val classMap: SortedMap<String, KClass> = TreeMap<String, KClass>() public val classMap: SortedMap<String, KClass> = TreeMap<String, KClass>()
public val classes: Collection<KClass> = classMap.values().sure() public val classes: Collection<KClass>
get() = classMap.values().sure().filter{ it.isApi() }
public val annotations: Collection<KClass> = ArrayList<KClass>() public val annotations: Collection<KClass> = ArrayList<KClass>()
@@ -700,7 +703,7 @@ class KType(val jetType: JetType, model: KModel, val klass: KClass?, val argumen
class KClass(val pkg: KPackage, val descriptor: ClassDescriptor, class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
val simpleName: String, val simpleName: String,
var kind: String = "class", var group: String = "Other", var group: String = "Other",
var annotations: List<KAnnotation> = arrayList<KAnnotation>(), var annotations: List<KAnnotation> = arrayList<KAnnotation>(),
var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>(), var typeParameters: List<KTypeParameter> = arrayList<KTypeParameter>(),
var since: String = "", var since: String = "",
@@ -715,6 +718,40 @@ class KClass(val pkg: KPackage, val descriptor: ClassDescriptor,
fun toString() = "$kind($name)" fun toString() = "$kind($name)"
fun isApi(): Boolean {
val visibility = descriptor.getVisibility()
return visibility.isAPI()
}
val kind: String
get() {
val k = descriptor.getKind()
return if (k == ClassKind.TRAIT) "trait"
else if (k == ClassKind.OBJECT) "object"
else if (k == ClassKind.ENUM_CLASS || k == ClassKind.ENUM_ENTRY) "enum"
else if (k == ClassKind.ANNOTATION_CLASS) "annotation"
else "class"
}
val kindCode: String
get() {
val k = descriptor.getKind()
return if (k == ClassKind.TRAIT) "trait"
else if (k == ClassKind.OBJECT) "object"
else if (k == ClassKind.ENUM_CLASS || k == ClassKind.ENUM_ENTRY) "enum class"
else if (k == ClassKind.ANNOTATION_CLASS) "class"
else "class"
}
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"
else ""
}
/** Link to the type which is relative if its a local type but could be a type in a different library or null if no link */ /** Link to the type which is relative if its a local type but could be a type in a different library or null if no link */
public var url: String? = null public var url: String? = null
get() { get() {
@@ -184,7 +184,7 @@ Class ${klass.simpleName}</H2>
<DL> <DL>
<DT><PRE><FONT SIZE="-1">""") <DT><PRE><FONT SIZE="-1">""")
printAnnotations(klass.annotations) printAnnotations(klass.annotations)
print("""</FONT>public class <A HREF="${sourceHref(klass)}"><B>${klass.simpleName}</B></A><DT>""") print("""</FONT>${klass.visibility} ${klass.kindCode} <A HREF="${sourceHref(klass)}"><B>${klass.simpleName}</B></A><DT>""")
if (!klass.baseClasses.isEmpty()) { if (!klass.baseClasses.isEmpty()) {
print("""extends """) print("""extends """)
for (bc in klass.baseClasses) { for (bc in klass.baseClasses) {
@@ -33,7 +33,7 @@ ${pkg.name} (${model.title})
<FONT size="+1" CLASS="FrameTitleFont"> <FONT size="+1" CLASS="FrameTitleFont">
<A HREF="${pkg.nameAsRelativePath}${pkg.nameAsPath}/package-summary.html" target="classFrame">${pkg.name}</A></FONT>""") <A HREF="${pkg.nameAsRelativePath}${pkg.nameAsPath}/package-summary.html" target="classFrame">${pkg.name}</A></FONT>""")
printClasses("interface", "Interfaces") printClasses("trait", "Traits")
printClasses("class", "Classes") printClasses("class", "Classes")
printClasses("enum", "Enums") printClasses("enum", "Enums")
printClasses("annotation", "Annotations") printClasses("annotation", "Annotations")
@@ -114,7 +114,7 @@ ${pkg.description(this)}
<P> <P>
""") """)
printClasses("interface", "Interfaces") printClasses("trait", "Traits")
printClasses("class", "Classes") printClasses("class", "Classes")
printClasses("enum", "Enums") printClasses("enum", "Enums")
printClasses("annotation", "Annotations") printClasses("annotation", "Annotations")
+1 -1
View File
@@ -232,7 +232,7 @@ inline fun <T> Reader.useLines(block: (Iterator<String>) -> T): T = this.buffere
*/ */
inline fun BufferedReader.lineIterator() : Iterator<String> = LineIterator(this) inline fun BufferedReader.lineIterator() : Iterator<String> = LineIterator(this)
protected class LineIterator(val reader: BufferedReader) : Iterator<String> { class LineIterator(val reader: BufferedReader) : Iterator<String> {
private var nextValue: String? = null private var nextValue: String? = null
private var done = false private var done = false
+2 -2
View File
@@ -199,7 +199,7 @@ fun Element.get(selector: String): List<Element> {
/** Returns an [[Iterator]] over the next siblings of this node */ /** Returns an [[Iterator]] over the next siblings of this node */
fun Node.nextSiblings() : Iterator<Node> = NextSiblingIterator(this) fun Node.nextSiblings() : Iterator<Node> = NextSiblingIterator(this)
protected class NextSiblingIterator(var node: Node) : AbstractIterator<Node>() { class NextSiblingIterator(var node: Node) : AbstractIterator<Node>() {
override fun computeNext(): Node? { override fun computeNext(): Node? {
val next = node.getNextSibling() val next = node.getNextSibling()
@@ -215,7 +215,7 @@ protected class NextSiblingIterator(var node: Node) : AbstractIterator<Node>() {
/** Returns an [[Iterator]] over the next siblings of this node */ /** Returns an [[Iterator]] over the next siblings of this node */
fun Node.previousSiblings() : Iterator<Node> = PreviousSiblingIterator(this) fun Node.previousSiblings() : Iterator<Node> = PreviousSiblingIterator(this)
protected class PreviousSiblingIterator(var node: Node) : AbstractIterator<Node>() { class PreviousSiblingIterator(var node: Node) : AbstractIterator<Node>() {
override fun computeNext(): Node? { override fun computeNext(): Node? {
val next = node.getPreviousSibling() val next = node.getPreviousSibling()
@@ -7,13 +7,13 @@ import java.util.Map
import java.util.HashMap import java.util.HashMap
import java.util.ArrayList import java.util.ArrayList
class ChangeEvent(val source: Any, val name: String, val oldValue: Any?, val newValue: Any?) { public class ChangeEvent(val source: Any, val name: String, val oldValue: Any?, val newValue: Any?) {
var propogationId: Any? = null var propogationId: Any? = null
fun toString() = "ChangeEvent($name, $oldValue, $newValue)" fun toString() = "ChangeEvent($name, $oldValue, $newValue)"
} }
trait ChangeListener { public trait ChangeListener {
fun onPropertyChange(event: ChangeEvent): Unit fun onPropertyChange(event: ChangeEvent): Unit
} }
@@ -22,7 +22,7 @@ trait ChangeListener {
* updates for easier binding to user interfaces, undo/redo command stacks and * updates for easier binding to user interfaces, undo/redo command stacks and
* change tracking mechanisms for persistence or distributed change notifications. * change tracking mechanisms for persistence or distributed change notifications.
*/ */
abstract class ChangeSupport { public abstract class ChangeSupport {
private var allListeners: List<ChangeListener>? = null private var allListeners: List<ChangeListener>? = null
private var nameListeners: Map<String, List<ChangeListener>>? = null private var nameListeners: Map<String, List<ChangeListener>>? = null
@@ -13,7 +13,7 @@ enum class State {
* A base class to simplify implementing iterators so that implementations only have to implement [[#computeNext()]] * A base class to simplify implementing iterators so that implementations only have to implement [[#computeNext()]]
* to implement the iterator, calling [[done()]] when the iteration is complete. * to implement the iterator, calling [[done()]] when the iteration is complete.
*/ */
abstract class AbstractIterator<T>: java.util.Iterator<T> { public abstract class AbstractIterator<T>: java.util.Iterator<T> {
var state: State = State.NotReady var state: State = State.NotReady
var next: T? = null var next: T? = null
@@ -30,6 +30,7 @@ class GenerateSiteTest : TestCase() {
val config = args.docConfig val config = args.docConfig
config.title = "Kotlin API ($version)" config.title = "Kotlin API ($version)"
config.version = version config.version = version
config.ignorePackages.add("kotlin.support")
config.ignorePackages.add("org.jetbrains.kotlin") config.ignorePackages.add("org.jetbrains.kotlin")
config.ignorePackages.add("java") config.ignorePackages.add("java")
config.ignorePackages.add("jet") config.ignorePackages.add("jet")