aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-02-26 19:08:59 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-02-26 19:08:59 +0100
commit146764aca661d51daa298c7cfe6b9b5efcff7e5f (patch)
tree8379c830a61ffa9a879e29405c83847b552aa028
parent1e74c644b1163948c389dd9082e0cba60ab5ed65 (diff)
downloaddokka-146764aca661d51daa298c7cfe6b9b5efcff7e5f.tar.gz
dokka-146764aca661d51daa298c7cfe6b9b5efcff7e5f.tar.bz2
dokka-146764aca661d51daa298c7cfe6b9b5efcff7e5f.zip
stop generating separate pages for property accessors
-rw-r--r--src/Formats/StructuredFormatService.kt2
-rw-r--r--src/Java/JavaDocumentationBuilder.kt4
-rw-r--r--src/Kotlin/ContentBuilder.kt4
-rw-r--r--src/Kotlin/DocumentationBuilder.kt38
-rw-r--r--src/Kotlin/KotlinLanguageService.kt5
-rw-r--r--src/Model/Content.kt28
-rw-r--r--src/Model/DocumentationNode.kt12
-rw-r--r--test/data/format/accessor.get.md8
-rw-r--r--test/data/format/accessor.kt4
-rw-r--r--test/data/format/accessor.md18
-rw-r--r--test/data/format/accessor.set.md8
-rw-r--r--test/data/format/deprecated.class.html13
-rw-r--r--test/data/format/deprecated.package.html2
-rw-r--r--test/data/format/extensions.class.md2
-rw-r--r--test/src/format/MarkdownFormatTest.kt10
-rw-r--r--test/src/model/PropertyTest.kt43
16 files changed, 82 insertions, 119 deletions
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index ee835aa0..70967b20 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -267,7 +267,6 @@ public abstract class StructuredFormatService(locationService: LocationService,
appendSection(location, "Functions", node.members(DocumentationNode.Kind.Function), node, to)
appendSection(location, "Default Object Properties", node.members(DocumentationNode.Kind.DefaultObjectProperty), node, to)
appendSection(location, "Default Object Functions", node.members(DocumentationNode.Kind.DefaultObjectFunction), 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(
@@ -280,7 +279,6 @@ public abstract class StructuredFormatService(locationService: LocationService,
DocumentationNode.Kind.Property,
DocumentationNode.Kind.Package,
DocumentationNode.Kind.Function,
- DocumentationNode.Kind.PropertyAccessor,
DocumentationNode.Kind.DefaultObjectProperty,
DocumentationNode.Kind.DefaultObjectFunction,
DocumentationNode.Kind.ExternalClass,
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt
index 4652500e..8183df8f 100644
--- a/src/Java/JavaDocumentationBuilder.kt
+++ b/src/Java/JavaDocumentationBuilder.kt
@@ -18,7 +18,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions,
fun parseDocumentation(docComment: PsiDocComment?): JavadocParseResult {
if (docComment == null) return JavadocParseResult(Content.Empty, null)
- val result = Content()
+ val result = MutableContent()
var deprecatedContent: Content? = null
val para = ContentParagraph()
result.append(para)
@@ -56,7 +56,7 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions,
}
}
- private fun Content.convertSeeTag(tag: PsiDocTag) {
+ private fun MutableContent.convertSeeTag(tag: PsiDocTag) {
val seeSection = findSectionByTag("See Also") ?: addSection("See Also", null)
val linkNode = resolveLink(tag.getValueElement())
val text = ContentText(tag.getValueElement()!!.getText())
diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt
index 56d2a407..4b8897b2 100644
--- a/src/Kotlin/ContentBuilder.kt
+++ b/src/Kotlin/ContentBuilder.kt
@@ -10,8 +10,8 @@ import org.intellij.markdown.*
import org.jetbrains.kotlin.psi.JetDeclarationWithBody
import org.jetbrains.kotlin.psi.JetBlockExpression
-public fun buildContent(tree: MarkdownNode, linkResolver: (String) -> ContentBlock): Content {
- val result = Content()
+public fun buildContent(tree: MarkdownNode, linkResolver: (String) -> ContentBlock): MutableContent {
+ val result = MutableContent()
buildContentTo(tree, result, linkResolver)
return result
}
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index b6bd8701..3910de04 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -136,7 +136,7 @@ class DocumentationBuilder(val session: ResolveSession,
fun KDocSection.getTags(): Array<KDocTag> = PsiTreeUtil.getChildrenOfType(this, javaClass<KDocTag>()) ?: array()
- private fun Content.addTagToSeeAlso(descriptor: DeclarationDescriptor, seeTag: KDocTag) {
+ private fun MutableContent.addTagToSeeAlso(descriptor: DeclarationDescriptor, seeTag: KDocTag) {
val subjectName = seeTag.getSubjectName()
if (subjectName != null) {
val seeSection = findSectionByTag("See Also") ?: addSection("See Also", null)
@@ -321,7 +321,6 @@ class DocumentationBuilder(val session: ResolveSession,
is ConstructorDescriptor -> build()
is ScriptDescriptor -> build()
is PropertyDescriptor -> build()
- is PropertyAccessorDescriptor -> build()
is FunctionDescriptor -> build()
is TypeParameterDescriptor -> build()
is ValueParameterDescriptor -> build()
@@ -414,17 +413,6 @@ class DocumentationBuilder(val session: ResolveSession,
}
}
- fun PropertyAccessorDescriptor.build(): DocumentationNode {
- val doc = parseDocumentation(this)
- val specialName = getName().asString().drop(1).takeWhile { it != '-' }
- val node = DocumentationNode(specialName, doc, Kind.PropertyAccessor).withModifiers(this)
-
- node.appendInPageChildren(getValueParameters(), DocumentationReference.Kind.Detail)
- node.appendType(getReturnType())
- register(this, node)
- return node
- }
-
fun PropertyDescriptor.build(): DocumentationNode {
val node = DocumentationNode(this, if (inClassObject()) Kind.DefaultObjectProperty else Kind.Property)
node.appendInPageChildren(getTypeParameters(), DocumentationReference.Kind.Detail)
@@ -436,12 +424,14 @@ class DocumentationBuilder(val session: ResolveSession,
node.appendTextNode("var", DocumentationNode.Kind.Modifier)
}
getGetter()?.let {
- if (!it.isDefault())
- node.appendChild(it, DocumentationReference.Kind.Member)
+ if (!it.isDefault()) {
+ node.addAccessorDocumentation(parseDocumentation(it), "Getter")
+ }
}
getSetter()?.let {
- if (!it.isDefault())
- node.appendChild(it, DocumentationReference.Kind.Member)
+ if (!it.isDefault()) {
+ node.addAccessorDocumentation(parseDocumentation(it), "Setter")
+ }
}
getOverriddenDescriptors().forEach {
@@ -452,6 +442,20 @@ class DocumentationBuilder(val session: ResolveSession,
return node
}
+ fun DocumentationNode.addAccessorDocumentation(documentation: Content, prefix: String) {
+ if (documentation == Content.Empty) return
+ updateContent {
+ if (!documentation.children.isEmpty()) {
+ val section = addSection(prefix, null)
+ documentation.children.forEach { section.append(it) }
+ }
+ documentation.sections.forEach {
+ val section = addSection("$prefix ${it.tag}", it.subjectName)
+ it.children.forEach { section.append(it) }
+ }
+ }
+ }
+
fun ValueParameterDescriptor.build(): DocumentationNode {
val node = DocumentationNode(this, Kind.Parameter)
val varargType = getVarargElementType()
diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt
index ab1f7016..9836bbda 100644
--- a/src/Kotlin/KotlinLanguageService.kt
+++ b/src/Kotlin/KotlinLanguageService.kt
@@ -26,8 +26,7 @@ class KotlinLanguageService : LanguageService {
DocumentationNode.Kind.Modifier -> renderModifier(node)
DocumentationNode.Kind.Constructor,
DocumentationNode.Kind.Function,
- DocumentationNode.Kind.DefaultObjectFunction,
- DocumentationNode.Kind.PropertyAccessor -> renderFunction(node)
+ DocumentationNode.Kind.DefaultObjectFunction -> renderFunction(node)
DocumentationNode.Kind.Property,
DocumentationNode.Kind.DefaultObjectProperty -> renderProperty(node)
else -> identifier(node.name)
@@ -241,7 +240,6 @@ class KotlinLanguageService : LanguageService {
DocumentationNode.Kind.Constructor -> identifier(node.owner!!.name)
DocumentationNode.Kind.Function,
DocumentationNode.Kind.DefaultObjectFunction -> keyword("fun ")
- DocumentationNode.Kind.PropertyAccessor -> {}
else -> throw IllegalArgumentException("Node $node is not a function-like object")
}
renderTypeParametersForNode(node)
@@ -267,7 +265,6 @@ class KotlinLanguageService : LanguageService {
private fun needReturnType(node: DocumentationNode) = when(node.kind) {
DocumentationNode.Kind.Constructor -> false
- DocumentationNode.Kind.PropertyAccessor -> node.name == "get"
else -> true
}
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index 8e9c068d..66267496 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -98,9 +98,22 @@ fun ContentBlock.link(to: DocumentationNode, body: ContentBlock.() -> Unit) {
append(block)
}
-public class Content() : ContentBlock() {
+public open class Content(): ContentBlock() {
+ public open val sections: List<ContentSection> get() = emptyList()
+ public open val summary: ContentNode get() = ContentEmpty
+ public open val description: ContentNode get() = ContentEmpty
+
+ fun findSectionByTag(tag: String): ContentSection? =
+ sections.firstOrNull { tag.equalsIgnoreCase(it.tag) }
+
+ class object {
+ val Empty = Content()
+ }
+}
+
+public open class MutableContent() : Content() {
private val sectionList = arrayListOf<ContentSection>()
- public val sections: List<ContentSection>
+ public override val sections: List<ContentSection>
get() = sectionList
fun addSection(tag: String?, subjectName: String?): ContentSection {
@@ -109,12 +122,9 @@ public class Content() : ContentBlock() {
return section
}
- fun findSectionByTag(tag: String): ContentSection? =
- sections.firstOrNull { tag.equalsIgnoreCase(it.tag) }
-
- public val summary: ContentNode get() = children.firstOrNull() ?: ContentEmpty
+ public override val summary: ContentNode get() = children.firstOrNull() ?: ContentEmpty
- public val description: ContentNode by Delegates.lazy {
+ public override val description: ContentNode by Delegates.lazy {
val descriptionNodes = children.drop(1)
if (descriptionNodes.isEmpty()) {
ContentEmpty
@@ -143,10 +153,6 @@ public class Content() : ContentBlock() {
val isEmpty: Boolean
get() = sections.none()
-
- class object {
- val Empty = Content()
- }
}
fun javadocSectionDisplayName(sectionName: String?): String? =
diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt
index f0c3ddf5..8fec29c4 100644
--- a/src/Model/DocumentationNode.kt
+++ b/src/Model/DocumentationNode.kt
@@ -3,11 +3,14 @@ package org.jetbrains.dokka
import java.util.LinkedHashSet
public open class DocumentationNode(val name: String,
- val content: Content,
+ content: Content,
val kind: DocumentationNode.Kind) {
private val references = LinkedHashSet<DocumentationReference>()
+ var content: Content = content
+ private set
+
public val summary: ContentNode get() = content.summary
public val owner: DocumentationNode?
@@ -38,6 +41,13 @@ public open class DocumentationNode(val name: String,
references.addAll(other.references)
}
+ public fun updateContent(body: MutableContent.() -> Unit) {
+ if (content !is MutableContent) {
+ content = MutableContent()
+ }
+ (content as MutableContent).body()
+ }
+
public fun details(kind: DocumentationNode.Kind): List<DocumentationNode> = details.filter { it.kind == kind }
public fun members(kind: DocumentationNode.Kind): List<DocumentationNode> = members.filter { it.kind == kind }
public fun links(kind: DocumentationNode.Kind): List<DocumentationNode> = links.filter { it.kind == kind }
diff --git a/test/data/format/accessor.get.md b/test/data/format/accessor.get.md
deleted file mode 100644
index 67a2f395..00000000
--- a/test/data/format/accessor.get.md
+++ /dev/null
@@ -1,8 +0,0 @@
-[test](test/index) / [C](test/-c/index) / [x](test/-c/x/index) / [get](test/-c/x/get)
-
-
-# get
-
-`get(): String`
-
-
diff --git a/test/data/format/accessor.kt b/test/data/format/accessor.kt
index b6ed9624..5a4d1742 100644
--- a/test/data/format/accessor.kt
+++ b/test/data/format/accessor.kt
@@ -1,5 +1,5 @@
class C() {
var x: String
- get() = ""
- set(value) { }
+ /** The getter returns an empty string. */ get() = ""
+ /** The setter does nothing. */ set(value) { }
}
diff --git a/test/data/format/accessor.md b/test/data/format/accessor.md
new file mode 100644
index 00000000..8279f452
--- /dev/null
+++ b/test/data/format/accessor.md
@@ -0,0 +1,18 @@
+[test](test/index) / [C](test/-c/index) / [x](test/-c/x)
+
+
+# x
+
+`var x: String`
+**Getter**
+
+The getter returns an empty string.
+
+
+**Setter**
+
+The setter does nothing.
+
+
+
+
diff --git a/test/data/format/accessor.set.md b/test/data/format/accessor.set.md
deleted file mode 100644
index e93766cd..00000000
--- a/test/data/format/accessor.set.md
+++ /dev/null
@@ -1,8 +0,0 @@
-[test](test/index) / [C](test/-c/index) / [x](test/-c/x/index) / [set](test/-c/x/set)
-
-
-# set
-
-`set(value:&nbsp;String)`
-
-
diff --git a/test/data/format/deprecated.class.html b/test/data/format/deprecated.class.html
index 352bd435..922306fc 100644
--- a/test/data/format/deprecated.class.html
+++ b/test/data/format/deprecated.class.html
@@ -16,7 +16,7 @@
<strong>Deprecated:</strong> This function sucks<br/>
<br/>
<br/>
-<a href="test/index">test</a>&nbsp;/&nbsp;<a href="test/p/index">p</a><br/>
+<a href="test/index">test</a>&nbsp;/&nbsp;<a href="test/p">p</a><br/>
<br/>
<h1>p</h1>
<code><span class="keyword">val </span><s><span class="identifier">p</span></s><span class="symbol">: </span><span class="identifier">Int</span></code><br/>
@@ -34,16 +34,5 @@
</tr>
</tbody>
</table>
-<h3>Accessors</h3>
-<table>
-<tbody>
-<tr>
-<td>
-<a href="test/p/get">get</a></td>
-<td>
-<code><span class="identifier">get</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Int</span></code></td>
-</tr>
-</tbody>
-</table>
</BODY>
</HTML>
diff --git a/test/data/format/deprecated.package.html b/test/data/format/deprecated.package.html
index 8e3c2aa9..1700eb15 100644
--- a/test/data/format/deprecated.package.html
+++ b/test/data/format/deprecated.package.html
@@ -25,7 +25,7 @@
<tbody>
<tr>
<td>
-<a href="test/p/index">p</a></td>
+<a href="test/p">p</a></td>
<td>
<code><span class="keyword">val </span><s><span class="identifier">p</span></s><span class="symbol">: </span><span class="identifier">Int</span></code></td>
</tr>
diff --git a/test/data/format/extensions.class.md b/test/data/format/extensions.class.md
index 11ee9ba7..33721e67 100644
--- a/test/data/format/extensions.class.md
+++ b/test/data/format/extensions.class.md
@@ -9,7 +9,7 @@
Function with receiver
|
-| [foobar](test/foo/-string/foobar/index) | `val String.foobar: Int`
+| [foobar](test/foo/-string/foobar) | `val String.foobar: Int`
Property with receiver.
|
diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt
index 7e379cf9..4b207b75 100644
--- a/test/src/format/MarkdownFormatTest.kt
+++ b/test/src/format/MarkdownFormatTest.kt
@@ -83,13 +83,9 @@ public class MarkdownFormatTest {
}
Test fun accessor() {
- verifyOutput("test/data/format/accessor.kt", ".get.md") { model, output ->
- val propertyNode = model.members.single().members.first { it.name == "C" }.members.first { it.name == "x" }
- markdownService.appendNodes(tempLocation, output, listOf(propertyNode.members[0]))
- }
- verifyOutput("test/data/format/accessor.kt", ".set.md") { model, output ->
- val propertyNode = model.members.single().members.first { it.name == "C" }.members.first { it.name == "x" }
- markdownService.appendNodes(tempLocation, output, listOf(propertyNode.members[1]))
+ verifyOutput("test/data/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)
}
}
diff --git a/test/src/model/PropertyTest.kt b/test/src/model/PropertyTest.kt
index 1a9ef995..93a0f681 100644
--- a/test/src/model/PropertyTest.kt
+++ b/test/src/model/PropertyTest.kt
@@ -39,14 +39,7 @@ public class PropertyTest {
assertEquals(Content.Empty, content)
assertEquals("String", detail(DocumentationNode.Kind.Type).name)
assertTrue(links.none())
- with(members.single()) {
- assertEquals("get", name)
- assertEquals(DocumentationNode.Kind.PropertyAccessor, kind)
- assertEquals(Content.Empty, content)
- assertEquals("String", detail(DocumentationNode.Kind.Type).name)
- assertTrue(links.none())
- assertTrue(members.none())
- }
+ assertTrue(members.none())
}
}
}
@@ -64,39 +57,7 @@ public class PropertyTest {
assertTrue("internal" in modifiers)
assertTrue("var" in modifiers)
assertTrue(links.none())
-
- assertEquals(2, members.count())
- with(members.elementAt(0)) {
- assertEquals("get", name)
- assertEquals(DocumentationNode.Kind.PropertyAccessor, kind)
- assertEquals(Content.Empty, content)
- val get_modifiers = details(DocumentationNode.Kind.Modifier).map { it.name }
- assertTrue("final" in get_modifiers)
- assertTrue("internal" in get_modifiers)
- assertEquals("String", detail(DocumentationNode.Kind.Type).name)
- assertTrue(links.none())
- assertTrue(members.none())
- }
- with(members.elementAt(1)) {
- assertEquals("set", name)
- assertEquals(DocumentationNode.Kind.PropertyAccessor, kind)
- assertEquals(Content.Empty, content)
- assertEquals(4, details.count())
- assertEquals("Unit", detail(DocumentationNode.Kind.Type).name)
- val set_modifiers = details(DocumentationNode.Kind.Modifier).map { it.name }
- assertTrue("final" in set_modifiers)
- assertTrue("internal" in set_modifiers)
- with(detail(DocumentationNode.Kind.Parameter)) {
- assertEquals("value", name)
- assertEquals(DocumentationNode.Kind.Parameter, kind)
- assertEquals(Content.Empty, content)
- assertEquals("String", detail(DocumentationNode.Kind.Type).name)
- assertTrue(links.none())
- assertTrue(members.none())
- }
- assertTrue(links.none())
- assertTrue(members.none())
- }
+ assertTrue(members.none())
}
}
}