kdoc improvements: added discovery of ReadMe.md or ReadMe.html files in a package source directory, so we can auto-discover documentation like this https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/ReadMe.md and fixed a regression where we could not find the KPackage of a descriptor with changes to the AST and fixed up some bad links to external classes
This commit is contained in:
@@ -91,7 +91,7 @@ class KDocConfig() {
|
|||||||
/**
|
/**
|
||||||
* Resolves a link to the given class name
|
* Resolves a link to the given class name
|
||||||
*/
|
*/
|
||||||
fun resolveLink(packageName: String): String {
|
fun resolveLink(packageName: String, warn: Boolean = true): String {
|
||||||
for (e in packagePrefixToUrls) {
|
for (e in packagePrefixToUrls) {
|
||||||
val p = e.key
|
val p = e.key
|
||||||
val url = e.value
|
val url = e.value
|
||||||
|
|||||||
+13
-14
@@ -270,6 +270,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
|||||||
val scope = descriptor.getMemberScope()
|
val scope = descriptor.getMemberScope()
|
||||||
addFunctions(pkg, scope)
|
addFunctions(pkg, scope)
|
||||||
pkg.local = isLocal(descriptor)
|
pkg.local = isLocal(descriptor)
|
||||||
|
pkg.useExternalLink = pkg.model.config.resolveLink(pkg.name, false).notEmpty()
|
||||||
|
|
||||||
if (pkg.wikiDescription.isEmpty()) {
|
if (pkg.wikiDescription.isEmpty()) {
|
||||||
// lets try find a custom doc
|
// lets try find a custom doc
|
||||||
@@ -872,7 +873,18 @@ abstract class KNamed(val name: String, model: KModel, declarationDescriptor: De
|
|||||||
|
|
||||||
class KPackage(model: KModel, val descriptor: NamespaceDescriptor,
|
class KPackage(model: KModel, val descriptor: NamespaceDescriptor,
|
||||||
val name: String,
|
val name: String,
|
||||||
var local: Boolean = false): KClassOrPackage(model, descriptor), Comparable<KPackage> {
|
var local: Boolean = false,
|
||||||
|
var useExternalLink: Boolean = false): KClassOrPackage(model, descriptor), Comparable<KPackage> {
|
||||||
|
|
||||||
|
|
||||||
|
// TODO generates java.lang.NoSuchMethodError: kotlin.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap;
|
||||||
|
//val classes = sortedMap<String,KClass>()
|
||||||
|
public val classMap: SortedMap<String, KClass> = TreeMap<String, KClass>()
|
||||||
|
|
||||||
|
public val classes: Collection<KClass>
|
||||||
|
get() = classMap.values().sure().filter{ it.isApi() }
|
||||||
|
|
||||||
|
public val annotations: Collection<KClass> = ArrayList<KClass>()
|
||||||
|
|
||||||
public override fun compareTo(other: KPackage): Int = name.compareTo(other.name)
|
public override fun compareTo(other: KPackage): Int = name.compareTo(other.name)
|
||||||
|
|
||||||
@@ -930,7 +942,6 @@ class KPackage(model: KModel, val descriptor: NamespaceDescriptor,
|
|||||||
return if (answer.length == 0) "" else answer + "/"
|
return if (answer.length == 0) "" else answer + "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun description(template: KDocTemplate): String {
|
override fun description(template: KDocTemplate): String {
|
||||||
// lets see if we can find a custom summary
|
// lets see if we can find a custom summary
|
||||||
val text = model.config.packageSummaryText[name]
|
val text = model.config.packageSummaryText[name]
|
||||||
@@ -940,17 +951,6 @@ class KPackage(model: KModel, val descriptor: NamespaceDescriptor,
|
|||||||
super<KClassOrPackage>.description(template)
|
super<KClassOrPackage>.description(template)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO generates java.lang.NoSuchMethodError: kotlin.util.namespace.hashMap(Ljet/TypeInfo;Ljet/TypeInfo;)Ljava/util/HashMap;
|
|
||||||
//val classes = sortedMap<String,KClass>()
|
|
||||||
public val classMap: SortedMap<String, KClass> = TreeMap<String, KClass>()
|
|
||||||
|
|
||||||
public val classes: Collection<KClass>
|
|
||||||
get() = classMap.values().sure().filter{ it.isApi() }
|
|
||||||
|
|
||||||
public val annotations: Collection<KClass> = ArrayList<KClass>()
|
|
||||||
|
|
||||||
fun qualifiedName(simpleName: String): String {
|
fun qualifiedName(simpleName: String): String {
|
||||||
return if (name.length() > 0) {
|
return if (name.length() > 0) {
|
||||||
"${name}.${simpleName}"
|
"${name}.${simpleName}"
|
||||||
@@ -959,7 +959,6 @@ class KPackage(model: KModel, val descriptor: NamespaceDescriptor,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun previous(pkg: KClass): KClass? {
|
fun previous(pkg: KClass): KClass? {
|
||||||
// TODO
|
// TODO
|
||||||
return null
|
return null
|
||||||
|
|||||||
+7
-7
@@ -14,7 +14,7 @@ import java.util.List
|
|||||||
|
|
||||||
abstract class KDocTemplate() : TextTemplate() {
|
abstract class KDocTemplate() : TextTemplate() {
|
||||||
open fun rootHref(pkg: KPackage): String {
|
open fun rootHref(pkg: KPackage): String {
|
||||||
return if (pkg.local)
|
return if (!pkg.useExternalLink)
|
||||||
relativePrefix()
|
relativePrefix()
|
||||||
else
|
else
|
||||||
pkg.model.config.resolveLink(pkg.name)
|
pkg.model.config.resolveLink(pkg.name)
|
||||||
@@ -24,7 +24,7 @@ abstract class KDocTemplate() : TextTemplate() {
|
|||||||
= "${rootHref(p)}${p.nameAsPath}/package-summary.html"
|
= "${rootHref(p)}${p.nameAsPath}/package-summary.html"
|
||||||
|
|
||||||
open fun href(c: KClass): String {
|
open fun href(c: KClass): String {
|
||||||
val postfix = if (c.pkg.local) "" else "?is-external=true"
|
val postfix = if (!c.pkg.useExternalLink) "" else "?is-external=true"
|
||||||
return "${rootHref(c.pkg)}${c.nameAsPath}.html$postfix"
|
return "${rootHref(c.pkg)}${c.nameAsPath}.html$postfix"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ abstract class KDocTemplate() : TextTemplate() {
|
|||||||
return klass.sourceLink()
|
return klass.sourceLink()
|
||||||
} else {
|
} else {
|
||||||
val pkg = klass.pkg
|
val pkg = klass.pkg
|
||||||
return if (pkg.local) {
|
return if (!pkg.useExternalLink) {
|
||||||
"${pkg.nameAsRelativePath}src-html/${klass.nameAsPath}.html#line.${klass.sourceLine}"
|
"${pkg.nameAsRelativePath}src-html/${klass.nameAsPath}.html#line.${klass.sourceLine}"
|
||||||
} else {
|
} else {
|
||||||
href(klass)
|
href(klass)
|
||||||
@@ -72,13 +72,13 @@ abstract class KDocTemplate() : TextTemplate() {
|
|||||||
val owner = f.owner
|
val owner = f.owner
|
||||||
return if (owner is KClass) {
|
return if (owner is KClass) {
|
||||||
val pkg = owner.pkg
|
val pkg = owner.pkg
|
||||||
if (pkg.local) {
|
if (!pkg.useExternalLink) {
|
||||||
"${rootHref(pkg)}src-html/${owner.simpleName}.html#line.${f.sourceLine}"
|
"${rootHref(pkg)}src-html/${owner.simpleName}.html#line.${f.sourceLine}"
|
||||||
} else {
|
} else {
|
||||||
href(f)
|
href(f)
|
||||||
}
|
}
|
||||||
} else if (owner is KPackage) {
|
} else if (owner is KPackage) {
|
||||||
if (owner.local) {
|
if (!owner.useExternalLink) {
|
||||||
// TODO how to find the function in a package???
|
// TODO how to find the function in a package???
|
||||||
"${rootHref(owner)}src-html/namespace.html#line.${f.sourceLine}"
|
"${rootHref(owner)}src-html/namespace.html#line.${f.sourceLine}"
|
||||||
} else {
|
} else {
|
||||||
@@ -95,13 +95,13 @@ abstract class KDocTemplate() : TextTemplate() {
|
|||||||
val owner = f.owner
|
val owner = f.owner
|
||||||
return if (owner is KClass) {
|
return if (owner is KClass) {
|
||||||
val pkg = owner.pkg
|
val pkg = owner.pkg
|
||||||
if (pkg.local) {
|
if (!pkg.useExternalLink) {
|
||||||
"${rootHref(pkg)}src-html/${owner.simpleName}.html#line.${f.sourceLine}"
|
"${rootHref(pkg)}src-html/${owner.simpleName}.html#line.${f.sourceLine}"
|
||||||
} else {
|
} else {
|
||||||
href(f)
|
href(f)
|
||||||
}
|
}
|
||||||
} else if (owner is KPackage) {
|
} else if (owner is KPackage) {
|
||||||
if (owner.local) {
|
if (!owner.useExternalLink) {
|
||||||
// TODO how to find the function in a package???
|
// TODO how to find the function in a package???
|
||||||
"${rootHref(owner)}src-html/namespace.html#line.${f.sourceLine}"
|
"${rootHref(owner)}src-html/namespace.html#line.${f.sourceLine}"
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user