mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
LC: regression test for findAttributeValue for defalut value in Java
^KT-66692 GitOrigin-RevId: 8721f49f4e6b1dff39001b338e0af6caa95a1ced
This commit is contained in:
committed by
intellij-monorepo-bot
parent
65bac0c820
commit
3566ea8042
+46
-1
@@ -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 {
|
||||
|
||||
+6
-2
@@ -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() {
|
||||
|
||||
+6
-2
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user