Light Classes: Correctly handle annotations for property parameters

When getting annotations for KtLightParameter which is property parameter we should return annotations for parameter instead of property

#KT-19671 Fixed
This commit is contained in:
Vyacheslav Gerasimov
2017-08-14 21:28:05 +03:00
parent 1e73921200
commit c549c63100
4 changed files with 66 additions and 11 deletions
@@ -0,0 +1,5 @@
annotation class MyAnnotation
class Test1(@MyAnnotation var bar: Int)
class Test2(@get:MyAnnotation @set:MyAnnotation @setparam:MyAnnotation @property:MyAnnotation @field:MyAnnotation var bar: Int)
@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import org.jetbrains.uast.*
import org.jetbrains.uast.test.env.findElementByText
import org.jetbrains.uast.visitor.UastVisitor
import org.junit.Assert
import org.junit.Test
@@ -67,4 +68,34 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
assertTrue(bar.containingFile.text!!, bar.psi.modifierList.hasModifierProperty(PsiModifier.DEFAULT))
}
}
@Test fun testParameterPropertyWithAnnotation() {
doTest("ParameterPropertyWithAnnotation") { _, file ->
val test1 = file.classes.find { it.name == "Test1" }!!
val constructor1 = test1.methods.find { it.name == "Test1" }!!
assertTrue(constructor1.uastParameters.first().annotations.any { it.qualifiedName == "MyAnnotation" })
val getter1 = test1.methods.find { it.name == "getBar" }!!
assertFalse(getter1.annotations.any { it.qualifiedName == "MyAnnotation" })
val setter1 = test1.methods.find { it.name == "setBar" }!!
assertFalse(setter1.annotations.any { it.qualifiedName == "MyAnnotation" })
assertFalse(setter1.uastParameters.first().annotations.any { it.qualifiedName == "MyAnnotation" })
val test2 = file.classes.find { it.name == "Test2" }!!
val constructor2 = test2.methods.find { it.name == "Test2" }!!
assertFalse(constructor2.uastParameters.first().annotations.any { it.qualifiedName == "MyAnnotation" })
val getter2 = test2.methods.find { it.name == "getBar" }!!
getter2.annotations.single { it.qualifiedName == "MyAnnotation" }
val setter2 = test2.methods.find { it.name == "setBar" }!!
setter2.annotations.single { it.qualifiedName == "MyAnnotation" }
setter2.uastParameters.first().annotations.single { it.qualifiedName == "MyAnnotation" }
test2.fields.find { it.name == "bar" }!!.annotations.single { it.qualifiedName == "MyAnnotation" }
}
}
}