From 146764aca661d51daa298c7cfe6b9b5efcff7e5f Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 26 Feb 2015 19:08:59 +0100 Subject: stop generating separate pages for property accessors --- src/Formats/StructuredFormatService.kt | 2 -- src/Java/JavaDocumentationBuilder.kt | 4 ++-- src/Kotlin/ContentBuilder.kt | 4 ++-- src/Kotlin/DocumentationBuilder.kt | 38 +++++++++++++++++++--------------- src/Kotlin/KotlinLanguageService.kt | 5 +---- src/Model/Content.kt | 28 +++++++++++++++---------- src/Model/DocumentationNode.kt | 12 ++++++++++- 7 files changed, 54 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index ee835aa0..70967b20 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -267,7 +267,6 @@ public abstract class StructuredFormatService(locationService: LocationService, appendSection(location, "Functions", node.members(DocumentationNode.Kind.Function), node, to) appendSection(location, "Default Object Properties", node.members(DocumentationNode.Kind.DefaultObjectProperty), node, to) appendSection(location, "Default Object Functions", node.members(DocumentationNode.Kind.DefaultObjectFunction), node, to) - appendSection(location, "Accessors", node.members(DocumentationNode.Kind.PropertyAccessor), node, to) appendSection(location, "Enum Values", node.members(DocumentationNode.Kind.EnumItem), node, to) appendSection(location, "Other members", node.members.filter { it.kind !in setOf( @@ -280,7 +279,6 @@ public abstract class StructuredFormatService(locationService: LocationService, DocumentationNode.Kind.Property, DocumentationNode.Kind.Package, DocumentationNode.Kind.Function, - DocumentationNode.Kind.PropertyAccessor, DocumentationNode.Kind.DefaultObjectProperty, DocumentationNode.Kind.DefaultObjectFunction, DocumentationNode.Kind.ExternalClass, diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index 4652500e..8183df8f 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -18,7 +18,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, fun parseDocumentation(docComment: PsiDocComment?): JavadocParseResult { if (docComment == null) return JavadocParseResult(Content.Empty, null) - val result = Content() + val result = MutableContent() var deprecatedContent: Content? = null val para = ContentParagraph() result.append(para) @@ -56,7 +56,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, } } - private fun Content.convertSeeTag(tag: PsiDocTag) { + private fun MutableContent.convertSeeTag(tag: PsiDocTag) { val seeSection = findSectionByTag("See Also") ?: addSection("See Also", null) val linkNode = resolveLink(tag.getValueElement()) val text = ContentText(tag.getValueElement()!!.getText()) diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 56d2a407..4b8897b2 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -10,8 +10,8 @@ import org.intellij.markdown.* import org.jetbrains.kotlin.psi.JetDeclarationWithBody import org.jetbrains.kotlin.psi.JetBlockExpression -public fun buildContent(tree: MarkdownNode, linkResolver: (String) -> ContentBlock): Content { - val result = Content() +public fun buildContent(tree: MarkdownNode, linkResolver: (String) -> ContentBlock): MutableContent { + val result = MutableContent() buildContentTo(tree, result, linkResolver) return result } diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index b6bd8701..3910de04 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -136,7 +136,7 @@ class DocumentationBuilder(val session: ResolveSession, fun KDocSection.getTags(): Array = PsiTreeUtil.getChildrenOfType(this, javaClass()) ?: array() - private fun Content.addTagToSeeAlso(descriptor: DeclarationDescriptor, seeTag: KDocTag) { + private fun MutableContent.addTagToSeeAlso(descriptor: DeclarationDescriptor, seeTag: KDocTag) { val subjectName = seeTag.getSubjectName() if (subjectName != null) { val seeSection = findSectionByTag("See Also") ?: addSection("See Also", null) @@ -321,7 +321,6 @@ class DocumentationBuilder(val session: ResolveSession, is ConstructorDescriptor -> build() is ScriptDescriptor -> build() is PropertyDescriptor -> build() - is PropertyAccessorDescriptor -> build() is FunctionDescriptor -> build() is TypeParameterDescriptor -> build() is ValueParameterDescriptor -> build() @@ -414,17 +413,6 @@ class DocumentationBuilder(val session: ResolveSession, } } - fun PropertyAccessorDescriptor.build(): DocumentationNode { - val doc = parseDocumentation(this) - val specialName = getName().asString().drop(1).takeWhile { it != '-' } - val node = DocumentationNode(specialName, doc, Kind.PropertyAccessor).withModifiers(this) - - node.appendInPageChildren(getValueParameters(), DocumentationReference.Kind.Detail) - node.appendType(getReturnType()) - register(this, node) - return node - } - fun PropertyDescriptor.build(): DocumentationNode { val node = DocumentationNode(this, if (inClassObject()) Kind.DefaultObjectProperty else Kind.Property) node.appendInPageChildren(getTypeParameters(), DocumentationReference.Kind.Detail) @@ -436,12 +424,14 @@ class DocumentationBuilder(val session: ResolveSession, node.appendTextNode("var", DocumentationNode.Kind.Modifier) } getGetter()?.let { - if (!it.isDefault()) - node.appendChild(it, DocumentationReference.Kind.Member) + if (!it.isDefault()) { + node.addAccessorDocumentation(parseDocumentation(it), "Getter") + } } getSetter()?.let { - if (!it.isDefault()) - node.appendChild(it, DocumentationReference.Kind.Member) + if (!it.isDefault()) { + node.addAccessorDocumentation(parseDocumentation(it), "Setter") + } } getOverriddenDescriptors().forEach { @@ -452,6 +442,20 @@ class DocumentationBuilder(val session: ResolveSession, return node } + fun DocumentationNode.addAccessorDocumentation(documentation: Content, prefix: String) { + if (documentation == Content.Empty) return + updateContent { + if (!documentation.children.isEmpty()) { + val section = addSection(prefix, null) + documentation.children.forEach { section.append(it) } + } + documentation.sections.forEach { + val section = addSection("$prefix ${it.tag}", it.subjectName) + it.children.forEach { section.append(it) } + } + } + } + fun ValueParameterDescriptor.build(): DocumentationNode { val node = DocumentationNode(this, Kind.Parameter) val varargType = getVarargElementType() diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index ab1f7016..9836bbda 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -26,8 +26,7 @@ class KotlinLanguageService : LanguageService { DocumentationNode.Kind.Modifier -> renderModifier(node) DocumentationNode.Kind.Constructor, DocumentationNode.Kind.Function, - DocumentationNode.Kind.DefaultObjectFunction, - DocumentationNode.Kind.PropertyAccessor -> renderFunction(node) + DocumentationNode.Kind.DefaultObjectFunction -> renderFunction(node) DocumentationNode.Kind.Property, DocumentationNode.Kind.DefaultObjectProperty -> renderProperty(node) else -> identifier(node.name) @@ -241,7 +240,6 @@ class KotlinLanguageService : LanguageService { DocumentationNode.Kind.Constructor -> identifier(node.owner!!.name) DocumentationNode.Kind.Function, DocumentationNode.Kind.DefaultObjectFunction -> keyword("fun ") - DocumentationNode.Kind.PropertyAccessor -> {} else -> throw IllegalArgumentException("Node $node is not a function-like object") } renderTypeParametersForNode(node) @@ -267,7 +265,6 @@ class KotlinLanguageService : LanguageService { private fun needReturnType(node: DocumentationNode) = when(node.kind) { DocumentationNode.Kind.Constructor -> false - DocumentationNode.Kind.PropertyAccessor -> node.name == "get" else -> true } diff --git a/src/Model/Content.kt b/src/Model/Content.kt index 8e9c068d..66267496 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -98,9 +98,22 @@ fun ContentBlock.link(to: DocumentationNode, body: ContentBlock.() -> Unit) { append(block) } -public class Content() : ContentBlock() { +public open class Content(): ContentBlock() { + public open val sections: List get() = emptyList() + public open val summary: ContentNode get() = ContentEmpty + public open val description: ContentNode get() = ContentEmpty + + fun findSectionByTag(tag: String): ContentSection? = + sections.firstOrNull { tag.equalsIgnoreCase(it.tag) } + + class object { + val Empty = Content() + } +} + +public open class MutableContent() : Content() { private val sectionList = arrayListOf() - public val sections: List + public override val sections: List get() = sectionList fun addSection(tag: String?, subjectName: String?): ContentSection { @@ -109,12 +122,9 @@ public class Content() : ContentBlock() { return section } - fun findSectionByTag(tag: String): ContentSection? = - sections.firstOrNull { tag.equalsIgnoreCase(it.tag) } - - public val summary: ContentNode get() = children.firstOrNull() ?: ContentEmpty + public override val summary: ContentNode get() = children.firstOrNull() ?: ContentEmpty - public val description: ContentNode by Delegates.lazy { + public override val description: ContentNode by Delegates.lazy { val descriptionNodes = children.drop(1) if (descriptionNodes.isEmpty()) { ContentEmpty @@ -143,10 +153,6 @@ public class Content() : ContentBlock() { val isEmpty: Boolean get() = sections.none() - - class object { - val Empty = Content() - } } fun javadocSectionDisplayName(sectionName: String?): String? = diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt index f0c3ddf5..8fec29c4 100644 --- a/src/Model/DocumentationNode.kt +++ b/src/Model/DocumentationNode.kt @@ -3,11 +3,14 @@ package org.jetbrains.dokka import java.util.LinkedHashSet public open class DocumentationNode(val name: String, - val content: Content, + content: Content, val kind: DocumentationNode.Kind) { private val references = LinkedHashSet() + var content: Content = content + private set + public val summary: ContentNode get() = content.summary public val owner: DocumentationNode? @@ -38,6 +41,13 @@ public open class DocumentationNode(val name: String, references.addAll(other.references) } + public fun updateContent(body: MutableContent.() -> Unit) { + if (content !is MutableContent) { + content = MutableContent() + } + (content as MutableContent).body() + } + public fun details(kind: DocumentationNode.Kind): List = details.filter { it.kind == kind } public fun members(kind: DocumentationNode.Kind): List = members.filter { it.kind == kind } public fun links(kind: DocumentationNode.Kind): List = links.filter { it.kind == kind } -- cgit