From c4f40a03404641a9a42e6518cb066f2e0ae609e0 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 12 Jan 2015 16:32:30 +0100 Subject: better display for enum members --- test/data/format/enumClass.kt | 4 ++++ test/data/format/enumClass.md | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/data/format/enumClass.kt create mode 100644 test/data/format/enumClass.md (limited to 'test/data/format') 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..1f2df115 --- /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) | `public enum val LOCAL_CONTINUE_AND_BREAK : [InlineOption](out.md)` | +| [ONLY_LOCAL_RETURN](out.md) | `public enum val ONLY_LOCAL_RETURN : [InlineOption](out.md)` | + -- cgit From 0c584d0e12f07946fdfc8cc0e9f132558ff794fc Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 12 Jan 2015 17:23:07 +0100 Subject: enum values continued --- src/Formats/StructuredFormatService.kt | 3 ++- src/Kotlin/KotlinLanguageService.kt | 7 +++++-- src/Languages/JavaLanguageService.kt | 3 ++- src/Languages/LanguageService.kt | 9 ++++++++- test/data/format/enumClass.md | 4 ++-- test/data/format/enumClass.value.md | 0 test/src/format/MarkdownFormatTest.kt | 4 ++++ 7 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 test/data/format/enumClass.value.md (limited to 'test/data/format') diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 49a7c96b..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) 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.md b/test/data/format/enumClass.md index 1f2df115..e1c4144e 100644 --- a/test/data/format/enumClass.md +++ b/test/data/format/enumClass.md @@ -20,6 +20,6 @@ public enum class InlineOption ### Enum Values -| [LOCAL_CONTINUE_AND_BREAK](out.md) | `public enum val LOCAL_CONTINUE_AND_BREAK : [InlineOption](out.md)` | -| [ONLY_LOCAL_RETURN](out.md) | `public enum val ONLY_LOCAL_RETURN : [InlineOption](out.md)` | +| [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 diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index 8cb6091f..1b8b1cc0 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -51,5 +51,9 @@ public class MarkdownFormatTest { 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])) + } } } -- cgit From d33f5b8d4268e3b3ea318faeb4b5c63a0b7b71fd Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 12 Jan 2015 17:49:34 +0100 Subject: don't show constructors for enum entries --- src/Kotlin/DocumentationBuilder.kt | 2 +- test/data/format/enumClass.value.md | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'test/data/format') diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 8b6b19d3..b155ebca 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -210,7 +210,7 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati } val node = DocumentationNode(this, kind) node.appendSupertypes(this) - if (getKind() != ClassKind.OBJECT) { + if (getKind() != ClassKind.OBJECT && getKind() != ClassKind.ENUM_ENTRY) { node.appendChildren(getTypeConstructor().getParameters(), DocumentationReference.Kind.Detail) node.appendChildren(getConstructors(), DocumentationReference.Kind.Member) } diff --git a/test/data/format/enumClass.value.md b/test/data/format/enumClass.value.md index e69de29b..70dc8eb8 100644 --- a/test/data/format/enumClass.value.md +++ b/test/data/format/enumClass.value.md @@ -0,0 +1,12 @@ +[test](out.md) / [](out.md) / [InlineOption](out.md) / [LOCAL_CONTINUE_AND_BREAK](out.md) + + +# LOCAL_CONTINUE_AND_BREAK + + +``` +LOCAL_CONTINUE_AND_BREAK +``` + + + -- cgit From 1ce5373a1f6c99d01db2156a833fcd796ef53e27 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 13 Jan 2015 16:19:42 +0100 Subject: code review and fix tests on Windows build agents --- src/Kotlin/DocumentationBuilder.kt | 6 +++++- test/data/format/enumClass.md | 6 ------ test/src/TestAPI.kt | 3 +-- test/src/format/MarkdownFormatTest.kt | 7 +++---- 4 files changed, 9 insertions(+), 13 deletions(-) (limited to 'test/data/format') diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index b155ebca..a9b017bb 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -212,7 +212,11 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati node.appendSupertypes(this) if (getKind() != ClassKind.OBJECT && getKind() != ClassKind.ENUM_ENTRY) { node.appendChildren(getTypeConstructor().getParameters(), DocumentationReference.Kind.Detail) - node.appendChildren(getConstructors(), DocumentationReference.Kind.Member) + val constructorsToDocument = if (getKind() == ClassKind.ENUM_CLASS) + getConstructors().filter { it.getValueParameters().size() > 0 } + else + getConstructors() + node.appendChildren(constructorsToDocument, DocumentationReference.Kind.Member) } node.appendChildren(getDefaultType().getMemberScope().getAllDescriptors(), DocumentationReference.Kind.Member) val classObjectDescriptor = getClassObjectDescriptor() diff --git a/test/data/format/enumClass.md b/test/data/format/enumClass.md index e1c4144e..7b3d242b 100644 --- a/test/data/format/enumClass.md +++ b/test/data/format/enumClass.md @@ -11,12 +11,6 @@ public enum class InlineOption -### Constructors - - -| [<init>](out.md) | `private InlineOption()` | - - ### Enum Values diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt index 901e78fc..d6c7efb7 100644 --- a/test/src/TestAPI.kt +++ b/test/src/TestAPI.kt @@ -4,7 +4,6 @@ import org.jetbrains.kotlin.cli.common.messages.* import com.intellij.openapi.util.* import kotlin.test.fail import org.jetbrains.dokka.* -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import java.io.File import com.intellij.openapi.application.PathManager import org.junit.Assert @@ -54,7 +53,7 @@ public fun verifyOutput(path: String, outputExtension: String, outputGenerator: verifyModel(path) { val output = StringBuilder() outputGenerator(it, output) - val expectedOutput = File(path.replace(".kt", outputExtension)).readText() + val expectedOutput = File(path.replace(".kt", outputExtension)).readText().replace("\r\n", "\n") Assert.assertEquals(expectedOutput, output.toString()) } } diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index 1b8b1cc0..a5a62e13 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -2,8 +2,6 @@ package org.jetbrains.dokka.tests import org.junit.Test import org.jetbrains.dokka.* -import java.io.File -import kotlin.test.assertEquals public class MarkdownFormatTest { private val markdownService = MarkdownFormatService(InMemoryLocationService, KotlinLanguageService()) @@ -52,8 +50,9 @@ public class MarkdownFormatTest { 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])) + val enumClassNode = model.members.single().members[0] + markdownService.appendNodes(tempLocation, output, + enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }) } } } -- cgit