From ef51f7e2466e28db0943d528b6b489aefd098c0d Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 30 Dec 2014 16:34:08 +0100 Subject: annotations work in progress --- test/data/format/annotations.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/data/format/annotations.md (limited to 'test/data/format/annotations.md') diff --git a/test/data/format/annotations.md b/test/data/format/annotations.md new file mode 100644 index 00000000..e69de29b -- cgit From 0e70fa4ca021bff09e7d9ce64269a4e698512af5 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 30 Dec 2014 16:59:34 +0100 Subject: render annotations --- src/Kotlin/KotlinLanguageService.kt | 24 +++++++++++++++--------- test/data/format/annotations.kt | 4 +++- test/data/format/annotations.md | 30 ++++++++++++++++++++++++++++++ test/src/format/MarkdownFormatTest.kt | 2 +- test/src/model/ClassTest.kt | 1 - 5 files changed, 49 insertions(+), 12 deletions(-) (limited to 'test/data/format/annotations.md') diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index a4016849..1e5edf4d 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -1,15 +1,6 @@ package org.jetbrains.dokka -import org.jetbrains.dokka.symbol -import org.jetbrains.dokka.text -import org.jetbrains.dokka.identifier -import org.jetbrains.dokka.link -import org.jetbrains.dokka.keyword -import org.jetbrains.dokka.LanguageService -import org.jetbrains.dokka.DocumentationNode -import org.jetbrains.dokka.ContentNode import org.jetbrains.dokka -import org.jetbrains.dokka.ContentText /** * Implements [LanguageService] and provides rendering of symbols in Kotlin language @@ -135,6 +126,7 @@ class KotlinLanguageService : LanguageService { } private fun ContentNode.renderParameter(node: DocumentationNode) { + renderAnnotationsForNode(node) identifier(node.name) symbol(": ") val parameterType = node.detail(DocumentationNode.Kind.Type) @@ -171,8 +163,20 @@ class KotlinLanguageService : LanguageService { } } + private fun ContentNode.renderAnnotationsForNode(node: DocumentationNode) { + node.annotations.forEach { + renderAnnotation(it) + } + } + + private fun ContentNode.renderAnnotation(node: DocumentationNode) { + identifier(node.name) + text(" ") + } + private fun ContentNode.renderClass(node: DocumentationNode) { renderModifiersForNode(node) + renderAnnotationsForNode(node) when (node.kind) { DocumentationNode.Kind.Class -> keyword("class ") DocumentationNode.Kind.Interface -> keyword("trait ") @@ -189,6 +193,7 @@ class KotlinLanguageService : LanguageService { private fun ContentNode.renderFunction(node: DocumentationNode) { renderModifiersForNode(node) + renderAnnotationsForNode(node) when (node.kind) { DocumentationNode.Kind.Constructor -> identifier(node.owner!!.name) DocumentationNode.Kind.Function, @@ -218,6 +223,7 @@ class KotlinLanguageService : LanguageService { private fun ContentNode.renderProperty(node: DocumentationNode) { renderModifiersForNode(node) + renderAnnotationsForNode(node) when (node.kind) { DocumentationNode.Kind.Property, DocumentationNode.Kind.ClassObjectProperty -> keyword("val ") diff --git a/test/data/format/annotations.kt b/test/data/format/annotations.kt index 445ec969..9356d4ca 100644 --- a/test/data/format/annotations.kt +++ b/test/data/format/annotations.kt @@ -1,4 +1,6 @@ data class Foo { - inline fun bar() { + inline fun bar([noinline] notInlined: () -> Unit) { } + + inline val x: Int } diff --git a/test/data/format/annotations.md b/test/data/format/annotations.md index e69de29b..83f79397 100644 --- a/test/data/format/annotations.md +++ b/test/data/format/annotations.md @@ -0,0 +1,30 @@ +[test](out.md) / [](out.md) / [Foo](out.md) + + +# Foo + + +``` +data class Foo +``` + + + + +### Constructors + + +| [<init>](out.md) | `public Foo()` | + + +### Properties + + +| [x](out.md) | `inline val x: Int` | + + +### Functions + + +| [bar](out.md) | `inline fun bar(noinline notInlined: () -> Unit): Unit` | + diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index e9852964..531980de 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -21,7 +21,7 @@ public class MarkdownFormatTest { } Test fun annotations() { - verifyOutput("test/data/format/annotations.kt") { model, output -> + verifyOutput("test/data/format/annotations.kt", ".md") { model, output -> markdownService.appendNodes(tempLocation, output, model.members.single().members) } } diff --git a/test/src/model/ClassTest.kt b/test/src/model/ClassTest.kt index b9be30bf..257d73eb 100644 --- a/test/src/model/ClassTest.kt +++ b/test/src/model/ClassTest.kt @@ -166,7 +166,6 @@ public class ClassTest { } } } -} Test fun annotatedClass() { verifyModel("test/data/classes/annotatedClass.kt") { model -> -- cgit From 7fbff24a81a7bcc453e1c4e30acdcf7b38c68265 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 9 Jan 2015 18:54:06 +0100 Subject: use JUnit for compares; avoid generating trailing whitespace in markdown --- src/Formats/MarkdownFormatService.kt | 5 +++-- test/data/format/annotationClass.md | 2 +- test/data/format/annotations.md | 6 +++--- test/data/format/classWithClassObject.md | 6 +++--- test/src/TestAPI.kt | 5 ++--- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'test/data/format/annotations.md') diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index 96f64eec..38fadf7a 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -106,14 +106,15 @@ public open class MarkdownFormatService(locationService: LocationService, } override fun appendTableRow(to: StringBuilder, body: () -> Unit) { - to.append("| ") + to.append("|") body() to.appendln() } override fun appendTableCell(to: StringBuilder, body: () -> Unit) { + to.append(" ") body() - to.append(" | ") + to.append(" |") } var outlineLevel = 0 diff --git a/test/data/format/annotationClass.md b/test/data/format/annotationClass.md index bfaa8581..301eff08 100644 --- a/test/data/format/annotationClass.md +++ b/test/data/format/annotationClass.md @@ -14,5 +14,5 @@ annotation class fancy ### Constructors -| [<init>](out.md) | `public fancy()` | +| [<init>](out.md) | `public fancy()` | diff --git a/test/data/format/annotations.md b/test/data/format/annotations.md index 83f79397..e745213e 100644 --- a/test/data/format/annotations.md +++ b/test/data/format/annotations.md @@ -14,17 +14,17 @@ data class Foo ### Constructors -| [<init>](out.md) | `public Foo()` | +| [<init>](out.md) | `public Foo()` | ### Properties -| [x](out.md) | `inline val x: Int` | +| [x](out.md) | `inline val x: Int` | ### Functions -| [bar](out.md) | `inline fun bar(noinline notInlined: () -> Unit): Unit` | +| [bar](out.md) | `inline fun bar(noinline notInlined: () -> Unit): Unit` | diff --git a/test/data/format/classWithClassObject.md b/test/data/format/classWithClassObject.md index f694a76f..796ecce2 100644 --- a/test/data/format/classWithClassObject.md +++ b/test/data/format/classWithClassObject.md @@ -14,17 +14,17 @@ class Klass ### Constructors -| [<init>](out.md) | `public Klass()` | +| [<init>](out.md) | `public Klass()` | ### Class Object Properties -| [x](out.md) | `val x: Int` | +| [x](out.md) | `val x: Int` | ### Class Object Functions -| [foo](out.md) | `fun foo(): Unit` | +| [foo](out.md) | `fun foo(): Unit` | diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt index a88835cd..e559e337 100644 --- a/test/src/TestAPI.kt +++ b/test/src/TestAPI.kt @@ -4,10 +4,9 @@ import org.jetbrains.jet.cli.common.messages.* import com.intellij.openapi.util.* import kotlin.test.fail import org.jetbrains.dokka.* -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor import java.io.File -import kotlin.test.assertEquals import com.intellij.openapi.application.PathManager +import org.junit.Assert public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> Unit) { val messageCollector = object : MessageCollector { @@ -55,7 +54,7 @@ public fun verifyOutput(path: String, outputExtension: String, outputGenerator: val output = StringBuilder() outputGenerator(it, output) val expectedOutput = File(path.replace(".kt", outputExtension)).readText() - assertEquals(expectedOutput, output.toString()) + Assert.assertEquals(expectedOutput, output.toString()) } } -- cgit