diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-05-04 13:53:10 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-05-26 11:32:03 +0200 |
commit | d47d386ad8c0ff4a2c3b9d5b4450a773bdcba2dc (patch) | |
tree | 364724f661349211f053ea80db1a7feb283f48ba /plugins/base/src/test/kotlin/utils | |
parent | b1e3033fca65ac1e8e312e51d2eed4f278ddb076 (diff) | |
download | dokka-d47d386ad8c0ff4a2c3b9d5b4450a773bdcba2dc.tar.gz dokka-d47d386ad8c0ff4a2c3b9d5b4450a773bdcba2dc.tar.bz2 dokka-d47d386ad8c0ff4a2c3b9d5b4450a773bdcba2dc.zip |
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
Diffstat (limited to 'plugins/base/src/test/kotlin/utils')
-rw-r--r-- | plugins/base/src/test/kotlin/utils/TestUtils.kt | 1 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/utils/contentUtils.kt | 173 |
2 files changed, 149 insertions, 25 deletions
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<String, Set<String>>, + visibility: String, + modifier: String, + keywords: Set<String>, name: String, returnType: String? = null, - vararg params: Pair<String, String> + vararg params: Pair<String, ParamAttributes> ) = platformHinted { - bareSignature(name, returnType, *params) + bareSignature(annotations, visibility, modifier, keywords, name, returnType, *params) } fun ContentMatcherBuilder<*>.bareSignature( + annotations: Map<String, Set<String>>, + visibility: String, + modifier: String, + keywords: Set<String>, name: String, returnType: String? = null, - vararg params: Pair<String, String> -) = group { - +"final fun" - link { +name } - +"(" - params.forEachIndexed { id, (n, t) -> - +"$n:" - group { link { +t } } - if (id != params.lastIndex) - +", " + vararg params: Pair<String, ParamAttributes> +) = 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<String, Set<String>>, + visibility: String?, + modifier: String?, + keywords: Set<String>, receiver: String, name: String, returnType: String? = null, - vararg params: Pair<String, String> + vararg params: Pair<String, ParamAttributes> ) = platformHinted { - bareSignatureWithReceiver(receiver, name, returnType, *params) + bareSignatureWithReceiver(annotations, visibility, modifier, keywords, receiver, name, returnType, *params) } fun ContentMatcherBuilder<*>.bareSignatureWithReceiver( + annotations: Map<String, Set<String>>, + visibility: String?, + modifier: String?, + keywords: Set<String>, receiver: String, name: String, returnType: String? = null, - vararg params: Pair<String, String> -) = + vararg params: Pair<String, ParamAttributes> +) = 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<String, Set<String>>, + visibility: String, + modifier: String, + keywords: Set<String>, + 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<String, Set<String>>) { + +"@" + link { +elem.key } + +"(" + elem.value.forEach { + +("$it = ") + skipAllNotMatching() + } + +")" +} + +data class ParamAttributes( + val annotations: Map<String, Set<String>>, + val keywords: Set<String>, + val type: String +)
\ No newline at end of file |