lightAnnotations: proper parents for KtLightAnnotationsValues

This commit is contained in:
Nicolay Mitropolsky
2018-07-11 23:27:04 +03:00
parent 8478c73434
commit cedc6821c3
6 changed files with 135 additions and 63 deletions
@@ -11,6 +11,7 @@ import com.intellij.psi.impl.LanguageConstantExpressionEvaluator
import com.intellij.psi.impl.light.LightIdentifier
import com.intellij.psi.impl.light.LightTypeElement
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
@@ -22,7 +23,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class KtLightPsiArrayInitializerMemberValue(
override val kotlinOrigin: KtElement,
val lightParent: PsiElement,
val arguments: (KtLightPsiArrayInitializerMemberValue) -> List<PsiAnnotationMemberValue>
private val arguments: (KtLightPsiArrayInitializerMemberValue) -> List<PsiAnnotationMemberValue>
) : KtLightElementBase(lightParent), PsiArrayInitializerMemberValue {
override fun getInitializers(): Array<PsiAnnotationMemberValue> = arguments(this).toTypedArray()
@@ -91,11 +92,16 @@ private fun psiType(kotlinType: KotlinType, context: PsiElement): PsiType? {
class KtLightPsiNameValuePair private constructor(
override val kotlinOrigin: KtElement,
val valueArgument: KtValueArgument,
lightParent: PsiElement
lightParent: PsiElement,
private val argument: (KtLightPsiNameValuePair) -> PsiAnnotationMemberValue?
) : KtLightElementBase(lightParent),
PsiNameValuePair {
constructor(valueArgument: KtValueArgument, lightParent: PsiElement) : this(valueArgument.asElement(), valueArgument, lightParent)
constructor(
valueArgument: KtValueArgument,
lightParent: PsiElement,
argument: (KtLightPsiNameValuePair) -> PsiAnnotationMemberValue?
) : this(valueArgument.asElement(), valueArgument, lightParent, argument)
override fun setValue(newValue: PsiAnnotationMemberValue): PsiAnnotationMemberValue =
throw UnsupportedOperationException("can't modify KtLightPsiNameValuePair")
@@ -104,8 +110,9 @@ class KtLightPsiNameValuePair private constructor(
override fun getName(): String? = valueArgument.getArgumentName()?.asName?.asString()
override fun getValue(): PsiAnnotationMemberValue? =
valueArgument.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(this, it) }
private val _value: PsiAnnotationMemberValue? by lazyPub { argument(this) }
override fun getValue(): PsiAnnotationMemberValue? = _value
override fun getLiteralValue(): String? = (getValue() as? PsiLiteralExpression)?.value?.toString()
@@ -11,6 +11,7 @@ import com.intellij.psi.impl.LanguageConstantExpressionEvaluator
import com.intellij.psi.impl.light.LightIdentifier
import com.intellij.psi.impl.light.LightTypeElement
import org.jetbrains.kotlin.asJava.LightClassGenerationSupport
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
@@ -22,7 +23,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class KtLightPsiArrayInitializerMemberValue(
override val kotlinOrigin: KtElement,
val lightParent: PsiElement,
val arguments: (KtLightPsiArrayInitializerMemberValue) -> List<PsiAnnotationMemberValue>
private val arguments: (KtLightPsiArrayInitializerMemberValue) -> List<PsiAnnotationMemberValue>
) : KtLightElementBase(lightParent), PsiArrayInitializerMemberValue {
override fun getInitializers(): Array<PsiAnnotationMemberValue> = arguments(this).toTypedArray()
@@ -72,16 +73,16 @@ class KtLightPsiClassObjectAccessExpression(override val kotlinOrigin: KtClassLi
}
private fun psiType(kotlinType: KotlinType, context: PsiElement): PsiType? {
val typeFqName = kotlinType.constructor.declarationDescriptor?.fqNameSafe?.asString() ?: return null
return when (typeFqName) {
"kotlin.Int" -> PsiType.INT
"kotlin.Long" -> PsiType.LONG
"kotlin.Short" -> PsiType.SHORT
"kotlin.Boolean" -> PsiType.BOOLEAN
"kotlin.Byte" -> PsiType.BYTE
"kotlin.Char" -> PsiType.CHAR
"kotlin.Double" -> PsiType.DOUBLE
"kotlin.Float" -> PsiType.FLOAT
val typeFqName = kotlinType.constructor.declarationDescriptor?.fqNameSafe?.asString() ?: return null
return when (typeFqName) {
"kotlin.Int" -> PsiType.INT
"kotlin.Long" -> PsiType.LONG
"kotlin.Short" -> PsiType.SHORT
"kotlin.Boolean" -> PsiType.BOOLEAN
"kotlin.Byte" -> PsiType.BYTE
"kotlin.Char" -> PsiType.CHAR
"kotlin.Double" -> PsiType.DOUBLE
"kotlin.Float" -> PsiType.FLOAT
"kotlin.Unit" -> PsiType.VOID
"kotlin.String" -> PsiType.getJavaLangString(context.manager, context.resolveScope)
else -> PsiType.getTypeByName(typeFqName, context.project, context.resolveScope)
@@ -91,11 +92,16 @@ private fun psiType(kotlinType: KotlinType, context: PsiElement): PsiType? {
class KtLightPsiNameValuePair private constructor(
override val kotlinOrigin: KtElement,
val valueArgument: KtValueArgument,
lightParent: PsiElement
lightParent: PsiElement,
private val argument: (KtLightPsiNameValuePair) -> PsiAnnotationMemberValue?
) : KtLightElementBase(lightParent),
PsiNameValuePair {
constructor(valueArgument: KtValueArgument, lightParent: PsiElement) : this(valueArgument.asElement(), valueArgument, lightParent)
constructor(
valueArgument: KtValueArgument,
lightParent: PsiElement,
argument: (KtLightPsiNameValuePair) -> PsiAnnotationMemberValue?
) : this(valueArgument.asElement(), valueArgument, lightParent, argument)
override fun setValue(newValue: PsiAnnotationMemberValue): PsiAnnotationMemberValue =
throw UnsupportedOperationException("can't modify KtLightPsiNameValuePair")
@@ -104,8 +110,9 @@ class KtLightPsiNameValuePair private constructor(
override fun getName(): String? = valueArgument.getArgumentName()?.asName?.asString()
override fun getValue(): PsiAnnotationMemberValue? =
valueArgument.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(this, it) }
private val _value: PsiAnnotationMemberValue? by lazyPub { argument(this) }
override fun getValue(): PsiAnnotationMemberValue? = _value
override fun getLiteralValue(): String? = (getValue() as? PsiLiteralExpression)?.value?.toString()
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
import org.jetbrains.kotlin.psi.*
@@ -40,6 +41,7 @@ import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.kotlin.resolve.descriptorUtil.declaresOrInheritsDefaultValue
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmOverloadsAnnotation
import org.jetbrains.kotlin.resolve.source.getPsi
@@ -96,28 +98,17 @@ class KtLightAnnotationForSourceEntry(
override fun findDeclaredAttributeValue(name: String?): PsiAnnotationMemberValue? = getAttributeValue(name, false)
private fun getCallEntry(name: String): MutableMap.MutableEntry<ValueParameterDescriptor, ResolvedValueArgument>? {
val resolvedCall = kotlinOrigin.getResolvedCall() ?: return null
return resolvedCall.valueArguments.entries.find { (param, _) -> param.name.asString() == name } ?: return null
}
private fun getAttributeValue(name: String?, useDefault: Boolean): PsiAnnotationMemberValue? {
val name = name ?: "value"
val callEntry = getCallEntry(name) ?: return null
val resolvedCall = kotlinOrigin.getResolvedCall() ?: return null
val callEntry = resolvedCall.valueArguments.entries.find { (param, _) -> param.name.asString() == name } ?: return null
val valueArguments = callEntry.value.arguments
val valueArgument = valueArguments.firstOrNull()
val argument = valueArgument?.getArgumentExpression()
if (argument != null) {
val arrayExpected = callEntry.key?.type?.let { KotlinBuiltIns.isArray(it) } ?: false
if (arrayExpected && (argument is KtStringTemplateExpression || argument is KtConstantExpression || getAnnotationName(argument) != null))
return KtLightPsiArrayInitializerMemberValue(
PsiTreeUtil.findCommonParent(valueArguments.map { it.getArgumentExpression() }) as KtElement,
this,
{ self ->
valueArguments.mapNotNull {
it.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
})
val valueArgument = callEntry.value.arguments.firstOrNull()
if (valueArgument != null) {
ktLightAnnotationParameterList.attributes.find { (it as KtLightPsiNameValuePair).valueArgument === valueArgument }?.let {
return it.value
}
@@ -153,13 +144,40 @@ class KtLightAnnotationForSourceEntry(
inner class KtLightAnnotationParameterList() : KtLightElementBase(this),
PsiAnnotationParameterList {
override val kotlinOrigin get() = null
override val kotlinOrigin: KtElement? get() = null
private val _attributes: Array<PsiNameValuePair> by lazyPub {
this@KtLightAnnotationForSourceEntry.kotlinOrigin.valueArguments.map { KtLightPsiNameValuePair(it as KtValueArgument, this) }
this@KtLightAnnotationForSourceEntry.kotlinOrigin.valueArguments.map { makeLightPsiNameValuePair(it as KtValueArgument) }
.toTypedArray<PsiNameValuePair>()
}
private fun makeArrayInitializerIfExpected(pair: KtLightPsiNameValuePair): PsiAnnotationMemberValue? {
val valueArgument = pair.valueArgument
val name = valueArgument.name ?: "value"
val callEntry = getCallEntry(name) ?: return null
val valueArguments = callEntry.value.arguments
val argument = valueArguments.firstOrNull()?.getArgumentExpression() ?: return null
if (!callEntry.key.type.let { KotlinBuiltIns.isArray(it) }) return null
if (argument !is KtStringTemplateExpression && argument !is KtConstantExpression && getAnnotationName(argument) == null) {
return null
}
val parent = PsiTreeUtil.findCommonParent(valueArguments.map { it.getArgumentExpression() }) as KtElement
return KtLightPsiArrayInitializerMemberValue(parent, pair) { self ->
valueArguments.mapNotNull {
it.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
}
}
private fun makeLightPsiNameValuePair(valueArgument: KtValueArgument) = KtLightPsiNameValuePair(valueArgument, this) { self ->
makeArrayInitializerIfExpected(self)
?: self.valueArgument.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
override fun getAttributes(): Array<PsiNameValuePair> = _attributes
}
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
import org.jetbrains.kotlin.psi.*
@@ -40,6 +41,7 @@ import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.kotlin.resolve.descriptorUtil.declaresOrInheritsDefaultValue
import org.jetbrains.kotlin.resolve.jvm.annotations.findJvmOverloadsAnnotation
import org.jetbrains.kotlin.resolve.source.getPsi
@@ -98,28 +100,17 @@ class KtLightAnnotationForSourceEntry(
override fun findDeclaredAttributeValue(name: String?): PsiAnnotationMemberValue? = getAttributeValue(name, false)
private fun getCallEntry(name: String): MutableMap.MutableEntry<ValueParameterDescriptor, ResolvedValueArgument>? {
val resolvedCall = kotlinOrigin.getResolvedCall() ?: return null
return resolvedCall.valueArguments.entries.find { (param, _) -> param.name.asString() == name } ?: return null
}
private fun getAttributeValue(name: String?, useDefault: Boolean): PsiAnnotationMemberValue? {
val name = name ?: "value"
val callEntry = getCallEntry(name) ?: return null
val resolvedCall = kotlinOrigin.getResolvedCall() ?: return null
val callEntry = resolvedCall.valueArguments.entries.find { (param, _) -> param.name.asString() == name } ?: return null
val valueArguments = callEntry.value.arguments
val valueArgument = valueArguments.firstOrNull()
val argument = valueArgument?.getArgumentExpression()
if (argument != null) {
val arrayExpected = callEntry.key?.type?.let { KotlinBuiltIns.isArray(it) } ?: false
if (arrayExpected && (argument is KtStringTemplateExpression || argument is KtConstantExpression || getAnnotationName(argument) != null))
return KtLightPsiArrayInitializerMemberValue(
PsiTreeUtil.findCommonParent(valueArguments.map { it.getArgumentExpression() }) as KtElement,
this,
{ self ->
valueArguments.mapNotNull {
it.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
})
val valueArgument = callEntry.value.arguments.firstOrNull()
if (valueArgument != null) {
ktLightAnnotationParameterList.attributes.find { (it as KtLightPsiNameValuePair).valueArgument === valueArgument }?.let {
return it.value
}
@@ -155,13 +146,40 @@ class KtLightAnnotationForSourceEntry(
inner class KtLightAnnotationParameterList() : KtLightElementBase(this),
PsiAnnotationParameterList {
override val kotlinOrigin get() = null
override val kotlinOrigin: KtElement? get() = null
private val _attributes: Array<PsiNameValuePair> by lazyPub {
this@KtLightAnnotationForSourceEntry.kotlinOrigin.valueArguments.map { KtLightPsiNameValuePair(it as KtValueArgument, this) }
this@KtLightAnnotationForSourceEntry.kotlinOrigin.valueArguments.map { makeLightPsiNameValuePair(it as KtValueArgument) }
.toTypedArray<PsiNameValuePair>()
}
private fun makeArrayInitializerIfExpected(pair: KtLightPsiNameValuePair): PsiAnnotationMemberValue? {
val valueArgument = pair.valueArgument
val name = valueArgument.name ?: "value"
val callEntry = getCallEntry(name) ?: return null
val valueArguments = callEntry.value.arguments
val argument = valueArguments.firstOrNull()?.getArgumentExpression() ?: return null
if (!callEntry.key.type.let { KotlinBuiltIns.isArray(it) }) return null
if (argument !is KtStringTemplateExpression && argument !is KtConstantExpression && getAnnotationName(argument) == null) {
return null
}
val parent = PsiTreeUtil.findCommonParent(valueArguments.map { it.getArgumentExpression() }) as KtElement
return KtLightPsiArrayInitializerMemberValue(parent, pair) { self ->
valueArguments.mapNotNull {
it.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
}
}
private fun makeLightPsiNameValuePair(valueArgument: KtValueArgument) = KtLightPsiNameValuePair(valueArgument, this) { self ->
makeArrayInitializerIfExpected(self)
?: self.valueArgument.getArgumentExpression()?.let { convertToLightAnnotationMemberValue(self, it) }
}
override fun getAttributes(): Array<PsiNameValuePair> = _attributes
}
@@ -385,7 +403,7 @@ private fun unwrapCall(callee: KtExpression): KtExpression = when (callee) {
private fun getAnnotationName(callee: KtExpression): String? {
val callee = unwrapCall(callee)
val resultingDescriptor = callee.getResolvedCall()?.resultingDescriptor
val resultingDescriptor = callee.getResolvedCall()?.resultingDescriptor
if (resultingDescriptor is ClassConstructorDescriptor) {
val ktClass = resultingDescriptor.constructedClass.source.getPsi() as? KtClass
if (ktClass?.isAnnotation() == true) return ktClass.fqName?.toString()
@@ -24,6 +24,7 @@ import com.intellij.psi.*
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.UsefulTestCase
import junit.framework.TestCase
import org.jetbrains.kotlin.asJava.elements.KtLightAnnotationForSourceEntry
import org.jetbrains.kotlin.config.LanguageFeature
@@ -108,6 +109,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("attribute") as PsiElement
assertTextAndRange("InnerAnnotation()", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
}
fun testConstants() {
@@ -277,6 +279,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("attribute") as PsiElement
assertTextAndRange("InnerAnnotation()", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
}
fun testAnnotationsInAnnotationsInAnnotationsDeclarations() {
@@ -337,6 +340,8 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("params") as PsiElement
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
TestCase.assertTrue(annotations.first().parameterList.attributes.any { (it.value == annotationAttributeVal) })
assertTextAndRange("arrayOf(\"abc\", \"def\")", annotationAttributeVal)
annotationAttributeVal as PsiArrayInitializerMemberValue
@@ -424,6 +429,8 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
assertTextAndRange("Inner()", innerAnnotationAttributeVal)
assertIsKtLightAnnotation("Inner()", innerAnnotationAttributeVal)
}
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
TestCase.assertTrue(annotation.parameterList.attributes.any { it.value == annotationAttributeVal })
}
}
@@ -444,6 +451,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("value") as PsiArrayInitializerMemberValue
assertTextAndRange("arrayOf(\"a\", \"b\", \"c\")", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
for ((i, arg) in listOf("\"a\"", "\"b\"", "\"c\"").withIndex()) {
assertTextAndRange(arg, annotationAttributeVal.initializers[i])
}
@@ -465,6 +473,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("value") as PsiArrayInitializerMemberValue
assertTextAndRange("arrayOf(*arrayOf(\"a\", \"b\"), \"c\", *arrayOf(\"d\", \"e\"))", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
for ((i, arg) in listOf("arrayOf(\"a\", \"b\")", "\"c\"", "arrayOf(\"d\", \"e\")").withIndex()) {
assertTextAndRange(arg, annotationAttributeVal.initializers[i])
}
@@ -486,6 +495,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("value") as PsiArrayInitializerMemberValue
assertTextAndRange("[\"a\", \"b\", \"c\"]", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
for ((i, arg) in listOf("\"a\"", "\"b\"", "\"c\"").withIndex()) {
assertTextAndRange(arg, annotationAttributeVal.initializers[i])
}
@@ -507,6 +517,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("value") as PsiArrayInitializerMemberValue
assertTextAndRange("\"a\"", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
for ((i, arg) in listOf("\"a\"").withIndex()) {
assertTextAndRange(arg, annotationAttributeVal.initializers[i])
}
@@ -24,6 +24,7 @@ import com.intellij.psi.*
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.UsefulTestCase
import junit.framework.TestCase
import org.jetbrains.kotlin.asJava.elements.KtLightAnnotationForSourceEntry
import org.jetbrains.kotlin.config.LanguageFeature
@@ -110,6 +111,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("attribute") as PsiElement
assertTextAndRange("InnerAnnotation()", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
}
fun testConstants() {
@@ -279,6 +281,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("attribute") as PsiElement
assertTextAndRange("InnerAnnotation()", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
}
fun testAnnotationsInAnnotationsInAnnotationsDeclarations() {
@@ -339,6 +342,8 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("params") as PsiElement
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
TestCase.assertTrue(annotations.first().parameterList.attributes.any { (it.value == annotationAttributeVal) })
assertTextAndRange("arrayOf(\"abc\", \"def\")", annotationAttributeVal)
annotationAttributeVal as PsiArrayInitializerMemberValue
@@ -426,6 +431,8 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
assertTextAndRange("Inner()", innerAnnotationAttributeVal)
assertIsKtLightAnnotation("Inner()", innerAnnotationAttributeVal)
}
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
TestCase.assertTrue(annotation.parameterList.attributes.any { it.value == annotationAttributeVal })
}
}
@@ -446,6 +453,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("value") as PsiArrayInitializerMemberValue
assertTextAndRange("arrayOf(\"a\", \"b\", \"c\")", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
for ((i, arg) in listOf("\"a\"", "\"b\"", "\"c\"").withIndex()) {
assertTextAndRange(arg, annotationAttributeVal.initializers[i])
}
@@ -467,6 +475,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("value") as PsiArrayInitializerMemberValue
assertTextAndRange("arrayOf(*arrayOf(\"a\", \"b\"), \"c\", *arrayOf(\"d\", \"e\"))", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
for ((i, arg) in listOf("arrayOf(\"a\", \"b\")", "\"c\"", "arrayOf(\"d\", \"e\")").withIndex()) {
assertTextAndRange(arg, annotationAttributeVal.initializers[i])
}
@@ -488,6 +497,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("value") as PsiArrayInitializerMemberValue
assertTextAndRange("[\"a\", \"b\", \"c\"]", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
for ((i, arg) in listOf("\"a\"", "\"b\"", "\"c\"").withIndex()) {
assertTextAndRange(arg, annotationAttributeVal.initializers[i])
}
@@ -509,6 +519,7 @@ class KtLightAnnotationTest : KotlinLightCodeInsightFixtureTestCase() {
val annotations = myFixture.findClass("AnnotatedClass").expectAnnotations(1)
val annotationAttributeVal = annotations.first().findAttributeValue("value") as PsiArrayInitializerMemberValue
assertTextAndRange("\"a\"", annotationAttributeVal)
UsefulTestCase.assertInstanceOf(annotationAttributeVal.parent, PsiNameValuePair::class.java)
for ((i, arg) in listOf("\"a\"").withIndex()) {
assertTextAndRange(arg, annotationAttributeVal.initializers[i])
}