diff --git a/plugins/annotation-processing/testData/processors/StringArray.kt b/plugins/annotation-processing/testData/processors/StringArray.kt new file mode 100644 index 00000000000..afac1d3f65e --- /dev/null +++ b/plugins/annotation-processing/testData/processors/StringArray.kt @@ -0,0 +1,2 @@ +@Suppress("Tom", "Mary") +class Test \ No newline at end of file diff --git a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/KotlinAnnotationProxyMaker.kt b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/KotlinAnnotationProxyMaker.kt index 3379d5b448b..5b69e6c875f 100644 --- a/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/KotlinAnnotationProxyMaker.kt +++ b/plugins/java-model-wrappers/src/org/jetbrains/kotlin/java/model/internal/KotlinAnnotationProxyMaker.kt @@ -64,6 +64,8 @@ class KotlinAnnotationProxyMaker(val annotation: PsiAnnotation, val annotationCl } } +private val JAVA_LANG_STRING = "java.lang.String" + private fun getConstantValue( psiValue: PsiAnnotationMemberValue, returnType: PsiType, @@ -74,7 +76,7 @@ private fun getConstantValue( when { returnType == PsiType.NULL || returnType == PsiType.VOID -> unexpectedType("void") - returnType.fqName == "java.lang.String" -> return (psiValue as? PsiExpression)?.calcConstantValue(evaluator) + returnType.fqName == JAVA_LANG_STRING -> return (psiValue as? PsiExpression)?.calcConstantValue(evaluator) jReturnType.isAnnotation -> { if (psiValue !is PsiAnnotation) error("psiValue is not a PsiAnnotation") val annotationClass = PsiTypesUtil.getPsiClass(returnType) ?: error("Can't resolve type $returnType") @@ -91,16 +93,16 @@ private fun getConstantValue( else -> listOf(psiValue) } - if (!jComponentType.isPrimitive && !jComponentType.isAnnotation) { - val typeMirrors = arrayValues.map { getObjectType(it).toJeType(manager) } - return MirroredTypesExceptionProxy(Collections.unmodifiableList(typeMirrors)) - } else { + if (jComponentType.isPrimitive || jComponentType.isAnnotation || jComponentType.canonicalName == JAVA_LANG_STRING) { val arr = Array.newInstance(jComponentType, arrayValues.size) - arrayValues.forEachIndexed { i, componentPsiValue -> + arrayValues.forEachIndexed { i, componentPsiValue -> val componentValue = getConstantValue(componentPsiValue, returnType.componentType, jComponentType, evaluator) try { Array.set(arr, i, componentValue) } catch (e: IllegalArgumentException) { return null } } return arr + } else { + val typeMirrors = arrayValues.map { getObjectType(it).toJeType(manager) } + return MirroredTypesExceptionProxy(Collections.unmodifiableList(typeMirrors)) } } jReturnType.isEnum -> { diff --git a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt index 369e587a5e7..de7800bba0d 100644 --- a/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt +++ b/plugins/plugins-tests/tests/org/jetbrains/kotlin/annotation/processing/test/processor/ProcessorTests.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.annotation.processing.test.processor import org.jetbrains.kotlin.java.model.elements.* +import org.jetbrains.kotlin.java.model.types.JeDeclaredType import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import javax.lang.model.element.AnnotationMirror @@ -111,4 +112,11 @@ class ProcessorTests : AbstractProcessorTest() { assertTrue(anno2.getParam("d") is JeTypeAnnotationValue) assertTrue((anno2.getParam("e") as JeArrayAnnotationValue).value.first() is JeTypeAnnotationValue) } + + fun testStringArray() = test("StringArray", "*") { set, roundEnv, env -> + val testClass = env.findClass("Test") + val suppress = testClass.getAnnotation(Suppress::class.java) + assertNotNull(suppress) + assertEquals(listOf("Tom", "Mary"), suppress!!.names.toList()) + } } \ No newline at end of file