Skip to content

Commit

Permalink
Revert doclet reformatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
prbprbprb committed Oct 14, 2024
1 parent 7249cb3 commit cb7d84e
Show file tree
Hide file tree
Showing 7 changed files with 602 additions and 546 deletions.
70 changes: 41 additions & 29 deletions api-doclet/src/main/kotlin/org/conscrypt/doclet/ClassIndex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,56 @@ import javax.lang.model.element.TypeElement
import kotlin.streams.toList

class ClassIndex {
private val index = mutableMapOf<String, ClassInfo>()
private val index = mutableMapOf<String, ClassInfo>()

private fun put(classInfo: ClassInfo) {
index[classInfo.qualifiedName] = classInfo
}

fun put(element: Element) {
put(ClassInfo(element as TypeElement))
}

fun get(qualifiedName: String) = index[qualifiedName]
private fun put(classInfo: ClassInfo) {
index[classInfo.qualifiedName] = classInfo
}

fun contains(qualifiedName: String) = index.containsKey(qualifiedName)
fun put(element: Element) {
put(ClassInfo(element as TypeElement))
}

fun find(name: String) = if (contains(name)) get(name) else findSimple(name)
fun get(qualifiedName: String) = index[qualifiedName]
fun contains(qualifiedName: String) = index.containsKey(qualifiedName)
fun find(name: String) = if (contains(name)) get(name) else findSimple(name)
private fun findSimple(name: String) = classes().firstOrNull { it.simpleName == name } // XXX dups

private fun findSimple(name: String) = classes().firstOrNull { it.simpleName == name } // XXX dups
fun classes(): Collection<ClassInfo> = index.values

fun classes(): Collection<ClassInfo> = index.values
fun addVisible(elements: Set<Element>) {
elements
.filterIsInstance<TypeElement>()
.filter(Element::isVisibleType)
.forEach(::put)
}

fun addVisible(elements: Set<Element>) {
elements.filterIsInstance<TypeElement>().filter(Element::isVisibleType).forEach(::put)
}
private fun packages(): List<String> = index.values.stream()
.map { it.packageName }
.distinct()
.sorted()
.toList()

private fun packages(): List<String> =
index.values.stream().map { it.packageName }.distinct().sorted().toList()
private fun classesForPackage(packageName: String) = index.values.stream()
.filter { it.packageName == packageName }
.sorted()
.toList()

private fun classesForPackage(packageName: String) =
index.values.stream().filter { it.packageName == packageName }.sorted().toList()
fun generateHtml():String = html {
packages().forEach { packageName ->
div("package-section") {
h2("Package $packageName", "package-name")
ul("class-list") {
classesForPackage(packageName)
.forEach { c ->
li {
a(c.fileName, c.simpleName)
}
}

fun generateHtml(): String = html {
packages().forEach { packageName ->
div("package-section") {
h2("Package $packageName", "package-name")
ul("class-list") {
classesForPackage(packageName).forEach { c -> li { a(c.fileName, c.simpleName) } }
}
}
}
}
}
}
}

169 changes: 95 additions & 74 deletions api-doclet/src/main/kotlin/org/conscrypt/doclet/ClassInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,96 +20,117 @@ import javax.lang.model.element.Element
import javax.lang.model.element.ExecutableElement
import javax.lang.model.element.TypeElement


data class ClassInfo(val element: TypeElement) : Comparable<ClassInfo> {
val simpleName = element.simpleName.toString()
val qualifiedName = element.qualifiedName.toString()
val packageName = FilterDoclet.elementUtils.getPackageOf(element).qualifiedName.toString()
val fileName = qualifiedName.replace('.', '/') + ".html"
val simpleName = element.simpleName.toString()
val qualifiedName = element.qualifiedName.toString()
val packageName = FilterDoclet.elementUtils.getPackageOf(element).qualifiedName.toString()
val fileName = qualifiedName.replace('.', '/') + ".html"

override fun compareTo(other: ClassInfo) = qualifiedName.compareTo(other.qualifiedName)
override fun compareTo(other: ClassInfo) = qualifiedName.compareTo(other.qualifiedName)

private fun description() = html {
div("class-description") { compose { element.commentsAndTagTrees() } }
}
private fun description() = html {
div("class-description") {
compose {
element.commentsAndTagTrees()
}
}
}

private fun fields() = html {
val fields = element.children(Element::isVisibleField)
if (fields.isNotEmpty()) {
h2("Fields")
fields.forEach { field ->
div("member") {
h4(field.simpleName.toString())
compose { field.commentsAndTagTrees() }
private fun fields() = html {
val fields = element.children(Element::isVisibleField)
if (fields.isNotEmpty()) {
h2("Fields")
fields.forEach { field ->
div("member") {
h4(field.simpleName.toString())
compose {
field.commentsAndTagTrees()
}
}
}
}
}
}
}

private fun nestedClasses() = html {
val nested = element.children(Element::isVisibleType)
nested
.takeIf { it.isNotEmpty() }
?.let {
h2("Nested Classes")
nested.forEach { cls ->
div("member") {
h4(cls.simpleName.toString())
compose { cls.commentsAndTagTrees() }
}
private fun nestedClasses() = html {
val nested = element.children(Element::isVisibleType)
nested.takeIf { it.isNotEmpty() }?.let {
h2("Nested Classes")
nested.forEach { cls ->
div("member") {
h4(cls.simpleName.toString())
compose {
cls.commentsAndTagTrees()
}
}
}
}
}
}
}

private fun method(method: ExecutableElement) = html {
div("member") {
h4(method.simpleName.toString())
pre(method.methodSignature(), "method-signature")
div("description") {
compose { method.commentTree() }
val params = method.paramTags()
val throwns = method.throwTags()
val returns =
if (method.isConstructor()) emptyList() else method.returnTag(method.returnType)
private fun method(method: ExecutableElement) = html {
div("member") {
h4(method.simpleName.toString())
pre(method.methodSignature(), "method-signature")
div("description") {
compose {
method.commentTree()
}
val params = method.paramTags()
val throwns = method.throwTags()
val returns = if (method.isConstructor())
emptyList()
else
method.returnTag(method.returnType)

if (params.size + returns.size + throwns.size > 0) {
div("params") {
table("params-table") {
rowGroup(params, title = "Parameters", colspan = 2) {
td { text(it.first) }
td { text(it.second) }
}
rowGroup(returns, title = "Returns", colspan = 2) {
td { text(it.first) }
td { text(it.second) }
}
rowGroup(throwns, title = "Throws", colspan = 2) {
td { text(it.first) }
td { text(it.second) }
}
if(params.size + returns.size + throwns.size > 0) {
div("params") {
table("params-table") {
rowGroup(params, title = "Parameters", colspan = 2) {
td {text(it.first)}
td {text(it.second)}
}
rowGroup(returns, title = "Returns", colspan = 2) {
td {text(it.first)}
td {text(it.second)}
}
rowGroup(throwns, title = "Throws", colspan = 2) {
td {text(it.first)}
td {text(it.second)}
}
}
}
}
}
}
}
}
}
}

private fun executables(title: String, filter: (Element) -> Boolean) = html {
val methods = element.children(filter)
if (methods.isNotEmpty()) {
h2(title)
methods.forEach { compose { method(it as ExecutableElement) } }
private fun executables(title: String, filter: (Element) -> Boolean) = html {
val methods = element.children(filter)
if (methods.isNotEmpty()) {
h2(title)
methods.forEach {
compose {
method(it as ExecutableElement)
}
}
}
}
}

private fun constructors() = executables("Constructors", Element::isVisibleConstructor)

private fun methods() = executables("Public Methods", Element::isVisibleMethod)
private fun constructors() = executables("Constructors", Element::isVisibleConstructor)
private fun methods() = executables("Public Methods", Element::isVisibleMethod)

fun generateHtml() = html {
div("package-name") { text("Package: $packageName") }
h1(simpleName)
pre(element.signature(), "class-signature")
fun generateHtml() = html {
div("package-name") { text("Package: $packageName") }
h1(simpleName)
pre(element.signature(), "class-signature")

compose { description() + fields() + constructors() + methods() + nestedClasses() }
}
compose {
description() +
fields() +
constructors() +
methods() +
nestedClasses()
}
}
}

Loading

0 comments on commit cb7d84e

Please sign in to comment.