aboutsummaryrefslogtreecommitdiff
path: root/src/Languages
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-10-03 22:51:44 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-10-03 22:51:44 +0400
commit71cd87e239ba4ba846eb5da04e45a451b8a840cb (patch)
treea95a0c385c72b0ba20b2b775a460cc87bc51531c /src/Languages
parentb642b7c35e63729303094483dc2d176ec5ce7a7d (diff)
downloaddokka-71cd87e239ba4ba846eb5da04e45a451b8a840cb.tar.gz
dokka-71cd87e239ba4ba846eb5da04e45a451b8a840cb.tar.bz2
dokka-71cd87e239ba4ba846eb5da04e45a451b8a840cb.zip
Resolve links in docs.
Diffstat (limited to 'src/Languages')
-rw-r--r--src/Languages/JavaLanguageService.kt25
-rw-r--r--src/Languages/KotlinLanguageService.kt29
-rw-r--r--src/Languages/LanguageService.kt17
3 files changed, 47 insertions, 24 deletions
diff --git a/src/Languages/JavaLanguageService.kt b/src/Languages/JavaLanguageService.kt
index 5d2b48f1..8cc54d4a 100644
--- a/src/Languages/JavaLanguageService.kt
+++ b/src/Languages/JavaLanguageService.kt
@@ -2,7 +2,10 @@ package org.jetbrains.dokka
import org.jetbrains.dokka.DocumentationNode.*
-class JavaLanguageService : LanguageService {
+/**
+ * Implements [LanguageService] and provides rendering of symbols in Java language
+ */
+public class JavaLanguageService : LanguageService {
override fun render(node: DocumentationNode): ContentNode {
return ContentText(when (node.kind) {
Kind.Package -> renderPackage(node)
@@ -30,11 +33,11 @@ class JavaLanguageService : LanguageService {
}
}
- fun renderPackage(node: DocumentationNode): String {
+ private fun renderPackage(node: DocumentationNode): String {
return "package ${node.name}"
}
- fun renderModifier(node: DocumentationNode): String {
+ private fun renderModifier(node: DocumentationNode): String {
return when (node.name) {
"open" -> ""
"internal" -> ""
@@ -42,7 +45,7 @@ class JavaLanguageService : LanguageService {
}
}
- fun renderType(node: DocumentationNode): String {
+ private fun renderType(node: DocumentationNode): String {
return when (node.name) {
"Unit" -> "void"
"Int" -> "int"
@@ -56,7 +59,7 @@ class JavaLanguageService : LanguageService {
}
}
- fun renderTypeParameter(node: DocumentationNode): String {
+ private fun renderTypeParameter(node: DocumentationNode): String {
val constraints = node.details(Kind.UpperBound)
return if (constraints.none())
node.name
@@ -65,11 +68,11 @@ class JavaLanguageService : LanguageService {
}
}
- fun renderParameter(node: DocumentationNode): String {
+ private fun renderParameter(node: DocumentationNode): String {
return "${renderType(node.detail(Kind.Type))} ${node.name}"
}
- fun renderTypeParametersForNode(node: DocumentationNode): String {
+ private fun renderTypeParametersForNode(node: DocumentationNode): String {
return StringBuilder {
val typeParameters = node.details(Kind.TypeParameter)
if (typeParameters.any()) {
@@ -80,14 +83,14 @@ class JavaLanguageService : LanguageService {
}.toString()
}
- fun renderModifiersForNode(node: DocumentationNode): String {
+ private fun renderModifiersForNode(node: DocumentationNode): String {
val modifiers = node.details(Kind.Modifier).map { renderModifier(it) }.filter { it != "" }
if (modifiers.none())
return ""
return modifiers.join(" ", postfix = " ")
}
- fun renderClass(node: DocumentationNode): String {
+ private fun renderClass(node: DocumentationNode): String {
return StringBuilder {
when (node.kind) {
Kind.Class -> append("class ")
@@ -103,7 +106,7 @@ class JavaLanguageService : LanguageService {
}.toString()
}
- fun renderFunction(node: DocumentationNode): String {
+ private fun renderFunction(node: DocumentationNode): String {
return StringBuilder {
when (node.kind) {
Kind.Constructor -> append(node.owner?.name)
@@ -127,7 +130,7 @@ class JavaLanguageService : LanguageService {
}.toString()
}
- fun renderProperty(node: DocumentationNode): String {
+ private fun renderProperty(node: DocumentationNode): String {
return StringBuilder {
when (node.kind) {
Kind.Property -> append("val ")
diff --git a/src/Languages/KotlinLanguageService.kt b/src/Languages/KotlinLanguageService.kt
index 46b58574..f806dd19 100644
--- a/src/Languages/KotlinLanguageService.kt
+++ b/src/Languages/KotlinLanguageService.kt
@@ -2,6 +2,9 @@ package org.jetbrains.dokka
import org.jetbrains.dokka.DocumentationNode.*
+/**
+ * Implements [LanguageService] and provides rendering of symbols in Kotlin language
+ */
class KotlinLanguageService : LanguageService {
override fun render(node: DocumentationNode): ContentNode {
return content {
@@ -33,13 +36,13 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderPackage(node: DocumentationNode) {
+ private fun ContentNode.renderPackage(node: DocumentationNode) {
keyword("package")
text(" ")
identifier(node.name)
}
- fun ContentNode.renderList(nodes: List<DocumentationNode>, separator: String = ", ", renderItem: (DocumentationNode) -> Unit) {
+ private fun ContentNode.renderList(nodes: List<DocumentationNode>, separator: String = ", ", renderItem: (DocumentationNode) -> Unit) {
if (nodes.none())
return
renderItem(nodes.first())
@@ -49,7 +52,7 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderLinked(node: DocumentationNode, body: ContentNode.(DocumentationNode)->Unit) {
+ private fun ContentNode.renderLinked(node: DocumentationNode, body: ContentNode.(DocumentationNode)->Unit) {
val to = node.links.firstOrNull()
if (to == null)
body(node)
@@ -59,7 +62,7 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderType(node: DocumentationNode) {
+ private fun ContentNode.renderType(node: DocumentationNode) {
val typeArguments = node.details(Kind.Type)
if (node.name == "Function${typeArguments.count() - 1}") {
// lambda
@@ -99,7 +102,7 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderModifier(node: DocumentationNode) {
+ private fun ContentNode.renderModifier(node: DocumentationNode) {
when (node.name) {
"final", "internal" -> {
}
@@ -107,7 +110,7 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderTypeParameter(node: DocumentationNode) {
+ private fun ContentNode.renderTypeParameter(node: DocumentationNode) {
val constraints = node.details(Kind.UpperBound)
identifier(node.name)
if (constraints.any()) {
@@ -118,14 +121,14 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderParameter(node: DocumentationNode) {
+ private fun ContentNode.renderParameter(node: DocumentationNode) {
identifier(node.name)
symbol(": ")
val parameterType = node.detail(Kind.Type)
renderType(parameterType)
}
- fun ContentNode.renderTypeParametersForNode(node: DocumentationNode) {
+ private fun ContentNode.renderTypeParametersForNode(node: DocumentationNode) {
val typeParameters = node.details(Kind.TypeParameter)
if (typeParameters.any()) {
symbol("<")
@@ -136,7 +139,7 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderSupertypesForNode(node: DocumentationNode) {
+ private fun ContentNode.renderSupertypesForNode(node: DocumentationNode) {
val supertypes = node.details(Kind.Supertype)
if (supertypes.any()) {
symbol(" : ")
@@ -146,7 +149,7 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderModifiersForNode(node: DocumentationNode) {
+ private fun ContentNode.renderModifiersForNode(node: DocumentationNode) {
val modifiers = node.details(Kind.Modifier)
for (it in modifiers) {
if (node.kind == Kind.Interface && it.name == "abstract")
@@ -156,7 +159,7 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderClass(node: DocumentationNode) {
+ private fun ContentNode.renderClass(node: DocumentationNode) {
renderModifiersForNode(node)
when (node.kind) {
Kind.Class -> keyword("class ")
@@ -172,7 +175,7 @@ class KotlinLanguageService : LanguageService {
renderSupertypesForNode(node)
}
- fun ContentNode.renderFunction(node: DocumentationNode) {
+ private fun ContentNode.renderFunction(node: DocumentationNode) {
renderModifiersForNode(node)
when (node.kind) {
Kind.Constructor -> identifier(node.owner!!.name)
@@ -200,7 +203,7 @@ class KotlinLanguageService : LanguageService {
}
}
- fun ContentNode.renderProperty(node: DocumentationNode) {
+ private fun ContentNode.renderProperty(node: DocumentationNode) {
renderModifiersForNode(node)
when (node.kind) {
Kind.Property -> keyword("val ")
diff --git a/src/Languages/LanguageService.kt b/src/Languages/LanguageService.kt
index 26217d41..bf55ac2c 100644
--- a/src/Languages/LanguageService.kt
+++ b/src/Languages/LanguageService.kt
@@ -1,7 +1,24 @@
package org.jetbrains.dokka
+/**
+ * Provides facility for rendering [DocumentationNode] as a language-dependent declaration
+ */
trait LanguageService {
+ /**
+ * Renders [node] as a class, function, property or other signature
+ * $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
+
+ /**
+ * Renders [node] as a named representation in the target language
+ *
+ * See also [google](http://google.com)
+ *
+ * $node: A [DocumentationNode] to render
+ * $returns: [String] which is a string representation of the node
+ */
fun renderName(node: DocumentationNode) : String
}