diff options
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 10 | ||||
-rw-r--r-- | src/Kotlin/KotlinLanguageService.kt | 7 | ||||
-rw-r--r-- | src/Languages/JavaLanguageService.kt | 3 | ||||
-rw-r--r-- | src/Languages/LanguageService.kt | 9 | ||||
-rw-r--r-- | test/data/format/enumClass.kt | 4 | ||||
-rw-r--r-- | test/data/format/enumClass.md | 25 | ||||
-rw-r--r-- | test/data/format/enumClass.value.md | 0 | ||||
-rw-r--r-- | test/src/format/MarkdownFormatTest.kt | 10 |
8 files changed, 61 insertions, 7 deletions
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 977d81d0..3f505e37 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka import java.util.LinkedHashMap +import org.jetbrains.dokka.LanguageService.RenderMode public data class FormatLink(val text: String, val location: Location) @@ -162,7 +163,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi val breakdownBySummary = members.groupBy { formatText(location, it.summary) } for ((summary, items) in breakdownBySummary) { val signatureTexts = items map { signature -> - val signature = languageService.render(signature) + val signature = languageService.render(signature, RenderMode.SUMMARY) val signatureAsCode = ContentCode() signatureAsCode.append(signature) formatText(location, signatureAsCode) @@ -216,6 +217,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi appendSection(location, "Class Object Properties", node.members(DocumentationNode.Kind.ClassObjectProperty), node, to) appendSection(location, "Class Object Functions", node.members(DocumentationNode.Kind.ClassObjectFunction), 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( DocumentationNode.Kind.Class, @@ -230,11 +232,13 @@ public abstract class StructuredFormatService(val locationService: LocationServi DocumentationNode.Kind.PropertyAccessor, DocumentationNode.Kind.ClassObjectProperty, DocumentationNode.Kind.ClassObjectFunction, - DocumentationNode.Kind.ExternalClass + DocumentationNode.Kind.ExternalClass, + DocumentationNode.Kind.EnumItem ) }, node, to) appendSection(location, "Extensions", node.extensions, node, to) - appendSection(location, "Inheritors", node.inheritors, node, to) + appendSection(location, "Inheritors", + node.inheritors.filter { it.kind != DocumentationNode.Kind.EnumItem }, node, to) appendSection(location, "Links", node.links, node, to) } diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index 40f47639..8795aba6 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -1,20 +1,23 @@ package org.jetbrains.dokka +import org.jetbrains.dokka.LanguageService.RenderMode + /** * Implements [LanguageService] and provides rendering of symbols in Kotlin language */ class KotlinLanguageService : LanguageService { - override fun render(node: DocumentationNode): ContentNode { + override fun render(node: DocumentationNode, renderMode: RenderMode): ContentNode { return content { when (node.kind) { DocumentationNode.Kind.Package -> renderPackage(node) DocumentationNode.Kind.Class, DocumentationNode.Kind.Interface, DocumentationNode.Kind.Enum, - DocumentationNode.Kind.EnumItem, DocumentationNode.Kind.AnnotationClass, DocumentationNode.Kind.Object -> renderClass(node) + DocumentationNode.Kind.EnumItem -> if (renderMode == RenderMode.FULL) identifier(node.name) + DocumentationNode.Kind.TypeParameter -> renderTypeParameter(node) DocumentationNode.Kind.Type, DocumentationNode.Kind.UpperBound -> renderType(node) diff --git a/src/Languages/JavaLanguageService.kt b/src/Languages/JavaLanguageService.kt index 8cc54d4a..7446b34f 100644 --- a/src/Languages/JavaLanguageService.kt +++ b/src/Languages/JavaLanguageService.kt @@ -1,12 +1,13 @@ package org.jetbrains.dokka import org.jetbrains.dokka.DocumentationNode.* +import org.jetbrains.dokka.LanguageService.RenderMode /** * Implements [LanguageService] and provides rendering of symbols in Java language */ public class JavaLanguageService : LanguageService { - override fun render(node: DocumentationNode): ContentNode { + override fun render(node: DocumentationNode, renderMode: RenderMode): ContentNode { return ContentText(when (node.kind) { Kind.Package -> renderPackage(node) Kind.Class, diff --git a/src/Languages/LanguageService.kt b/src/Languages/LanguageService.kt index 191f12c4..35fea501 100644 --- a/src/Languages/LanguageService.kt +++ b/src/Languages/LanguageService.kt @@ -4,12 +4,19 @@ package org.jetbrains.dokka * Provides facility for rendering [DocumentationNode] as a language-dependent declaration */ trait LanguageService { + enum class RenderMode { + /** Brief signature (used in a list of all members of the class). */ + SUMMARY + /** Full signature (used in the page describing the member itself */ + FULL + } + /** * Renders a [node](DocumentationNode) as a class, function, property or other signature in a target language. * $node: A [DocumentationNode] to render * $returns: [ContentNode] which is a root for a rich content tree suitable for formatting with [FormatService] */ - fun render(node: DocumentationNode): ContentNode + fun render(node: DocumentationNode, renderMode: RenderMode = RenderMode.FULL): ContentNode /** * Renders [node] as a named representation in the target language diff --git a/test/data/format/enumClass.kt b/test/data/format/enumClass.kt new file mode 100644 index 00000000..5988c644 --- /dev/null +++ b/test/data/format/enumClass.kt @@ -0,0 +1,4 @@ +public enum class InlineOption { + LOCAL_CONTINUE_AND_BREAK + ONLY_LOCAL_RETURN +} diff --git a/test/data/format/enumClass.md b/test/data/format/enumClass.md new file mode 100644 index 00000000..e1c4144e --- /dev/null +++ b/test/data/format/enumClass.md @@ -0,0 +1,25 @@ +[test](out.md) / [](out.md) / [InlineOption](out.md) + + +# InlineOption + + +``` +public enum class InlineOption +``` + + + + +### Constructors + + +| [<init>](out.md) | `private InlineOption()` | + + +### Enum Values + + +| [LOCAL_CONTINUE_AND_BREAK](out.md) | `` | +| [ONLY_LOCAL_RETURN](out.md) | `` | + diff --git a/test/data/format/enumClass.value.md b/test/data/format/enumClass.value.md new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/data/format/enumClass.value.md diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index 3d32743f..1b8b1cc0 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -46,4 +46,14 @@ public class MarkdownFormatTest { markdownService.appendNodes(tempLocation, output, model.members.single().members) } } + + Test fun enumClass() { + verifyOutput("test/data/format/enumClass.kt", ".md") { model, output -> + markdownService.appendNodes(tempLocation, output, model.members.single().members) + } + verifyOutput("test/data/format/enumClass.kt", ".value.md") { model, output -> + val documentationNode = model.members.single() + markdownService.appendNodes(tempLocation, output, listOf(documentationNode.members[0].members[1])) + } + } } |