Parse enum arrays correctly
(cherry picked from commit 5f2b5cf)
This commit is contained in:
committed by
Yan Zhulanow
parent
f15f90a719
commit
82160bc86d
@@ -0,0 +1,7 @@
|
|||||||
|
package org.jetbrains.kotlin.annotation.processing.test.processor
|
||||||
|
|
||||||
|
enum class RGBColors { RED, GREEN, BLUE }
|
||||||
|
annotation class ColorsAnnotation(val colors: Array<RGBColors>)
|
||||||
|
|
||||||
|
@ColorsAnnotation(colors = arrayOf(RGBColors.BLUE, RGBColors.RED))
|
||||||
|
class Test
|
||||||
+6
-2
@@ -92,8 +92,12 @@ private fun getConstantValue(
|
|||||||
is PsiArrayInitializerMemberValue -> psiValue.initializers.toList()
|
is PsiArrayInitializerMemberValue -> psiValue.initializers.toList()
|
||||||
else -> listOf(psiValue)
|
else -> listOf(psiValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jComponentType.isPrimitive || jComponentType.isAnnotation || jComponentType.canonicalName == JAVA_LANG_STRING) {
|
if (jComponentType.isPrimitive
|
||||||
|
|| jComponentType.isAnnotation
|
||||||
|
|| jComponentType.isEnum
|
||||||
|
|| jComponentType.canonicalName == JAVA_LANG_STRING
|
||||||
|
) {
|
||||||
val arr = Array.newInstance(jComponentType, arrayValues.size)
|
val arr = Array.newInstance(jComponentType, arrayValues.size)
|
||||||
arrayValues.forEachIndexed { i, componentPsiValue ->
|
arrayValues.forEachIndexed { i, componentPsiValue ->
|
||||||
val componentValue = getConstantValue(componentPsiValue, returnType.componentType, jComponentType, evaluator)
|
val componentValue = getConstantValue(componentPsiValue, returnType.componentType, jComponentType, evaluator)
|
||||||
|
|||||||
+11
-3
@@ -16,9 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.annotation.processing.test.processor
|
package org.jetbrains.kotlin.annotation.processing.test.processor
|
||||||
|
|
||||||
import com.intellij.psi.JavaPsiFacade
|
|
||||||
import com.intellij.psi.impl.PsiSubstitutorImpl
|
|
||||||
import com.intellij.psi.util.PsiTypesUtil
|
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import org.jetbrains.kotlin.annotation.processing.impl.DisposableRef
|
import org.jetbrains.kotlin.annotation.processing.impl.DisposableRef
|
||||||
import org.jetbrains.kotlin.annotation.processing.impl.KotlinProcessingEnvironment
|
import org.jetbrains.kotlin.annotation.processing.impl.KotlinProcessingEnvironment
|
||||||
@@ -35,6 +32,10 @@ import javax.lang.model.type.DeclaredType
|
|||||||
import javax.lang.model.type.TypeMirror
|
import javax.lang.model.type.TypeMirror
|
||||||
import javax.lang.model.type.TypeVariable
|
import javax.lang.model.type.TypeVariable
|
||||||
|
|
||||||
|
// See EnumArray.kt
|
||||||
|
enum class RGBColors { RED, GREEN, BLUE }
|
||||||
|
annotation class ColorsAnnotation(val colors: Array<RGBColors>)
|
||||||
|
|
||||||
class ProcessorTests : AbstractProcessorTest() {
|
class ProcessorTests : AbstractProcessorTest() {
|
||||||
override val testDataDir = "plugins/annotation-processing/testData/processors"
|
override val testDataDir = "plugins/annotation-processing/testData/processors"
|
||||||
|
|
||||||
@@ -127,6 +128,13 @@ class ProcessorTests : AbstractProcessorTest() {
|
|||||||
assertTrue((anno2.getParam("e") as JeArrayAnnotationValue).value.first() is JeTypeAnnotationValue)
|
assertTrue((anno2.getParam("e") as JeArrayAnnotationValue).value.first() is JeTypeAnnotationValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testEnumArray() = test("EnumArray", "*") { set, roundEnv, env ->
|
||||||
|
val testClass = env.findClass("org.jetbrains.kotlin.annotation.processing.test.processor.Test")
|
||||||
|
val enumAnno = testClass.getAnnotation(ColorsAnnotation::class.java)
|
||||||
|
assertNotNull(enumAnno)
|
||||||
|
assertEquals(listOf("BLUE", "RED"), enumAnno!!.colors.map { it.name })
|
||||||
|
}
|
||||||
|
|
||||||
fun testStringArray() = test("StringArray", "*") { set, roundEnv, env ->
|
fun testStringArray() = test("StringArray", "*") { set, roundEnv, env ->
|
||||||
val testClass = env.findClass("Test")
|
val testClass = env.findClass("Test")
|
||||||
val suppress = testClass.getAnnotation(Suppress::class.java)
|
val suppress = testClass.getAnnotation(Suppress::class.java)
|
||||||
|
|||||||
Reference in New Issue
Block a user