From d47d386ad8c0ff4a2c3b9d5b4450a773bdcba2dc Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Mon, 4 May 2020 13:53:10 +0200 Subject: Enhance signature presentation. Support presetnation Java as Kotlin and Kotlin as Java. Refactor annotations creation from PSI/Descriptors. Add proper rendering of annotation signatures in both kotlin syntax and java syntax. Tests for annotations --- plugins/base/src/test/kotlin/utils/TestUtils.kt | 1 + plugins/base/src/test/kotlin/utils/contentUtils.kt | 173 ++++++++++++++++++--- 2 files changed, 149 insertions(+), 25 deletions(-) (limited to 'plugins/base/src/test/kotlin/utils') diff --git a/plugins/base/src/test/kotlin/utils/TestUtils.kt b/plugins/base/src/test/kotlin/utils/TestUtils.kt index 6bc624d6..1591f4f7 100644 --- a/plugins/base/src/test/kotlin/utils/TestUtils.kt +++ b/plugins/base/src/test/kotlin/utils/TestUtils.kt @@ -73,4 +73,5 @@ val Bound.name: String? is TypeConstructor -> dri.classNames is JavaObject -> "Object" is Void -> "void" + is Dynamic -> "dynamic" } \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/utils/contentUtils.kt b/plugins/base/src/test/kotlin/utils/contentUtils.kt index c71409c3..a1141832 100644 --- a/plugins/base/src/test/kotlin/utils/contentUtils.kt +++ b/plugins/base/src/test/kotlin/utils/contentUtils.kt @@ -1,68 +1,174 @@ package utils import matchers.content.* +import org.jetbrains.dokka.model.* import org.jetbrains.dokka.pages.ContentGroup +import kotlin.text.Typography.nbsp //TODO: Try to unify those functions after update to 1.4 -fun ContentMatcherBuilder<*>.signature( +fun ContentMatcherBuilder<*>.functionSignature( + annotations: Map>, + visibility: String, + modifier: String, + keywords: Set, name: String, returnType: String? = null, - vararg params: Pair + vararg params: Pair ) = platformHinted { - bareSignature(name, returnType, *params) + bareSignature(annotations, visibility, modifier, keywords, name, returnType, *params) } fun ContentMatcherBuilder<*>.bareSignature( + annotations: Map>, + visibility: String, + modifier: String, + keywords: Set, name: String, returnType: String? = null, - vararg params: Pair -) = group { - +"final fun" - link { +name } - +"(" - params.forEachIndexed { id, (n, t) -> - +"$n:" - group { link { +t } } - if (id != params.lastIndex) - +", " + vararg params: Pair +) = group { // TODO: remove it when double wrapping for signatures will be resolved + group { + annotations.entries.forEach { + group { + unwrapAnnotation(it) + } + } + +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun") + link { +name } + +"(" + params.forEachIndexed { id, (n, t) -> + + t.annotations.forEach { + unwrapAnnotation(it) + } + t.keywords.forEach { + +it + } + + +"$n:" + group { link { +(t.type) } } + if (id != params.lastIndex) + +", " + } + +")" + if (returnType != null) { + +(": ") + group { + link { + +(returnType) + } + } + } } - +")" - returnType?.let { +": $it" } } -fun ContentMatcherBuilder<*>.signatureWithReceiver( +fun ContentMatcherBuilder<*>.functionSignatureWithReceiver( + annotations: Map>, + visibility: String?, + modifier: String?, + keywords: Set, receiver: String, name: String, returnType: String? = null, - vararg params: Pair + vararg params: Pair ) = platformHinted { - bareSignatureWithReceiver(receiver, name, returnType, *params) + bareSignatureWithReceiver(annotations, visibility, modifier, keywords, receiver, name, returnType, *params) } fun ContentMatcherBuilder<*>.bareSignatureWithReceiver( + annotations: Map>, + visibility: String?, + modifier: String?, + keywords: Set, receiver: String, name: String, returnType: String? = null, - vararg params: Pair -) = + vararg params: Pair +) = group { // TODO: remove it when double wrapping for signatures will be resolved group { - +"final fun" + annotations.entries.forEach { + group { + unwrapAnnotation(it) + } + } + +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun") group { link { +receiver } } +"." link { +name } +"(" - params.forEach { (n, t) -> + params.forEachIndexed { id, (n, t) -> + + t.annotations.forEach { + unwrapAnnotation(it) + } + t.keywords.forEach { + +it + } + +"$n:" - group { link { +t } } + group { link { +(t.type) } } + if (id != params.lastIndex) + +", " } +")" - returnType?.let { +": $it" } + if (returnType != null) { + +(": ") + group { + link { + +(returnType) + } + } + } } +} +fun ContentMatcherBuilder<*>.propertySignature( + annotations: Map>, + visibility: String, + modifier: String, + keywords: Set, + preposition: String, + name: String, + type: String? = null +) { + group { + header { +"Package test" } + } + group { + skipAllNotMatching() + header { +"Properties" } + table { + group { + link { +name } + platformHinted { + group { + group { + annotations.entries.forEach { + group { + unwrapAnnotation(it) + } + } + +("$visibility $modifier ${keywords.joinToString("") { "$it " }} $preposition") + link { +name } + if (type != null) { + +(": ") + group { + link { + +(type) + } + } + } + } + } + } + } + } + } +} fun ContentMatcherBuilder<*>.pWrapped(text: String) = group {// TODO: remove it when double wrapping for descriptions will be resolved @@ -73,4 +179,21 @@ fun ContentMatcherBuilder<*>.unnamedTag(tag: String, content: ContentMatcherBuil group { header(4) { +tag } group { content() } - } \ No newline at end of file + } + +private fun ContentMatcherBuilder<*>.unwrapAnnotation(elem: Map.Entry>) { + +"@" + link { +elem.key } + +"(" + elem.value.forEach { + +("$it = ") + skipAllNotMatching() + } + +")" +} + +data class ParamAttributes( + val annotations: Map>, + val keywords: Set, + val type: String +) \ No newline at end of file -- cgit