Kapt: calculate default values of Kotlin annotations correctly for annotations from binaries (KT-13733)

(cherry picked from commit fed9cb2)
This commit is contained in:
Yan Zhulanow
2016-09-05 21:29:24 +03:00
parent 30a29eaa46
commit ef375e66cd
3 changed files with 25 additions and 1 deletions
@@ -0,0 +1,12 @@
// Some user annotation is required because annoations from kotlin.jvm are filtered out in kapt
annotation class Anno
@JvmSuppressWildcards
@Anno
class Test
@JvmSuppressWildcards(suppress = true)
class TestTrue
@JvmSuppressWildcards(suppress = false)
class TestFalse
@@ -52,7 +52,7 @@ private fun PsiModifierList.getJavaModifiers(): Set<Modifier> {
internal fun PsiExpression.calcConstantValue(evaluator: PsiConstantEvaluationHelper? = null): Any? {
return when (this) {
is PsiLiteral -> value
is KtLightAnnotation.LightExpressionValue<*> -> getConstantValue()
is KtLightAnnotation.LightExpressionValue<*> -> getConstantValue() ?: delegate.calcConstantValue(evaluator)
is PsiExpression -> (evaluator ?: getConstantEvaluator(this)).computeConstantExpression(this)
else -> null
}
@@ -217,4 +217,16 @@ class ProcessorTests : AbstractProcessorTest() {
val annotations = (annotationHandler as SourceRetentionAnnotationHandlerImpl).sourceRetentionAnnotations.sorted()
assertEquals("Source1, Source2, Source3, Source4, Test5\$Source5", annotations.joinToString())
}
fun testKotlinAnnotationDefaultValueFromBinary() = test("DefaultValueFromBinary", "*") { set, roundEnv, env ->
fun check(expectedValue: Boolean, className: String) {
val clazz = env.findClass(className)
val anno = clazz.getAnnotation(JvmSuppressWildcards::class.java)!!
assertEquals(expectedValue, anno.suppress)
}
check(true, "Test")
check(true, "TestTrue")
check(false, "TestFalse")
}
}