Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errata from upstreaming and downstreaming. #1234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 29 additions & 41 deletions api-doclet/src/main/kotlin/org/conscrypt/doclet/ClassIndex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,44 @@ 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
}
private fun put(classInfo: ClassInfo) {
index[classInfo.qualifiedName] = classInfo
}

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

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
fun get(qualifiedName: String) = index[qualifiedName]

fun classes(): Collection<ClassInfo> = index.values
fun contains(qualifiedName: String) = index.containsKey(qualifiedName)

fun addVisible(elements: Set<Element>) {
elements
.filterIsInstance<TypeElement>()
.filter(Element::isVisibleType)
.forEach(::put)
}
fun find(name: String) = if (contains(name)) get(name) else findSimple(name)

private fun packages(): List<String> = index.values.stream()
.map { it.packageName }
.distinct()
.sorted()
.toList()
private fun findSimple(name: String) = classes().firstOrNull { it.simpleName == name } // XXX dups

private fun classesForPackage(packageName: String) = index.values.stream()
.filter { it.packageName == packageName }
.sorted()
.toList()
fun classes(): Collection<ClassInfo> = index.values

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 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 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) } }
}
}
}
}
}

169 changes: 74 additions & 95 deletions api-doclet/src/main/kotlin/org/conscrypt/doclet/ClassInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,117 +20,96 @@ 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)

fun generateHtml() = html {
div("package-name") { text("Package: $packageName") }
h1(simpleName)
pre(element.signature(), "class-signature")
private fun methods() = executables("Public Methods", Element::isVisibleMethod)

compose {
description() +
fields() +
constructors() +
methods() +
nestedClasses()
}
}
}
fun generateHtml() = html {
div("package-name") { text("Package: $packageName") }
h1(simpleName)
pre(element.signature(), "class-signature")

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