diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-02-05 14:55:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 14:55:45 +0100 |
commit | 70000c87a37caa2a6b518a555f53c98514434403 (patch) | |
tree | 3a0e7a2b797b6edfffc0396bb5f9d35708120e9d /plugins/base/src/test | |
parent | b44e41ec8e3e26c73affaaa98bbd170fde352d96 (diff) | |
download | dokka-70000c87a37caa2a6b518a555f53c98514434403.tar.gz dokka-70000c87a37caa2a6b518a555f53c98514434403.tar.bz2 dokka-70000c87a37caa2a6b518a555f53c98514434403.zip |
Annotations for parameters (#1710)
* Annotations for parameters
* Annotations for parameters
Diffstat (limited to 'plugins/base/src/test')
3 files changed, 107 insertions, 5 deletions
diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt index 164e5f4a..0b9e2390 100644 --- a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt +++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt @@ -5,11 +5,15 @@ import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Annotations import org.jetbrains.dokka.model.StringValue +import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.ContentText +import org.jetbrains.dokka.pages.MemberPageNode import org.jetbrains.dokka.pages.PackagePageNode import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult import org.junit.jupiter.api.Test import utils.ParamAttributes +import utils.assertNotNull import utils.bareSignature import utils.propertySignature import kotlin.test.assertEquals @@ -227,7 +231,7 @@ class ContentForAnnotationsTest : BaseAbstractTest() { } @Test - fun `JvmName for property with setter and getter`(){ + fun `JvmName for property with setter and getter`() { testInline( """ |/src/main/kotlin/test/source.kt @@ -237,7 +241,8 @@ class ContentForAnnotationsTest : BaseAbstractTest() { |var property: String | get() = "" | set(value) {} - """.trimIndent(), testConfiguration) { + """.trimIndent(), testConfiguration + ) { documentablesCreationStage = { modules -> fun expectedAnnotation(name: String) = Annotations.Annotation( dri = DRI("kotlin.jvm", "JvmName"), @@ -264,4 +269,49 @@ class ContentForAnnotationsTest : BaseAbstractTest() { } } } + + @Test + fun `annotated bounds in Kotlin`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |@MustBeDocumented + |@Target(AnnotationTarget.TYPE_PARAMETER) + |annotation class Hello(val bar: String) + |fun <T: @Hello("abc") String> foo(arg: String): List<T> = TODO() + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { root -> + val fooPage = root.dfs { it.name == "foo" } as MemberPageNode + fooPage.content.dfs { it is ContentText && it.text == "Hello" }.assertNotNull() + } + } + } + + @Test + fun `annotated bounds in Java`() { + testInline( + """ + |/src/main/java/demo/AnnotationTest.java + |package demo; + |import java.lang.annotation.*; + |import java.util.List; + |@Documented + |@Target({ElementType.TYPE_USE, ElementType.TYPE}) + |@interface Hello { + | public String bar() default ""; + |} + |public class AnnotationTest { + | public <T extends @Hello(bar = "baz") String> List<T> foo() { + | return null; + | } + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { root -> + val fooPage = root.dfs { it.name == "foo" } as MemberPageNode + fooPage.content.dfs { it is ContentText && it.text == "Hello" }.assertNotNull() + } + } + } } diff --git a/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt b/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt index 5679010d..9e00fafd 100644 --- a/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt +++ b/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt @@ -1,11 +1,10 @@ package model.annotations import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.Annotations -import org.jetbrains.dokka.model.DClass -import org.jetbrains.dokka.model.DFunction +import org.jetbrains.dokka.model.* import org.junit.jupiter.api.Test import utils.AbstractModelTest +import kotlin.test.Ignore import kotlin.test.assertEquals class JavaAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { @@ -85,4 +84,34 @@ class JavaAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/jav } } } + + @Test + fun `function with generic parameter that has annotated bounds`() { + inlineModelTest( + """ + |@Retention(RetentionPolicy.RUNTIME) + |@Target({ElementType.TYPE_USE}) + |@interface Hello { + | public String bar() default ""; + |} + |class Test { + | public <T extends @Hello(bar = "baz") String> List<T> foo() { + | return null; + | } + |} + """.trimIndent() + ) { + with((this / "java" / "Test").cast<DClass>()) { + with((this / "foo").cast<DFunction>()) { + val annotations = ((generics.first().bounds.first() as Nullable).inner as GenericTypeConstructor) + .extra[Annotations]?.directAnnotations?.flatMap { it.value } + val driOfHello = DRI("java", "Hello") + val annotationsValues = annotations?.flatMap { it.params.values }?.map { it.toString() }?.toList() + + assertEquals(listOf(driOfHello), annotations?.map { it.dri }) + assertEquals(listOf("baz"), annotationsValues) + } + } + } + } }
\ No newline at end of file diff --git a/plugins/base/src/test/kotlin/model/annotations/KotlinAnnotationsForParametersTest.kt b/plugins/base/src/test/kotlin/model/annotations/KotlinAnnotationsForParametersTest.kt index 4cc34c09..e88d7353 100644 --- a/plugins/base/src/test/kotlin/model/annotations/KotlinAnnotationsForParametersTest.kt +++ b/plugins/base/src/test/kotlin/model/annotations/KotlinAnnotationsForParametersTest.kt @@ -3,6 +3,8 @@ package model.annotations import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Annotations import org.jetbrains.dokka.model.DFunction +import org.jetbrains.dokka.model.DProperty +import org.jetbrains.dokka.model.GenericTypeConstructor import org.junit.jupiter.api.Test import utils.AbstractModelTest import kotlin.test.assertEquals @@ -27,4 +29,25 @@ class KotlinAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/a } } } + + @Test + fun `generic receiver with annotated bounds`() { + inlineModelTest( + """ + |@Target(AnnotationTarget.TYPE_PARAMETER) + |annotation class Hello(val bar: String) + |fun <T: @Hello("abc") String> foo(arg: String): List<T> = TODO() + """.trimIndent() + ) { + with((this / "annotations" / "foo").cast<DFunction>()) { + val annotations = (generics.first().bounds.first() as GenericTypeConstructor) + .extra[Annotations]?.directAnnotations?.flatMap { it.value } + val driOfHello = DRI("annotations", "Hello") + val annotationsValues = annotations?.flatMap { it.params.values }?.map { it.toString() }?.toList() + + assertEquals(listOf(driOfHello), annotations?.map { it.dri }) + assertEquals(listOf("abc"), annotationsValues) + } + } + } }
\ No newline at end of file |