diff options
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 4 | ||||
-rw-r--r-- | src/Formats/MarkdownFormatService.kt | 4 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 14 | ||||
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 6 | ||||
-rw-r--r-- | src/Kotlin/KotlinLanguageService.kt | 16 | ||||
-rw-r--r-- | src/Model/Content.kt | 1 | ||||
-rw-r--r-- | src/Model/DocumentationNode.kt | 2 | ||||
-rw-r--r-- | src/Model/DocumentationReference.kt | 1 | ||||
-rw-r--r-- | test/data/format/deprecated.class.html | 46 | ||||
-rw-r--r-- | test/data/format/deprecated.kt | 5 | ||||
-rw-r--r-- | test/data/format/deprecated.package.html | 44 | ||||
-rw-r--r-- | test/src/format/HtmlFormatTest.kt | 9 | ||||
-rw-r--r-- | test/src/model/ClassTest.kt | 3 |
13 files changed, 149 insertions, 6 deletions
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index b23e4a45..f76693dc 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -93,6 +93,10 @@ public open class HtmlFormatService(locationService: LocationService, return "<emph>${text}</emph>" } + override fun formatStrikethrough(text: String): String { + return "<s>${text}</s>" + } + override fun formatCode(code: String): String { return "<code>${code}</code>" } diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index 38fadf7a..a2e3ce55 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -46,6 +46,10 @@ public open class MarkdownFormatService(locationService: LocationService, return "*$text*" } + override fun formatStrikethrough(text: String): String { + return "~~$text~~" + } + override public fun formatLink(text: String, location: Location): String { return "[$text](${location.path})" } diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index cb510f80..51222ffb 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka import java.util.LinkedHashMap +import com.intellij.openapi.util.text.StringUtil public data class FormatLink(val text: String, val location: Location) @@ -28,6 +29,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi public abstract fun formatLink(text: String, href: String): String public open fun formatLink(link: FormatLink): String = formatLink(formatText(link.text), link.location) public abstract fun formatStrong(text: String): String + public abstract fun formatStrikethrough(text: String): String public abstract fun formatEmphasis(text: String): String public abstract fun formatCode(code: String): String public abstract fun formatList(text: String): String @@ -46,6 +48,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi is ContentKeyword -> append(formatKeyword(content.text)) is ContentIdentifier -> append(formatIdentifier(content.text)) is ContentStrong -> append(formatStrong(formatText(location, content.children))) + is ContentStrikethrough -> append(formatStrikethrough(formatText(location, content.children))) is ContentCode -> append(formatCode(formatText(location, content.children))) is ContentEmphasis -> append(formatEmphasis(formatText(location, content.children))) is ContentList -> append(formatList(formatText(location, content.children))) @@ -116,6 +119,17 @@ public abstract class StructuredFormatService(val locationService: LocationServi for ((summary, items) in breakdownBySummary) { items.forEach { appendBlockCode(to, formatText(location, languageService.render(it))) + val deprecation = it.deprecation + if (deprecation != null) { + val deprecationParameter = deprecation.details(DocumentationNode.Kind.Parameter).firstOrNull() + val deprecationValue = deprecationParameter?.details(DocumentationNode.Kind.Value)?.firstOrNull() + if (deprecationValue != null) { + to.append(formatStrong("Deprecated: ")) + appendLine(to, formatText(StringUtil.unquoteString(deprecationValue.name))) + } else { + appendLine(to, formatStrong("Deprecated")) + } + } } appendLine(to, summary) appendLine(to) diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 844d8290..121c44bf 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -127,7 +127,11 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati fun DocumentationNode.appendAnnotations(annotated: Annotated) { annotated.getAnnotations().forEach { - it.build()?.let { append(it, DocumentationReference.Kind.Annotation) } + val annotationNode = it.build() + if (annotationNode != null) { + append(annotationNode, + if (annotationNode.name == "deprecated") DocumentationReference.Kind.Deprecation else DocumentationReference.Kind.Annotation) + } } } diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index 92d5bf1d..2ed308f8 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -196,7 +196,7 @@ class KotlinLanguageService : LanguageService { else -> throw IllegalArgumentException("Node $node is not a class-like object") } - identifier(node.name) + identifierOrDeprecated(node) renderTypeParametersForNode(node) renderSupertypesForNode(node) } @@ -218,7 +218,7 @@ class KotlinLanguageService : LanguageService { } if (node.kind != org.jetbrains.dokka.DocumentationNode.Kind.Constructor) - identifier(node.name) + identifierOrDeprecated(node) symbol("(") renderList(node.details(DocumentationNode.Kind.Parameter)) { @@ -246,8 +246,18 @@ class KotlinLanguageService : LanguageService { symbol(".") } - identifier(node.name) + identifierOrDeprecated(node) symbol(": ") renderType(node.detail(DocumentationNode.Kind.Type)) } + + fun ContentNode.identifierOrDeprecated(node: DocumentationNode) { + if (node.deprecation != null) { + val strike = ContentStrikethrough() + strike.identifier(node.name) + append(strike) + } else { + identifier(node.name) + } + } }
\ No newline at end of file diff --git a/src/Model/Content.kt b/src/Model/Content.kt index e1c1ef78..8491fd88 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -27,6 +27,7 @@ public class ContentSymbol(val text: String) : ContentNode() public class ContentParagraph() : ContentBlock() public class ContentEmphasis() : ContentBlock() public class ContentStrong() : ContentBlock() +public class ContentStrikethrough() : ContentBlock() public class ContentCode() : ContentBlock() public class ContentBlockCode() : ContentBlock() public class ContentNodeLink(val node : DocumentationNode) : ContentBlock() diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt index 5f9aabab..635d1db9 100644 --- a/src/Model/DocumentationNode.kt +++ b/src/Model/DocumentationNode.kt @@ -32,6 +32,8 @@ public open class DocumentationNode(val name: String, get() = references(DocumentationReference.Kind.Link).map { it.to } public val annotations: List<DocumentationNode> get() = references(DocumentationReference.Kind.Annotation).map { it.to } + public val deprecation: DocumentationNode? + get() = references(DocumentationReference.Kind.Deprecation).singleOrNull()?.to // TODO: Should we allow node mutation? Model merge will copy by ref, so references are transparent, which could nice public fun addReferenceTo(to: DocumentationNode, kind: DocumentationReference.Kind) { diff --git a/src/Model/DocumentationReference.kt b/src/Model/DocumentationReference.kt index 9fb366cb..bd40f0f5 100644 --- a/src/Model/DocumentationReference.kt +++ b/src/Model/DocumentationReference.kt @@ -10,6 +10,7 @@ public data class DocumentationReference(val from: DocumentationNode, val to: Do Inheritor Override Annotation + Deprecation } } diff --git a/test/data/format/deprecated.class.html b/test/data/format/deprecated.class.html new file mode 100644 index 00000000..87599082 --- /dev/null +++ b/test/data/format/deprecated.class.html @@ -0,0 +1,46 @@ +<HTML> +<HEAD> +</HEAD> +<BODY> +<a href="out.html">test</a> / <a href="out.html"></a> / <a href="out.html">C</a><br/> +<br/> +<h1>C</h1> +<pre><code><span class="keyword">class </span><s><span class="identifier">C</span></s></code></pre><strong>Deprecated: </strong>This class sucks<br/> +<br/> +<br/> +<a href="out.html">test</a> / <a href="out.html"></a> / <a href="out.html">f</a><br/> +<br/> +<h1>f</h1> +<pre><code><span class="keyword">fun </span><s><span class="identifier">f</span></s><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code></pre><strong>Deprecated: </strong>This function sucks<br/> +<br/> +<br/> +<a href="out.html">test</a> / <a href="out.html"></a> / <a href="out.html">p</a><br/> +<br/> +<h1>p</h1> +<pre><code><span class="keyword">val </span><s><span class="identifier">p</span></s><span class="symbol">: </span><span class="identifier">Int</span></code></pre><strong>Deprecated: </strong>This property sucks<br/> +<br/> +<br/> +<h3>Constructors</h3> +<table> +<tbody> +<tr> +<td> +<a href="out.html"><init></a></td> +<td> +<code><span class="keyword">public</span> <span class="identifier">C</span><span class="symbol">(</span><span class="symbol">)</span></code></td> +</tr> +</tbody> +</table> +<h3>Accessors</h3> +<table> +<tbody> +<tr> +<td> +<a href="out.html">get</a></td> +<td> +<code></code></td> +</tr> +</tbody> +</table> +</BODY> +</HTML> diff --git a/test/data/format/deprecated.kt b/test/data/format/deprecated.kt new file mode 100644 index 00000000..9ee2c1d6 --- /dev/null +++ b/test/data/format/deprecated.kt @@ -0,0 +1,5 @@ +deprecated("This class sucks") class C() { } + +deprecated("This function sucks") fun f() { } + +deprecated("This property sucks") val p: Int get() = 0 diff --git a/test/data/format/deprecated.package.html b/test/data/format/deprecated.package.html new file mode 100644 index 00000000..cf563a8b --- /dev/null +++ b/test/data/format/deprecated.package.html @@ -0,0 +1,44 @@ +<HTML> +<HEAD> +</HEAD> +<BODY> +<a href="out.html">test</a> / <a href="out.html"></a><br/> +<br/> +<h1></h1> +<pre><code><span class="keyword">package</span> <span class="identifier"></span></code></pre><br/> +<br/> +<h3>Types</h3> +<table> +<tbody> +<tr> +<td> +<a href="out.html">C</a></td> +<td> +<code><span class="keyword">class </span><s><span class="identifier">C</span></s></code></td> +</tr> +</tbody> +</table> +<h3>Properties</h3> +<table> +<tbody> +<tr> +<td> +<a href="out.html">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> +</tbody> +</table> +<h3>Functions</h3> +<table> +<tbody> +<tr> +<td> +<a href="out.html">f</a></td> +<td> +<code><span class="keyword">fun </span><s><span class="identifier">f</span></s><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code></td> +</tr> +</tbody> +</table> +</BODY> +</HTML> diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index 881a7828..47fe9c4e 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -24,4 +24,13 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members) } } + + Test fun deprecated() { + verifyOutput("test/data/format/deprecated.kt", ".package.html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members) + } + verifyOutput("test/data/format/deprecated.kt", ".class.html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members) + } + } } diff --git a/test/src/model/ClassTest.kt b/test/src/model/ClassTest.kt index ae82a4f1..f21c5c57 100644 --- a/test/src/model/ClassTest.kt +++ b/test/src/model/ClassTest.kt @@ -183,8 +183,7 @@ public class ClassTest { Test fun annotatedClassWithAnnotationParameters() { verifyModel("test/data/classes/annotatedClassWithAnnotationParameters.kt") { model -> with(model.members.single().members.single()) { - assertEquals(1, annotations.count()) - with(annotations[0]) { + with(deprecation!!) { assertEquals("deprecated", name) assertEquals(Content.Empty, content) assertEquals(DocumentationNode.Kind.Annotation, kind) |