From 76c7e32f74b8982303a86f81b2ffed2b2a7e7c70 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 16 Nov 2016 16:51:08 +0300 Subject: Type alias support --- core/src/test/kotlin/format/MarkdownFormatTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/src/test/kotlin/format') diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 7f0922ba..280e8e22 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -28,7 +28,7 @@ class MarkdownFormatTest { } //TODO: Enable after typealias support - @Ignore("Disabled until we will correctly support typealias") + // @Ignore("Disabled until we will correctly support typealias") @Test fun exceptionClass() { verifyMarkdownNode("exceptionClass", withKotlinRuntime = true) verifyMarkdownPackage("exceptionClass", withKotlinRuntime = true) -- cgit From 89d41a1bc909c7e350b07bc29d39762449d64650 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 16 Nov 2016 17:53:47 +0300 Subject: Fix most of failing tests, by not unwrapping types, if it not abbreviated (Otherwise we will lose in/out variance) --- core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 7 +++---- core/src/test/kotlin/format/MarkdownFormatTest.kt | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'core/src/test/kotlin/format') diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 5f2d08f9..f922a25b 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -152,10 +152,9 @@ class DocumentationBuilder fun DocumentationNode.appendType(kotlinType: KotlinType?, kind: NodeKind = NodeKind.Type, prefix: String = "") { if (kotlinType == null) return - if (kotlinType is WrappedType) - return appendType(kotlinType.unwrap()) - if (kotlinType is AbbreviatedType) - return appendType(kotlinType.abbreviation) + (kotlinType.unwrap() as? AbbreviatedType)?.let { + return appendType(it.abbreviation) + } val classifierDescriptor = kotlinType.constructor.declarationDescriptor val name = when (classifierDescriptor) { diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 280e8e22..c9f86503 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -27,8 +27,6 @@ class MarkdownFormatTest { verifyMarkdownPackage("annotationClass", withKotlinRuntime = true) } - //TODO: Enable after typealias support - // @Ignore("Disabled until we will correctly support typealias") @Test fun exceptionClass() { verifyMarkdownNode("exceptionClass", withKotlinRuntime = true) verifyMarkdownPackage("exceptionClass", withKotlinRuntime = true) -- cgit From 4b86a1410d0427178132c07f6f04033645663bb0 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 17 Nov 2016 22:06:53 +0300 Subject: Fixup, added some type alias rendering tests --- .../main/kotlin/Formats/StructuredFormatService.kt | 2 +- core/src/test/kotlin/format/MarkdownFormatTest.kt | 5 ++ core/testdata/format/typeAliases.kt | 27 ++++++++++ core/testdata/format/typeAliases.md | 63 ++++++++++++++++++++++ core/testdata/format/typeAliases.package.md | 24 +++++++++ 5 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 core/testdata/format/typeAliases.kt create mode 100644 core/testdata/format/typeAliases.md create mode 100644 core/testdata/format/typeAliases.package.md (limited to 'core/src/test/kotlin/format') diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt index b7306486..a7a50f91 100644 --- a/core/src/main/kotlin/Formats/StructuredFormatService.kt +++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt @@ -372,7 +372,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, appendSection("Types", node.members.filter { it.kind in NodeKind.classLike && it.kind != NodeKind.TypeAlias && it.kind != NodeKind.AnnotationClass && it.kind != NodeKind.Exception }) appendSection("Annotations", node.members(NodeKind.AnnotationClass)) appendSection("Exceptions", node.members(NodeKind.Exception)) - appendSection("Type aliases", node.members(NodeKind.TypeAlias)) + appendSection("Type Aliases", node.members(NodeKind.TypeAlias)) appendSection("Extensions for External Classes", node.members(NodeKind.ExternalClass)) appendSection("Enum Values", node.members(NodeKind.EnumItem), sortMembers = false) appendSection("Constructors", node.members(NodeKind.Constructor)) diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index c9f86503..6e4c44c8 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -227,6 +227,11 @@ class MarkdownFormatTest { verifyMarkdownNodeByName("qualifiedNameLink", "foo", withKotlinRuntime = true) } + @Test fun typeAliases() { + verifyMarkdownNode("typeAliases") + verifyMarkdownPackage("typeAliases") + } + private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) { verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output -> markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) diff --git a/core/testdata/format/typeAliases.kt b/core/testdata/format/typeAliases.kt new file mode 100644 index 00000000..9657963e --- /dev/null +++ b/core/testdata/format/typeAliases.kt @@ -0,0 +1,27 @@ + +class A +class B +class C + +typealias D = A +typealias E = D + +typealias F = (A) -> B + +typealias G = C +typealias H = C + +typealias I = H +typealias J = H + +typealias K = H + +typealias L = (K, B) -> J + +/** + * Documented + */ +typealias M = A + +@Deprecated("!!!") +typealias N = A \ No newline at end of file diff --git a/core/testdata/format/typeAliases.md b/core/testdata/format/typeAliases.md new file mode 100644 index 00000000..55e9317e --- /dev/null +++ b/core/testdata/format/typeAliases.md @@ -0,0 +1,63 @@ +[test](test/index) / [A](test/-a/index) + +# A + +`class A`[test](test/index) / [B](test/-b/index) + +# B + +`class B`[test](test/index) / [C](test/-c/index) + +# C + +`class C`[test](test/index) / [D](test/-d) + +# D + +`typealias D = `[`A`](test/-a/index)[test](test/index) / [E](test/-e) + +# E + +`typealias E = `[`D`](test/-d)[test](test/index) / [F](test/-f) + +# F + +`typealias F = (`[`A`](test/-a/index)`) -> `[`B`](test/-b/index)[test](test/index) / [G](test/-g) + +# G + +`typealias G = `[`C`](test/-c/index)`<`[`A`](test/-a/index)`>`[test](test/index) / [H](test/-h) + +# H + +`typealias H = `[`C`](test/-c/index)``[test](test/index) / [I](test/-i) + +# I + +`typealias I = `[`H`](test/-h)``[test](test/index) / [J](test/-j) + +# J + +`typealias J = `[`H`](test/-h)`<`[`A`](test/-a/index)`>`[test](test/index) / [K](test/-k) + +# K + +`typealias K = `[`H`](test/-h)`<`[`J`](test/-j)`>`[test](test/index) / [L](test/-l) + +# L + +`typealias L = (`[`K`](test/-k)`, `[`B`](test/-b/index)`) -> `[`J`](test/-j)[test](test/index) / [M](test/-m) + +# M + +`typealias M = `[`A`](test/-a/index) + +Documented + +[test](test/index) / [N](test/-n) + +# N + +`typealias ~~N~~ = `[`A`](test/-a/index) +**Deprecated:** !!! + diff --git a/core/testdata/format/typeAliases.package.md b/core/testdata/format/typeAliases.package.md new file mode 100644 index 00000000..0eff1ed5 --- /dev/null +++ b/core/testdata/format/typeAliases.package.md @@ -0,0 +1,24 @@ +[test](test/index) + +## Package <root> + +### Types + +| [A](test/-a/index) | `class A` | +| [B](test/-b/index) | `class B` | +| [C](test/-c/index) | `class C` | + +### Type Aliases + +| [D](test/-d) | `typealias D = `[`A`](test/-a/index) | +| [E](test/-e) | `typealias E = `[`D`](test/-d) | +| [F](test/-f) | `typealias F = (`[`A`](test/-a/index)`) -> `[`B`](test/-b/index) | +| [G](test/-g) | `typealias G = `[`C`](test/-c/index)`<`[`A`](test/-a/index)`>` | +| [H](test/-h) | `typealias H = `[`C`](test/-c/index)`` | +| [I](test/-i) | `typealias I = `[`H`](test/-h)`` | +| [J](test/-j) | `typealias J = `[`H`](test/-h)`<`[`A`](test/-a/index)`>` | +| [K](test/-k) | `typealias K = `[`H`](test/-h)`<`[`J`](test/-j)`>` | +| [L](test/-l) | `typealias L = (`[`K`](test/-k)`, `[`B`](test/-b/index)`) -> `[`J`](test/-j) | +| [M](test/-m) | `typealias M = `[`A`](test/-a/index)
Documented | +| [N](test/-n) | `typealias ~~N~~ = `[`A`](test/-a/index) | + -- cgit