diff --git a/plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/LightClassBehaviorTestBase.kt b/plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/LightClassBehaviorTestBase.kt index 4b2ea0bd8b5bb59c2a9ce7119a45f787b2daa958..adc410d41910ee56e8f03c2e94a1824b2135ea36 100644 --- a/plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/LightClassBehaviorTestBase.kt +++ b/plugins/kotlin/uast/uast-kotlin-base/tests/test/org/jetbrains/uast/test/common/kotlin/LightClassBehaviorTestBase.kt @@ -594,7 +594,7 @@ interface LightClassBehaviorTestBase : UastPluginSelection { ) } - fun checkDefaultValueOfAnnotation(myFixture: JavaCodeInsightTestFixture) { + fun checkDefaultValueOfAnnotation_Kotlin(myFixture: JavaCodeInsightTestFixture) { myFixture.configureByText( "main.kt", """ annotation class IntDef( @@ -629,6 +629,51 @@ interface LightClassBehaviorTestBase : UastPluginSelection { TestCase.assertEquals("false", flagValue?.toString()) } + fun checkDefaultValueOfAnnotation_Java(myFixture: JavaCodeInsightTestFixture) { + myFixture.addClass( + """ + import java.lang.annotation.Annotation; + import java.lang.annotation.ElementType; + import java.lang.annotation.Target; + + @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) + public @interface MyRestrictedApi { + String explanation(); + Class<? extends Annotation>[] allowlistAnnotations() default {}; + boolean allowedInTestonlyTargets() default false; + } + """.trimIndent() + ) + myFixture.configureByText( + "main.kt", """ + @Target(AnnotationTarget.FUNCTION) annotation class KAllowlist + + class Test { + @MyRestrictedApi( + explanation = "umbrella", + allowlistAnnotations = [KAllowlist::class], + ) + fun foo() {} + } + """.trimIndent() + ) + + val uFile = myFixture.file.toUElement()!! + val foo = uFile.findElementByTextFromPsi<UMethod>("fun foo", strict = false) + .orFail("can't convert to UMethod") + val lc = foo.uAnnotations.single().javaPsi!! + val annos = (lc.findAttributeValue("allowlistAnnotations") as? PsiArrayInitializerMemberValue)?.initializers + TestCase.assertEquals( + "[KAllowlist]", + annos?.joinToString(separator = ", ", prefix = "[", postfix = "]") { annoValue -> + (annoValue as? PsiClassObjectAccessExpression)?.type?.canonicalText ?: annoValue.text + } + ) + + val flagValue = (lc.findAttributeValue("allowedInTestonlyTargets") as? PsiLiteralExpression)?.value + TestCase.assertEquals("false", flagValue?.toString()) + } + fun checkAnnotationParameterReference(myFixture: JavaCodeInsightTestFixture) { PsiReferenceContributor.EP_NAME.point.registerExtension( PsiReferenceContributorEP().apply { diff --git a/plugins/kotlin/uast/uast-kotlin-fir/tests/test/org/jetbrains/fir/uast/test/FirLightClassBehaviorTest.kt b/plugins/kotlin/uast/uast-kotlin-fir/tests/test/org/jetbrains/fir/uast/test/FirLightClassBehaviorTest.kt index dfbc9220cc6b55b1d452d61994feffe91c3d9f33..6924094576a9989ce75291728bd29e6c03ee0ffc 100644 --- a/plugins/kotlin/uast/uast-kotlin-fir/tests/test/org/jetbrains/fir/uast/test/FirLightClassBehaviorTest.kt +++ b/plugins/kotlin/uast/uast-kotlin-fir/tests/test/org/jetbrains/fir/uast/test/FirLightClassBehaviorTest.kt @@ -77,8 +77,12 @@ class FirLightClassBehaviorTest : KotlinLightCodeInsightFixtureTestCase(), Light checkUpperBoundForRecursiveTypeParameter(myFixture) } - fun testDefaultValueOfAnnotation() { - checkDefaultValueOfAnnotation(myFixture) + fun testDefaultValueOfAnnotation_Kotlin() { + checkDefaultValueOfAnnotation_Kotlin(myFixture) + } + + fun testDefaultValueOfAnnotation_Java() { + checkDefaultValueOfAnnotation_Java(myFixture) } fun testAnnotationParameterReference() { diff --git a/plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1LightClassBehaviorTest.kt b/plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1LightClassBehaviorTest.kt index 1d9ad3d99bd997f235a2007c381029411540bf9e..6bbd366d61adaa95c8769818cf91cda715285a92 100644 --- a/plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1LightClassBehaviorTest.kt +++ b/plugins/kotlin/uast/uast-kotlin/tests/test/org/jetbrains/uast/test/kotlin/comparison/FE1LightClassBehaviorTest.kt @@ -81,8 +81,12 @@ class FE1LightClassBehaviorTest : KotlinLightCodeInsightFixtureTestCase(), Light checkUpperBoundForRecursiveTypeParameter(myFixture) } - fun testDefaultValueOfAnnotation() { - checkDefaultValueOfAnnotation(myFixture) + fun testDefaultValueOfAnnotation_Kotlin() { + checkDefaultValueOfAnnotation_Kotlin(myFixture) + } + + fun testDefaultValueOfAnnotation_Java() { + checkDefaultValueOfAnnotation_Java(myFixture) } fun testAnnotationParameterReference() {