aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2016-07-01 17:47:03 +0200
committerDmitry Jemerov <yole@jetbrains.com>2016-07-01 17:47:03 +0200
commit625ea7d5d679399a24877d4f6988d58ce2662a8c (patch)
tree1009a6b208dfa84ca2213fd57a1b4f519007e897 /core/src
parentcb97c45aa0b0204ebc61a149794518d50b262814 (diff)
downloaddokka-625ea7d5d679399a24877d4f6988d58ce2662a8c.tar.gz
dokka-625ea7d5d679399a24877d4f6988d58ce2662a8c.tar.bz2
dokka-625ea7d5d679399a24877d4f6988d58ce2662a8c.zip
extract stateful builder out of FormatService
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/Formats/FormatService.kt12
-rw-r--r--core/src/main/kotlin/Formats/GFMFormatService.kt21
-rw-r--r--core/src/main/kotlin/Formats/HtmlFormatService.kt51
-rw-r--r--core/src/main/kotlin/Formats/JekyllFormatService.kt36
-rw-r--r--core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt19
-rw-r--r--core/src/main/kotlin/Formats/MarkdownFormatService.kt25
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt34
-rw-r--r--core/src/test/kotlin/format/GFMFormatTest.kt2
-rw-r--r--core/src/test/kotlin/format/HtmlFormatTest.kt119
-rw-r--r--core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt2
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt147
11 files changed, 243 insertions, 225 deletions
diff --git a/core/src/main/kotlin/Formats/FormatService.kt b/core/src/main/kotlin/Formats/FormatService.kt
index aa4e925c..e281f2fc 100644
--- a/core/src/main/kotlin/Formats/FormatService.kt
+++ b/core/src/main/kotlin/Formats/FormatService.kt
@@ -11,12 +11,18 @@ interface FormatService {
/** Returns extension for output files */
val extension: String
- /** Appends formatted content to [StringBuilder](to) using specified [location] */
- fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>)
+ fun createOutputBuilder(to: StringBuilder, location: Location): FormattedOutputBuilder
fun enumerateSupportFiles(callback: (resource: String, targetPath: String) -> Unit) {
}
}
+interface FormattedOutputBuilder {
+ /** Appends formatted content to [StringBuilder](to) using specified [location] */
+ fun appendNodes(nodes: Iterable<DocumentationNode>)
+}
+
/** Format content to [String] using specified [location] */
-fun FormatService.format(location: Location, nodes: Iterable<DocumentationNode>): String = StringBuilder().apply { appendNodes(location, this, nodes) }.toString()
+fun FormatService.format(location: Location, nodes: Iterable<DocumentationNode>): String = StringBuilder().apply {
+ createOutputBuilder(this, location).appendNodes(nodes)
+}.toString()
diff --git a/core/src/main/kotlin/Formats/GFMFormatService.kt b/core/src/main/kotlin/Formats/GFMFormatService.kt
index 7b1eab85..b57fa932 100644
--- a/core/src/main/kotlin/Formats/GFMFormatService.kt
+++ b/core/src/main/kotlin/Formats/GFMFormatService.kt
@@ -2,6 +2,20 @@ package org.jetbrains.dokka
import com.google.inject.Inject
+open class GFMOutputBuilder(to: StringBuilder,
+ location: Location,
+ locationService: LocationService,
+ languageService: LanguageService,
+ extension: String)
+ : MarkdownOutputBuilder(to, location, locationService, languageService, extension)
+{
+ override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) {
+ to.appendln(columns.joinToString(" | ", "| ", " |"))
+ to.appendln("|" + "---|".repeat(columns.size))
+ body()
+ }
+}
+
open class GFMFormatService(locationService: LocationService,
signatureGenerator: LanguageService,
linkExtension: String)
@@ -10,9 +24,6 @@ open class GFMFormatService(locationService: LocationService,
@Inject constructor(locationService: LocationService,
signatureGenerator: LanguageService) : this(locationService, signatureGenerator, "md")
- override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) {
- to.appendln(columns.joinToString(" | ", "| ", " "))
- to.appendln("|" + "---|".repeat(columns.size))
- body()
- }
+ override fun createOutputBuilder(to: StringBuilder, location: Location): FormattedOutputBuilder =
+ GFMOutputBuilder(to, location, locationService, languageService, extension)
}
diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt
index c7443128..fff8f553 100644
--- a/core/src/main/kotlin/Formats/HtmlFormatService.kt
+++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt
@@ -6,10 +6,14 @@ import java.io.File
import java.nio.file.Path
import java.nio.file.Paths
-open class HtmlFormatService @Inject constructor(@Named("folders") locationService: LocationService,
- signatureGenerator: LanguageService,
- val templateService: HtmlTemplateService)
-: StructuredFormatService(locationService, signatureGenerator, "html"), OutlineFormatService {
+open class HtmlOutputBuilder(to: StringBuilder,
+ location: Location,
+ locationService: LocationService,
+ languageService: LanguageService,
+ extension: String,
+ val templateService: HtmlTemplateService)
+ : StructuredOutputBuilder(to, location, locationService, languageService, extension)
+{
override fun formatText(text: String): String {
return text.htmlEscape()
}
@@ -105,23 +109,33 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi
}
- override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
- templateService.appendHeader(to, getPageTitle(nodes), calcPathToRoot(location))
- super.appendNodes(location, to, nodes)
+ override fun appendNodes(nodes: Iterable<DocumentationNode>) {
+ templateService.appendHeader(to, getPageTitle(nodes), locationService.calcPathToRoot(location))
+ super.appendNodes(nodes)
templateService.appendFooter(to)
}
+ override fun formatNonBreakingSpace(): String = "&nbsp;"
+}
+
+open class HtmlFormatService @Inject constructor(@Named("folders") locationService: LocationService,
+ signatureGenerator: LanguageService,
+ val templateService: HtmlTemplateService)
+: StructuredFormatService(locationService, signatureGenerator, "html"), OutlineFormatService {
+
+ override fun enumerateSupportFiles(callback: (String, String) -> Unit) {
+ callback("/dokka/styles/style.css", "style.css")
+ }
+
+ override fun createOutputBuilder(to: StringBuilder, location: Location) =
+ HtmlOutputBuilder(to, location, locationService, languageService, extension, templateService)
+
override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
- templateService.appendHeader(to, "Module Contents", calcPathToRoot(location))
+ templateService.appendHeader(to, "Module Contents", locationService.calcPathToRoot(location))
super.appendOutline(location, to, nodes)
templateService.appendFooter(to)
}
- private fun calcPathToRoot(location: Location): Path {
- val path = Paths.get(location.path)
- return path.parent?.relativize(Paths.get(locationService.root.path + '/')) ?: path
- }
-
override fun getOutlineFileName(location: Location): File {
return File("${location.path}-outline.html")
}
@@ -129,7 +143,7 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi
override fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder) {
val link = ContentNodeDirectLink(node)
link.append(languageService.render(node, LanguageService.RenderMode.FULL))
- val signature = formatText(location, link)
+ val signature = createOutputBuilder(to, location).formatText(location, link)
to.appendln("<a href=\"${location.path}\">${signature}</a><br/>")
}
@@ -138,12 +152,11 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi
body()
to.appendln("</ul>")
}
+}
- override fun formatNonBreakingSpace(): String = "&nbsp;"
-
- override fun enumerateSupportFiles(callback: (String, String) -> Unit) {
- callback("/dokka/styles/style.css", "style.css")
- }
+private fun LocationService.calcPathToRoot(location: Location): Path {
+ val path = Paths.get(location.path)
+ return path.parent?.relativize(Paths.get(root.path + '/')) ?: path
}
fun getPageTitle(nodes: Iterable<DocumentationNode>): String? {
diff --git a/core/src/main/kotlin/Formats/JekyllFormatService.kt b/core/src/main/kotlin/Formats/JekyllFormatService.kt
index 9271e3a9..bab73379 100644
--- a/core/src/main/kotlin/Formats/JekyllFormatService.kt
+++ b/core/src/main/kotlin/Formats/JekyllFormatService.kt
@@ -2,23 +2,37 @@ package org.jetbrains.dokka
import com.google.inject.Inject
-open class JekyllFormatService(locationService: LocationService,
- signatureGenerator: LanguageService,
- linkExtension: String)
-: MarkdownFormatService(locationService, signatureGenerator, linkExtension) {
-
- @Inject constructor(locationService: LocationService,
- signatureGenerator: LanguageService): this(locationService, signatureGenerator, "md")
-
- override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+open class JekyllOutputBuilder(to: StringBuilder,
+ location: Location,
+ locationService: LocationService,
+ languageService: LanguageService,
+ extension: String)
+ : MarkdownOutputBuilder(to, location, locationService, languageService, extension)
+{
+ override fun appendNodes(nodes: Iterable<DocumentationNode>) {
to.appendln("---")
appendFrontMatter(nodes, to)
to.appendln("---")
to.appendln("")
- super.appendNodes(location, to, nodes)
+ super.appendNodes(nodes)
}
protected open fun appendFrontMatter(nodes: Iterable<DocumentationNode>, to: StringBuilder) {
to.appendln("title: ${getPageTitle(nodes)}")
}
-} \ No newline at end of file
+}
+
+
+open class JekyllFormatService(locationService: LocationService,
+ signatureGenerator: LanguageService,
+ linkExtension: String)
+: MarkdownFormatService(locationService, signatureGenerator, linkExtension) {
+
+ @Inject constructor(locationService: LocationService,
+ signatureGenerator: LanguageService): this(locationService, signatureGenerator, "md") {
+ }
+
+ override fun createOutputBuilder(to: StringBuilder, location: Location): FormattedOutputBuilder =
+ JekyllOutputBuilder(to, location, locationService, languageService, extension)
+
+}
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
index 1f3a3750..e3229523 100644
--- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
+++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
@@ -2,9 +2,14 @@ package org.jetbrains.dokka
import com.google.inject.Inject
-class KotlinWebsiteFormatService @Inject constructor(locationService: LocationService,
- signatureGenerator: LanguageService)
-: JekyllFormatService(locationService, signatureGenerator, "html") {
+
+class KotlinWebsiteOutputBuilder(to: StringBuilder,
+ location: Location,
+ locationService: LocationService,
+ languageService: LanguageService,
+ extension: String)
+ : JekyllOutputBuilder(to, location, locationService, languageService, extension)
+{
private var needHardLineBreaks = false
private var insideDiv = 0
@@ -140,3 +145,11 @@ class KotlinWebsiteFormatService @Inject constructor(locationService: LocationSe
else -> "identifier"
}
}
+
+class KotlinWebsiteFormatService @Inject constructor(locationService: LocationService,
+ signatureGenerator: LanguageService)
+ : JekyllFormatService(locationService, signatureGenerator, "html")
+{
+ override fun createOutputBuilder(to: StringBuilder, location: Location) =
+ KotlinWebsiteOutputBuilder(to, location, locationService, languageService, extension)
+}
diff --git a/core/src/main/kotlin/Formats/MarkdownFormatService.kt b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
index 79177239..5ddb7f1f 100644
--- a/core/src/main/kotlin/Formats/MarkdownFormatService.kt
+++ b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
@@ -3,13 +3,13 @@ package org.jetbrains.dokka
import com.google.inject.Inject
-open class MarkdownFormatService(locationService: LocationService,
- signatureGenerator: LanguageService,
- linkExtension: String)
-: StructuredFormatService(locationService, signatureGenerator, "md", linkExtension) {
- @Inject constructor(locationService: LocationService,
- signatureGenerator: LanguageService): this(locationService, signatureGenerator, "md")
-
+open class MarkdownOutputBuilder(to: StringBuilder,
+ location: Location,
+ locationService: LocationService,
+ languageService: LanguageService,
+ extension: String)
+ : StructuredOutputBuilder(to, location, locationService, languageService, extension)
+{
override fun formatBreadcrumbs(items: Iterable<FormatLink>): String {
return items.map { formatLink(it) }.joinToString(" / ")
}
@@ -99,3 +99,14 @@ open class MarkdownFormatService(locationService: LocationService,
override fun formatNonBreakingSpace(): String = "&nbsp;"
}
+
+open class MarkdownFormatService(locationService: LocationService,
+ signatureGenerator: LanguageService,
+ linkExtension: String)
+: StructuredFormatService(locationService, signatureGenerator, "md", linkExtension) {
+ @Inject constructor(locationService: LocationService,
+ signatureGenerator: LanguageService): this(locationService, signatureGenerator, "md")
+
+ override fun createOutputBuilder(to: StringBuilder, location: Location): FormattedOutputBuilder =
+ MarkdownOutputBuilder(to, location, locationService, languageService, extension)
+}
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index 72b6833d..407c7018 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -10,11 +10,11 @@ enum class ListKind {
Unordered
}
-abstract class StructuredFormatService(locationService: LocationService,
+abstract class StructuredOutputBuilder(val to: StringBuilder,
+ val location: Location,
+ val locationService: LocationService,
val languageService: LanguageService,
- override val extension: String,
- val linkExtension: String = extension) : FormatService {
- val locationService: LocationService = locationService.withExtension(linkExtension)
+ val extension: String) : FormattedOutputBuilder {
abstract fun appendBlockCode(to: StringBuilder, lines: List<String>, language: String)
abstract fun appendHeader(to: StringBuilder, text: String, level: Int = 1)
@@ -141,7 +141,7 @@ abstract class StructuredFormatService(locationService: LocationService,
}
}
- open inner class PageBuilder(val location: Location, val to: StringBuilder, val nodes: Iterable<DocumentationNode>) {
+ open inner class PageBuilder(val nodes: Iterable<DocumentationNode>) {
open fun build() {
val breakdownByLocation = nodes.groupBy { node ->
formatBreadcrumbs(node.path.filterNot { it.name.isEmpty() }.map { link(node, it) })
@@ -285,8 +285,8 @@ abstract class StructuredFormatService(locationService: LocationService,
}
}
- inner class SingleNodePageBuilder(location: Location, to: StringBuilder, val node: DocumentationNode)
- : PageBuilder(location, to, listOf(node)) {
+ inner class SingleNodePageBuilder(val node: DocumentationNode)
+ : PageBuilder(listOf(node)) {
override fun build() {
super.build()
@@ -397,8 +397,8 @@ abstract class StructuredFormatService(locationService: LocationService,
}
}
- inner class AllTypesNodeBuilder(location: Location, to: StringBuilder, val node: DocumentationNode)
- : PageBuilder(location, to, listOf(node)) {
+ inner class AllTypesNodeBuilder(val node: DocumentationNode)
+ : PageBuilder(listOf(node)) {
override fun build() {
to.append(formatText(location, node.owner!!.summary))
@@ -429,18 +429,26 @@ abstract class StructuredFormatService(locationService: LocationService,
}
}
- override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ override fun appendNodes(nodes: Iterable<DocumentationNode>) {
val singleNode = nodes.singleOrNull()
if (singleNode != null) {
if (singleNode.kind == NodeKind.AllTypes) {
- AllTypesNodeBuilder(location, to, singleNode).build()
+ AllTypesNodeBuilder(singleNode).build()
}
else {
- SingleNodePageBuilder(location, to, singleNode).build()
+ SingleNodePageBuilder(singleNode).build()
}
}
else {
- PageBuilder(location, to, nodes).build()
+ PageBuilder(nodes).build()
}
}
+
+}
+
+abstract class StructuredFormatService(locationService: LocationService,
+ val languageService: LanguageService,
+ override val extension: String,
+ val linkExtension: String = extension) : FormatService {
+ val locationService: LocationService = locationService.withExtension(linkExtension)
}
diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt
index 7f7ee286..d21885d3 100644
--- a/core/src/test/kotlin/format/GFMFormatTest.kt
+++ b/core/src/test/kotlin/format/GFMFormatTest.kt
@@ -13,7 +13,7 @@ class GFMFormatTest {
private fun verifyGFMNodeByName(fileName: String, name: String) {
verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output ->
- gfmService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == name })
+ gfmService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name })
}
}
}
diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt
index 9936b8e2..2f92366b 100644
--- a/core/src/test/kotlin/format/HtmlFormatTest.kt
+++ b/core/src/test/kotlin/format/HtmlFormatTest.kt
@@ -1,8 +1,6 @@
package org.jetbrains.dokka.tests
-import org.jetbrains.dokka.HtmlFormatService
-import org.jetbrains.dokka.HtmlTemplateService
-import org.jetbrains.dokka.KotlinLanguageService
+import org.jetbrains.dokka.*
import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
import org.jetbrains.kotlin.config.KotlinSourceRoot
import org.junit.Test
@@ -12,152 +10,112 @@ class HtmlFormatTest {
private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService(), HtmlTemplateService.default())
@Test fun classWithCompanionObject() {
- verifyOutput("testdata/format/classWithCompanionObject.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("classWithCompanionObject")
}
@Test fun htmlEscaping() {
- verifyOutput("testdata/format/htmlEscaping.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("htmlEscaping")
}
@Test fun overloads() {
- verifyOutput("testdata/format/overloads.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members)
- }
+ verifyHtmlNodes("overloads") { model -> model.members }
}
@Test fun overloadsWithDescription() {
- verifyOutput("testdata/format/overloadsWithDescription.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("overloadsWithDescription")
}
@Test fun overloadsWithDifferentDescriptions() {
- verifyOutput("testdata/format/overloadsWithDifferentDescriptions.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("overloadsWithDifferentDescriptions")
}
@Test fun deprecated() {
verifyOutput("testdata/format/deprecated.kt", ".package.html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members)
+ htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members)
}
verifyOutput("testdata/format/deprecated.kt", ".class.html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
+ htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members)
}
}
@Test fun brokenLink() {
- verifyOutput("testdata/format/brokenLink.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("brokenLink")
}
@Test fun codeSpan() {
- verifyOutput("testdata/format/codeSpan.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("codeSpan")
}
@Test fun parenthesis() {
- verifyOutput("testdata/format/parenthesis.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("parenthesis")
}
@Test fun bracket() {
- verifyOutput("testdata/format/bracket.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("bracket")
}
@Test fun see() {
- verifyOutput("testdata/format/see.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("see")
}
@Test fun tripleBackticks() {
- verifyOutput("testdata/format/tripleBackticks.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("tripleBackticks")
}
@Test fun typeLink() {
- verifyOutput("testdata/format/typeLink.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar"} )
- }
+ verifyHtmlNodes("typeLink") { model -> model.members.single().members.filter { it.name == "Bar" } }
}
@Test fun parameterAnchor() {
- verifyOutput("testdata/format/parameterAnchor.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("parameterAnchor")
}
@Test fun javaSupertypeLink() {
- verifyJavaOutput("testdata/format/javaSupertype.java", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members.single { it.name == "C"}.members.filter { it.name == "Bar"} )
+ verifyJavaHtmlNodes("javaSupertype") { model ->
+ model.members.single().members.single { it.name == "C" }.members.filter { it.name == "Bar" }
}
}
@Test fun javaLinkTag() {
- verifyJavaOutput("testdata/format/javaLinkTag.java", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyJavaHtmlNode("javaLinkTag")
}
@Test fun javaLinkTagWithLabel() {
- verifyJavaOutput("testdata/format/javaLinkTagWithLabel.java", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyJavaHtmlNode("javaLinkTagWithLabel")
}
@Test fun javaSeeTag() {
- verifyJavaOutput("testdata/format/javaSeeTag.java", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyJavaHtmlNode("javaSeeTag")
}
@Test fun javaDeprecated() {
- verifyJavaOutput("testdata/format/javaDeprecated.java", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" })
+ verifyJavaHtmlNodes("javaDeprecated") { model ->
+ model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" }
}
}
@Test fun crossLanguageKotlinExtendsJava() {
verifyOutput(arrayOf(KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"),
- JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null)),
+ JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null)),
".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" })
+ htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == "Bar" })
}
}
@Test fun orderedList() {
- verifyOutput("testdata/format/orderedList.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" })
- }
+ verifyHtmlNodes("orderedList") { model -> model.members.single().members.filter { it.name == "Bar" } }
}
@Test fun linkWithLabel() {
- verifyOutput("testdata/format/linkWithLabel.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" })
- }
+ verifyHtmlNodes("linkWithLabel") { model -> model.members.single().members.filter { it.name == "Bar" } }
}
@Test fun entity() {
- verifyOutput("testdata/format/entity.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" })
- }
+ verifyHtmlNodes("entity") { model -> model.members.single().members.filter { it.name == "Bar" } }
}
@Test fun uninterpretedEmphasisCharacters() {
- verifyOutput("testdata/format/uninterpretedEmphasisCharacters.kt", ".html") { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyHtmlNode("uninterpretedEmphasisCharacters")
}
@Test fun markdownInLinks() {
@@ -173,10 +131,27 @@ class HtmlFormatTest {
}
private fun verifyHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) {
+ verifyHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members }
+ }
+
+ private fun verifyHtmlNodes(fileName: String,
+ withKotlinRuntime: Boolean = false,
+ nodeFilter: (DocumentationModule) -> List<DocumentationNode>) {
verifyOutput("testdata/format/$fileName.kt", ".html", withKotlinRuntime = withKotlinRuntime) { model, output ->
- htmlService.appendNodes(tempLocation, output, model.members.single().members)
+ htmlService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model))
}
}
+ private fun verifyJavaHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) {
+ verifyJavaHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members }
+ }
+
+ private fun verifyJavaHtmlNodes(fileName: String,
+ withKotlinRuntime: Boolean = false,
+ nodeFilter: (DocumentationModule) -> List<DocumentationNode>) {
+ verifyJavaOutput("testdata/format/$fileName.java", ".html", withKotlinRuntime = withKotlinRuntime) { model, output ->
+ htmlService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model))
+ }
+ }
}
diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt
index d4738b2f..e6ef792a 100644
--- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt
+++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt
@@ -17,7 +17,7 @@ class KotlinWebSiteFormatTest {
private fun verifyKWSNodeByName(fileName: String, name: String) {
verifyOutput("testdata/format/website/$fileName.kt", ".md") { model, output ->
- kwsService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == name })
+ kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name })
}
}
}
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 84bf082b..cad1977d 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -1,5 +1,7 @@
package org.jetbrains.dokka.tests
+import org.jetbrains.dokka.DocumentationModule
+import org.jetbrains.dokka.DocumentationNode
import org.jetbrains.dokka.KotlinLanguageService
import org.jetbrains.dokka.MarkdownFormatService
import org.junit.Test
@@ -8,21 +10,15 @@ class MarkdownFormatTest {
private val markdownService = MarkdownFormatService(InMemoryLocationService, KotlinLanguageService())
@Test fun emptyDescription() {
- verifyOutput("testdata/format/emptyDescription.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("emptyDescription")
}
@Test fun classWithCompanionObject() {
- verifyOutput("testdata/format/classWithCompanionObject.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("classWithCompanionObject")
}
@Test fun annotations() {
- verifyOutput("testdata/format/annotations.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("annotations")
}
@Test fun annotationClass() {
@@ -36,74 +32,60 @@ class MarkdownFormatTest {
}
@Test fun annotationParams() {
- verifyOutput("testdata/format/annotationParams.kt", ".md", withKotlinRuntime = true) { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("annotationParams", withKotlinRuntime = true)
}
@Test fun extensions() {
verifyOutput("testdata/format/extensions.kt", ".package.md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members)
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members)
}
verifyOutput("testdata/format/extensions.kt", ".class.md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members)
}
}
@Test fun enumClass() {
verifyOutput("testdata/format/enumClass.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members)
}
verifyOutput("testdata/format/enumClass.kt", ".value.md") { model, output ->
val enumClassNode = model.members.single().members[0]
- markdownService.appendNodes(tempLocation, output,
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(
enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" })
}
}
@Test fun varargsFunction() {
- verifyOutput("testdata/format/varargsFunction.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("varargsFunction")
}
@Test fun overridingFunction() {
- verifyOutput("testdata/format/overridingFunction.kt", ".md") { model, output ->
+ verifyMarkdownNodes("overridingFunction") { model->
val classMembers = model.members.single().members.first { it.name == "D" }.members
- markdownService.appendNodes(tempLocation, output, classMembers.filter { it.name == "f" })
+ classMembers.filter { it.name == "f" }
}
-
}
@Test fun propertyVar() {
- verifyOutput("testdata/format/propertyVar.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("propertyVar")
}
@Test fun functionWithDefaultParameter() {
- verifyOutput("testdata/format/functionWithDefaultParameter.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("functionWithDefaultParameter")
}
@Test fun accessor() {
- verifyOutput("testdata/format/accessor.kt", ".md") { model, output ->
- val propertyNode = model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" }
- markdownService.appendNodes(tempLocation, output, propertyNode)
+ verifyMarkdownNodes("accessor") { model ->
+ model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" }
}
}
@Test fun paramTag() {
- verifyOutput("testdata/format/paramTag.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("paramTag")
}
@Test fun throwsTag() {
- verifyOutput("testdata/format/throwsTag.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("throwsTag")
}
@Test fun typeParameterBounds() {
@@ -115,99 +97,71 @@ class MarkdownFormatTest {
}
@Test fun typeProjectionVariance() {
- verifyOutput("testdata/format/typeProjectionVariance.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("typeProjectionVariance")
}
@Test fun javadocHtml() {
- verifyJavaOutput("testdata/format/javadocHtml.java", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyJavaMarkdownNode("javadocHtml")
}
@Test fun javaCodeLiteralTags() {
- verifyJavaOutput("testdata/format/javaCodeLiteralTags.java", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyJavaMarkdownNode("javaCodeLiteralTags")
}
@Test fun javaCodeInParam() {
- verifyJavaOutput("testdata/format/javaCodeInParam.java", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyJavaMarkdownNode("javaCodeInParam")
}
@Test fun javaSpaceInAuthor() {
- verifyJavaOutput("testdata/format/javaSpaceInAuthor.java", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyJavaMarkdownNode("javaSpaceInAuthor")
}
@Test fun nullability() {
- verifyOutput("testdata/format/nullability.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("nullability")
}
@Test fun operatorOverloading() {
- verifyOutput("testdata/format/operatorOverloading.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" })
+ verifyMarkdownNodes("operatorOverloading") { model->
+ model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" }
}
}
@Test fun javadocOrderedList() {
- verifyJavaOutput("testdata/format/javadocOrderedList.java", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" })
+ verifyJavaMarkdownNodes("javadocOrderedList") { model ->
+ model.members.single().members.filter { it.name == "Bar" }
}
}
@Test fun companionObjectExtension() {
- verifyOutput("testdata/format/companionObjectExtension.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Foo" })
- }
+ verifyMarkdownNodeByName("companionObjectExtension", "Foo")
}
@Test fun starProjection() {
- verifyOutput("testdata/format/starProjection.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("starProjection")
}
@Test fun extensionFunctionParameter() {
- verifyOutput("testdata/format/extensionFunctionParameter.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("extensionFunctionParameter")
}
@Test fun summarizeSignatures() {
- verifyOutput("testdata/format/summarizeSignatures.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members)
- }
+ verifyMarkdownNodes("summarizeSignatures") { model -> model.members }
}
@Test fun summarizeSignaturesProperty() {
- verifyOutput("testdata/format/summarizeSignaturesProperty.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members)
- }
+ verifyMarkdownNodes("summarizeSignaturesProperty") { model -> model.members }
}
@Test fun reifiedTypeParameter() {
- verifyOutput("testdata/format/reifiedTypeParameter.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("reifiedTypeParameter", withKotlinRuntime = true)
}
@Test fun annotatedTypeParameter() {
- verifyOutput("testdata/format/annotatedTypeParameter.kt", ".md", withKotlinRuntime = true) { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
- }
+ verifyMarkdownNode("annotatedTypeParameter", withKotlinRuntime = true)
}
@Test fun inheritedMembers() {
- verifyOutput("testdata/format/inheritedMembers.kt", ".md") { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" })
- }
+ verifyMarkdownNodeByName("inheritedMembers", "Bar")
}
@Test fun inheritedExtensions() {
@@ -243,9 +197,8 @@ class MarkdownFormatTest {
}
@Test fun extensionWithDocumentedReceiver() {
- verifyOutput("testdata/format/extensionWithDocumentedReceiver.kt", ".md") { model, output ->
- val nodesWithName = model.members.single().members.single().members.filter { it.name == "fn" }
- markdownService.appendNodes(tempLocation, output, nodesWithName)
+ verifyMarkdownNodes("extensionWithDocumentedReceiver") { model ->
+ model.members.single().members.single().members.filter { it.name == "fn" }
}
}
@@ -259,23 +212,37 @@ class MarkdownFormatTest {
private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) {
verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members)
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members)
}
}
private fun verifyMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) {
+ verifyMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members }
+ }
+
+ private fun verifyMarkdownNodes(fileName: String, withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List<DocumentationNode>) {
verifyOutput("testdata/format/$fileName.kt", ".md", withKotlinRuntime = withKotlinRuntime) { model, output ->
- markdownService.appendNodes(tempLocation, output, model.members.single().members)
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model))
+ }
+ }
+
+ private fun verifyJavaMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) {
+ verifyJavaMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members }
+ }
+
+ private fun verifyJavaMarkdownNodes(fileName: String, withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List<DocumentationNode>) {
+ verifyJavaOutput("testdata/format/$fileName.java", ".md", withKotlinRuntime = withKotlinRuntime) { model, output ->
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model))
}
}
private fun verifyMarkdownNodeByName(fileName: String, name: String) {
- verifyOutput("testdata/format/$fileName.kt", ".md") { model, output ->
+ verifyMarkdownNodes(fileName) { model->
val nodesWithName = model.members.single().members.filter { it.name == name }
if (nodesWithName.isEmpty()) {
throw IllegalArgumentException("Found no nodes named $name")
}
- markdownService.appendNodes(tempLocation, output, nodesWithName)
+ nodesWithName
}
}
}