From cab4eb11ca5203af3b229aee11111c603cd563fe Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Wed, 30 Mar 2022 14:55:51 +0300 Subject: Fix type parameter annotation regression (#2388) (#2410) --- .../JavaAnnotationsForParametersTest.kt | 61 +++++++++++++++++++++- .../KotlinAnnotationsForParametersTest.kt | 56 ++++++++++++++++++-- 2 files changed, 112 insertions(+), 5 deletions(-) (limited to 'plugins/base/src/test') 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 void foo(java.util.List<@Hello T> param) {} + |} + """.trimIndent() + ) { + with((this / "java" / "Test").cast()) { + with((this / "foo").cast()) { + val paramAnnotations = parameters.first() + .type.cast() + .projections.first().cast() + .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 param) {} + |} + """.trimIndent() + ) { + with((this / "java" / "Test").cast()) { + with((this / "foo").cast()) { + val paramAnnotations = parameters.first() + .type.cast() + .projections.first().cast() + .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 foo(param: List<@Hello T>) {} + """.trimIndent() + ) { + with((this / "annotations" / "foo").cast()) { + val paramAnnotations = parameters.first() + .type.cast() + .projections + .first().cast>() + .inner.cast() + .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) {} + """.trimIndent() + ) { + with((this / "annotations" / "foo").cast()) { + val paramAnnotations = parameters.first() + .type.cast() + .projections.first().cast>() + .inner.cast() + .annotations() + + assertTrue(paramAnnotations.isEmpty()) + } + } + } } \ No newline at end of file -- cgit