aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--javadoc/src/main/kotlin/docbase.kt23
-rw-r--r--javadoc/src/main/kotlin/tags.kt21
-rw-r--r--src/Java/JavaPsiDocumentationBuilder.kt20
-rw-r--r--src/Model/Content.kt8
4 files changed, 56 insertions, 16 deletions
diff --git a/javadoc/src/main/kotlin/docbase.kt b/javadoc/src/main/kotlin/docbase.kt
index 318aa3d5..cdb4bbc7 100644
--- a/javadoc/src/main/kotlin/docbase.kt
+++ b/javadoc/src/main/kotlin/docbase.kt
@@ -63,12 +63,25 @@ open class DocumentationNodeBareAdapter(override val node: DocumentationNode) :
open class DocumentationNodeAdapter(override val module: ModuleNodeAdapter, node: DocumentationNode) : DocumentationNodeBareAdapter(node), HasModule {
override fun inlineTags(): Array<out Tag> = buildInlineTags(module, this, node.content).toTypedArray()
override fun firstSentenceTags(): Array<out Tag> = buildInlineTags(module, this, node.summary).toTypedArray()
- override fun tags(): Array<out Tag> = (buildInlineTags(module, this, node.content) + node.content.sections.flatMap {
- when (it.tag) {
- ContentTags.SeeAlso -> buildInlineTags(module, this, it)
- else -> emptyList<Tag>()
+
+ override fun tags(): Array<out Tag> {
+ val result = ArrayList<Tag>(buildInlineTags(module, this, node.content))
+ node.content.sections.flatMapTo(result) {
+ when (it.tag) {
+ ContentTags.SeeAlso -> buildInlineTags(module, this, it)
+ else -> emptyList<Tag>()
+ }
}
- }).toTypedArray()
+
+ node.deprecation?.let {
+ val content = it.content.asText()
+ if (content != null) {
+ result.add(TagImpl(this, "deprecated", content))
+ }
+ }
+
+ return result.toTypedArray()
+ }
}
// should be extension property but can't because of KT-8745
diff --git a/javadoc/src/main/kotlin/tags.kt b/javadoc/src/main/kotlin/tags.kt
index 9fdf86f2..5c38bbee 100644
--- a/javadoc/src/main/kotlin/tags.kt
+++ b/javadoc/src/main/kotlin/tags.kt
@@ -4,6 +4,19 @@ import com.sun.javadoc.*
import org.jetbrains.dokka.*
import java.util.*
+class TagImpl(val holder: Doc, val name: String, val text: String): Tag {
+ override fun text(): String? = text
+
+ override fun holder(): Doc = holder
+ override fun firstSentenceTags(): Array<out Tag>? = arrayOf()
+ override fun inlineTags(): Array<out Tag>? = arrayOf()
+
+ override fun name(): String = name
+ override fun kind(): String = name
+
+ override fun position(): SourcePosition = holder.position()
+}
+
class TextTag(val holder: Doc, val content: ContentText) : Tag {
val plainText: String
get() = content.text
@@ -32,8 +45,7 @@ class SeeExternalLinkTagAdapter(val holder: Doc, val link: ContentExternalLink)
override fun inlineTags(): Array<out Tag> = emptyArray() // TODO
override fun label(): String {
- val contentText = link.children.singleOrNull() as? ContentText
- val label = contentText?.text ?: link.href
+ val label = link.asText() ?: link.href
return "<a href=\"${link.href}\">$label</a>"
}
@@ -48,6 +60,11 @@ class SeeExternalLinkTagAdapter(val holder: Doc, val link: ContentExternalLink)
override fun kind(): String = "@see"
}
+fun ContentBlock.asText(): String? {
+ val contentText = children.singleOrNull() as? ContentText
+ return contentText?.text
+}
+
class SeeMethodTagAdapter(holder: Doc, val method: MethodAdapter, content: ContentNodeLink) : SeeTagAdapter(holder, content) {
override fun referencedMember(): MemberDoc = method
override fun referencedMemberName(): String = method.name()
diff --git a/src/Java/JavaPsiDocumentationBuilder.kt b/src/Java/JavaPsiDocumentationBuilder.kt
index fc60450a..72f398ce 100644
--- a/src/Java/JavaPsiDocumentationBuilder.kt
+++ b/src/Java/JavaPsiDocumentationBuilder.kt
@@ -80,9 +80,9 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder {
}
}
- fun DocumentationNode(element: PsiNamedElement,
- kind: Kind,
- name: String = element.name ?: "<anonymous>"): DocumentationNode {
+ fun nodeForElement(element: PsiNamedElement,
+ kind: Kind,
+ name: String = element.name ?: "<anonymous>"): DocumentationNode {
val (docComment, deprecatedContent) = docParser.parseDocumentation(element)
val node = DocumentationNode(name, docComment, kind)
if (element is PsiModifierListOwner) {
@@ -100,6 +100,10 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder {
val deprecationNode = DocumentationNode("", deprecatedContent, Kind.Modifier)
node.append(deprecationNode, DocumentationReference.Kind.Deprecation)
}
+ if (element is PsiDocCommentOwner && element.isDeprecated && node.deprecation == null) {
+ val deprecationNode = DocumentationNode("", Content.of(ContentText("Deprecated")), Kind.Modifier)
+ node.append(deprecationNode, DocumentationReference.Kind.Deprecation)
+ }
return node
}
@@ -140,7 +144,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder {
isAnnotationType -> DocumentationNode.Kind.AnnotationClass
else -> DocumentationNode.Kind.Class
}
- val node = DocumentationNode(this, kind)
+ val node = nodeForElement(this, kind)
superTypes.filter { !ignoreSupertype(it) }.forEach {
node.appendType(it, Kind.Supertype)
val superClass = it.resolve()
@@ -169,7 +173,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder {
}
fun PsiField.build(): DocumentationNode {
- val node = DocumentationNode(this, nodeKind())
+ val node = nodeForElement(this, nodeKind())
node.appendType(type)
node.appendModifiers(this)
register(this, node)
@@ -182,7 +186,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder {
}
fun PsiMethod.build(): DocumentationNode {
- val node = DocumentationNode(this, nodeKind(),
+ val node = nodeForElement(this, nodeKind(),
if (isConstructor) "<init>" else name)
if (!isConstructor) {
@@ -200,7 +204,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder {
}
fun PsiParameter.build(): DocumentationNode {
- val node = DocumentationNode(this, Kind.Parameter)
+ val node = nodeForElement(this, Kind.Parameter)
node.appendType(type)
if (type is PsiEllipsisType) {
node.appendTextNode("vararg", Kind.Modifier, DocumentationReference.Kind.Detail)
@@ -209,7 +213,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder {
}
fun PsiTypeParameter.build(): DocumentationNode {
- val node = DocumentationNode(this, Kind.TypeParameter)
+ val node = nodeForElement(this, Kind.TypeParameter)
extendsListTypes.forEach { node.appendType(it, Kind.UpperBound) }
implementsListTypes.forEach { node.appendType(it, Kind.UpperBound) }
return node
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index 45d42a2d..6556b09e 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -11,7 +11,7 @@ public object ContentEmpty : ContentNode {
public open class ContentBlock() : ContentNode {
val children = arrayListOf<ContentNode>()
- fun append(node : ContentNode) {
+ fun append(node: ContentNode) {
children.add(node)
}
@@ -173,6 +173,12 @@ public open class Content(): ContentBlock() {
companion object {
val Empty = Content()
+
+ fun of(vararg child: ContentNode): Content {
+ val result = MutableContent()
+ child.forEach { result.append(it) }
+ return result
+ }
}
}