aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2022-03-30 14:55:51 +0300
committerGitHub <noreply@github.com>2022-03-30 14:55:51 +0300
commitcab4eb11ca5203af3b229aee11111c603cd563fe (patch)
tree1db3cc81a1b6e14787e5c0e7c695a8a169f8d0ae /plugins/base/src/test/kotlin
parent42aeb063ce0d717926bcfb85ab09d1a5f23e0451 (diff)
downloaddokka-cab4eb11ca5203af3b229aee11111c603cd563fe.tar.gz
dokka-cab4eb11ca5203af3b229aee11111c603cd563fe.tar.bz2
dokka-cab4eb11ca5203af3b229aee11111c603cd563fe.zip
Fix type parameter annotation regression (#2388) (#2410)
Diffstat (limited to 'plugins/base/src/test/kotlin')
-rw-r--r--plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt61
-rw-r--r--plugins/base/src/test/kotlin/model/annotations/KotlinAnnotationsForParametersTest.kt56
2 files changed, 112 insertions, 5 deletions
diff --git a/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt b/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt
index 3e5c8176..d6564343 100644
--- a/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt
+++ b/plugins/base/src/test/kotlin/model/annotations/JavaAnnotationsForParametersTest.kt
@@ -1,11 +1,13 @@
package model.annotations
+import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.annotations
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
+import org.jetbrains.dokka.utilities.cast
import org.junit.jupiter.api.Test
import utils.AbstractModelTest
-import kotlin.test.Ignore
import kotlin.test.assertEquals
+import kotlin.test.assertTrue
class JavaAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
@@ -114,4 +116,61 @@ class JavaAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/jav
}
}
}
+
+ @Test
+ fun `type parameter annotations should be visible even if type declaration has none`() {
+ inlineModelTest(
+ """
+ |@Retention(RetentionPolicy.RUNTIME)
+ |@Target(ElementType.PARAMETER)
+ |public @interface Hello {
+ | public String bar() default "";
+ |}
+ |public class Test {
+ | public <T> void foo(java.util.List<@Hello T> param) {}
+ |}
+ """.trimIndent()
+ ) {
+ with((this / "java" / "Test").cast<DClass>()) {
+ with((this / "foo").cast<DFunction>()) {
+ val paramAnnotations = parameters.first()
+ .type.cast<GenericTypeConstructor>()
+ .projections.first().cast<TypeParameter>()
+ .annotations()
+ .values
+ .flatten()
+
+ assertEquals(1, paramAnnotations.size)
+ assertEquals(DRI("java", "Hello"), paramAnnotations[0].dri)
+ }
+ }
+ }
+ }
+
+ @Test
+ fun `type parameter annotations should not be propagated from resolved type`() {
+ inlineModelTest(
+ """
+ |@Retention(RetentionPolicy.RUNTIME)
+ |@Target(ElementType.PARAMETER)
+ |public @interface Hello {
+ | public String bar() default "";
+ |}
+ |public class Test {
+ | public <@Hello T> void foo(java.util.List<T> param) {}
+ |}
+ """.trimIndent()
+ ) {
+ with((this / "java" / "Test").cast<DClass>()) {
+ with((this / "foo").cast<DFunction>()) {
+ val paramAnnotations = parameters.first()
+ .type.cast<GenericTypeConstructor>()
+ .projections.first().cast<TypeParameter>()
+ .annotations()
+
+ assertTrue(paramAnnotations.isEmpty())
+ }
+ }
+ }
+ }
} \ 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 e88d7353..c459cc34 100644
--- a/plugins/base/src/test/kotlin/model/annotations/KotlinAnnotationsForParametersTest.kt
+++ b/plugins/base/src/test/kotlin/model/annotations/KotlinAnnotationsForParametersTest.kt
@@ -1,13 +1,13 @@
package model.annotations
+import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.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.jetbrains.dokka.model.*
+import org.jetbrains.dokka.utilities.cast
import org.junit.jupiter.api.Test
import utils.AbstractModelTest
import kotlin.test.assertEquals
+import kotlin.test.assertTrue
class KotlinAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/annotations/Test.kt", "annotations") {
@Test
@@ -50,4 +50,52 @@ class KotlinAnnotationsForParametersTest : AbstractModelTest("/src/main/kotlin/a
}
}
}
+
+ @Test
+ fun `type parameter annotations should be visible even if type declaration has none`() {
+ inlineModelTest(
+ """
+ |@Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPE)
+ |annotation class Hello
+ |
+ |fun <T> foo(param: List<@Hello T>) {}
+ """.trimIndent()
+ ) {
+ with((this / "annotations" / "foo").cast<DFunction>()) {
+ val paramAnnotations = parameters.first()
+ .type.cast<GenericTypeConstructor>()
+ .projections
+ .first().cast<Invariance<TypeParameter>>()
+ .inner.cast<TypeParameter>()
+ .annotations()
+ .values
+ .flatten()
+
+ assertEquals(1, paramAnnotations.size)
+ assertEquals(DRI("annotations", "Hello"), paramAnnotations[0].dri)
+ }
+ }
+ }
+
+ @Test
+ fun `type parameter annotations should not be propagated from resolved type`() {
+ inlineModelTest(
+ """
+ |@Target(AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.TYPE)
+ |annotation class Hello
+ |
+ |fun <@Hello T> foo(param: List<T>) {}
+ """.trimIndent()
+ ) {
+ with((this / "annotations" / "foo").cast<DFunction>()) {
+ val paramAnnotations = parameters.first()
+ .type.cast<GenericTypeConstructor>()
+ .projections.first().cast<Invariance<TypeParameter>>()
+ .inner.cast<TypeParameter>()
+ .annotations()
+
+ assertTrue(paramAnnotations.isEmpty())
+ }
+ }
+ }
} \ No newline at end of file