aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2021-01-20 10:41:48 +0100
committerGitHub <noreply@github.com>2021-01-20 10:41:48 +0100
commit1f592a7ec2786e0a0b77d224d1414ef3042caae4 (patch)
tree71d2ec07325d505d2c1b78a71720ddc825b2b87c /plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt
parent93520158b4be59f98015d07e8fecaa7e5a49fd99 (diff)
downloaddokka-1f592a7ec2786e0a0b77d224d1414ef3042caae4.tar.gz
dokka-1f592a7ec2786e0a0b77d224d1414ef3042caae4.tar.bz2
dokka-1f592a7ec2786e0a0b77d224d1414ef3042caae4.zip
Annotations for parameters (#1704)
Diffstat (limited to 'plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt')
-rw-r--r--plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt88
1 files changed, 88 insertions, 0 deletions
diff --git a/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt b/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt
new file mode 100644
index 00000000..5679010d
--- /dev/null
+++ b/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt
@@ -0,0 +1,88 @@
+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.junit.jupiter.api.Test
+import utils.AbstractModelTest
+import kotlin.test.assertEquals
+
+class JavaAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
+
+ @Test
+ fun `function with deprecated parameter`() {
+ inlineModelTest(
+ """
+ |class Test {
+ | public void fn(@Deprecated String name) {}
+ |}
+ """.trimIndent()
+ ) {
+ with((this / "java" / "Test").cast<DClass>()) {
+ with((this / "fn").cast<DFunction>()) {
+ val dri =
+ parameters.first().extra[Annotations]?.directAnnotations?.flatMap { it.value }?.map { it.dri }
+ assertEquals(listOf(DRI("java.lang", "Deprecated")), dri)
+ }
+ }
+ }
+ }
+
+ @Test
+ fun `function with parameter that has custom annotation`() {
+ inlineModelTest(
+ """
+ |@Retention(RetentionPolicy.RUNTIME)
+ |@Target(ElementType.PARAMETER)
+ |public @interface Hello {
+ | public String bar() default "";
+ |}
+ |class Test {
+ | public void foo(@Hello(bar = "baz") String arg){ }
+ |}
+ """.trimIndent()
+ ) {
+ with((this / "java" / "Test").cast<DClass>()) {
+ with((this / "foo").cast<DFunction>()) {
+ val annotations =
+ parameters.first().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)
+ }
+ }
+ }
+ }
+
+ @Test
+ fun `function with annotated generic parameter`() {
+ inlineModelTest(
+ """
+ |@Retention(RetentionPolicy.RUNTIME)
+ |@Target(ElementType.TYPE_PARAMETER)
+ |@interface Hello {
+ | public String bar() default "";
+ |}
+ |class Test {
+ | public <@Hello(bar = "baz") T> List<T> foo() {
+ | return null;
+ | }
+ |}
+ """.trimIndent()
+ ) {
+ with((this / "java" / "Test").cast<DClass>()) {
+ with((this / "foo").cast<DFunction>()) {
+ val annotations = generics.first().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