Commit 4357cb87 authored by Jinseong Jeon's avatar Jinseong Jeon
Browse files

LC: regression test for findAttributeValue for defalut value in Java

^KT-66692
parent 0fd44a8c
Showing with 58 additions and 5 deletions
+58 -5
......@@ -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 {
......
......@@ -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() {
......
......@@ -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() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment