From cad221f454adceb12d74fc563788b3d8247e44f6 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 2 Mar 2015 12:25:00 +0100 Subject: represent nullability in doc model instead of appending ? to type name --- src/Kotlin/DocumentationBuilder.kt | 5 ++++- src/Kotlin/KotlinLanguageService.kt | 4 ++++ src/Model/DocumentationNode.kt | 1 + test/data/format/htmlEscaping.html | 2 +- test/data/format/nullability.kt | 5 +++++ test/data/format/nullability.md | 20 ++++++++++++++++++++ test/src/format/MarkdownFormatTest.kt | 6 ++++++ 7 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 test/data/format/nullability.kt create mode 100644 test/data/format/nullability.md diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index d8933087..3b7f25d6 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -224,13 +224,16 @@ class DocumentationBuilder(val session: ResolveSession, return val classifierDescriptor = jetType.getConstructor().getDeclarationDescriptor() val name = when (classifierDescriptor) { - is Named -> classifierDescriptor.getName().asString() + if (jetType.isMarkedNullable()) "?" else "" + is Named -> classifierDescriptor.getName().asString() else -> "" } val node = DocumentationNode(name, Content.Empty, kind) if (prefix != "") { node.appendTextNode(prefix, Kind.Modifier) } + if (jetType.isMarkedNullable()) { + node.appendTextNode("?", Kind.NullabilityModifier) + } if (classifierDescriptor != null && !classifierDescriptor.isBoringBuiltinClass()) { link(node, classifierDescriptor) } diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index 4b43fb88..855745e0 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -114,6 +114,10 @@ class KotlinLanguageService : LanguageService { } symbol(">") } + val nullabilityModifier = node.details(DocumentationNode.Kind.NullabilityModifier).singleOrNull() + if (nullabilityModifier != null) { + symbol(nullabilityModifier.name) + } } private fun ContentBlock.renderModifier(node: DocumentationNode) { diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt index 3fc1198c..c9373849 100644 --- a/src/Model/DocumentationNode.kt +++ b/src/Model/DocumentationNode.kt @@ -91,6 +91,7 @@ public open class DocumentationNode(val name: String, Exception Modifier + NullabilityModifier Module diff --git a/test/data/format/htmlEscaping.html b/test/data/format/htmlEscaping.html index 52c69239..a485c08f 100644 --- a/test/data/format/htmlEscaping.html +++ b/test/data/format/htmlEscaping.html @@ -6,7 +6,7 @@ test / x

x

-fun <T> x(): T?
+fun <T> x(): T?

Special characters: < is "less than", > is "greater than", & is "ampersand"



diff --git a/test/data/format/nullability.kt b/test/data/format/nullability.kt new file mode 100644 index 00000000..d1d4545b --- /dev/null +++ b/test/data/format/nullability.kt @@ -0,0 +1,5 @@ +class C { + fun foo(): Comparable? { + return null + } +} diff --git a/test/data/format/nullability.md b/test/data/format/nullability.md new file mode 100644 index 00000000..ee50a0a5 --- /dev/null +++ b/test/data/format/nullability.md @@ -0,0 +1,20 @@ +[test](test/index) / [C](test/-c/index) + + +# C + +`class C<T>` + + + +### Constructors + + +| [<init>](test/-c/-init-) | `C()` | + + +### Functions + + +| [foo](test/-c/foo) | `fun foo(): Comparable<T>?` | + diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index 0452645a..7164fdee 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -142,4 +142,10 @@ public class MarkdownFormatTest { markdownService.appendNodes(tempLocation, output, model.members.single().members) } } + + Test fun nullability() { + verifyOutput("test/data/format/nullability.kt", ".md") { model, output -> + markdownService.appendNodes(tempLocation, output, model.members.single().members) + } + } } -- cgit