diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/lightClassUtils.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/lightClassUtils.kt index 9466b7a96e0..18452b6471a 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/lightClassUtils.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/lightClassUtils.kt @@ -119,6 +119,10 @@ private fun KtParameter.toAnnotationLightMethod(): PsiMethod? { return LightClassUtil.getLightClassMethod(this) } +fun KtParameter.toLightGetter(): PsiMethod? = LightClassUtil.getLightClassPropertyMethods(this).getter + +fun KtParameter.toLightSetter(): PsiMethod? = LightClassUtil.getLightClassPropertyMethods(this).setter + fun KtTypeParameter.toPsiTypeParameters(): List { val paramList = getNonStrictParentOfType() ?: return listOf() diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt index a50796842a3..918b8465869 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt @@ -17,6 +17,8 @@ package org.jetbrains.uast.kotlin import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.asJava.toLightGetter +import org.jetbrains.kotlin.asJava.toLightSetter import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType @@ -38,10 +40,14 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : UEle val target = psi.useSiteTarget?.getAnnotationUseSiteTarget() when (target) { AnnotationUseSiteTarget.PROPERTY_GETTER -> - parent = (parentUnwrapped as? KtProperty)?.getter ?: parent + parent = (parentUnwrapped as? KtProperty)?.getter + ?: (parentUnwrapped as? KtParameter)?.toLightGetter() + ?: parent AnnotationUseSiteTarget.PROPERTY_SETTER -> - parent = (parentUnwrapped as? KtProperty)?.setter ?: parent + parent = (parentUnwrapped as? KtProperty)?.setter + ?: (parentUnwrapped as? KtParameter)?.toLightSetter() + ?: parent } } diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.kt b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.kt index 74763263e6f..95cf4da360c 100644 --- a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.kt +++ b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.kt @@ -1,5 +1,9 @@ annotation class MyAnnotation +annotation class MyAnnotation2 +annotation class MyAnnotation3 +annotation class MyAnnotation4 +annotation class MyAnnotation5 class Test1(@MyAnnotation var bar: Int) -class Test2(@get:MyAnnotation @set:MyAnnotation @setparam:MyAnnotation @property:MyAnnotation @field:MyAnnotation var bar: Int) \ No newline at end of file +class Test2(@get:MyAnnotation @set:MyAnnotation2 @setparam:MyAnnotation3 @property:MyAnnotation4 @field:MyAnnotation5 var bar: Int) \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log.txt b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log.txt index 72ea91462ec..69573a72273 100644 --- a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log.txt +++ b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log.txt @@ -1,5 +1,9 @@ UFile (package = ) UClass (name = MyAnnotation) + UClass (name = MyAnnotation2) + UClass (name = MyAnnotation3) + UClass (name = MyAnnotation4) + UClass (name = MyAnnotation5) UClass (name = Test1) UField (name = bar) UAnnotation (fqName = null) @@ -13,14 +17,14 @@ UFile (package = ) UAnnotation (fqName = null) UClass (name = Test2) UField (name = bar) - UAnnotation (fqName = MyAnnotation) + UAnnotation (fqName = MyAnnotation5) UAnnotation (fqName = null) UAnnotationMethod (name = getBar) UAnnotation (fqName = MyAnnotation) UAnnotationMethod (name = setBar) - UAnnotation (fqName = MyAnnotation) + UAnnotation (fqName = MyAnnotation2) UParameter (name = p) - UAnnotation (fqName = MyAnnotation) + UAnnotation (fqName = MyAnnotation3) UAnnotation (fqName = null) UAnnotationMethod (name = Test2) UParameter (name = bar) diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render.txt b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render.txt index 9748b245f8f..19d3c2b5a8f 100644 --- a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render.txt +++ b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render.txt @@ -1,6 +1,18 @@ public abstract annotation MyAnnotation { } +public abstract annotation MyAnnotation2 { +} + +public abstract annotation MyAnnotation3 { +} + +public abstract annotation MyAnnotation4 { +} + +public abstract annotation MyAnnotation5 { +} + public final class Test1 { private var bar: int public final fun getBar() : int = UastEmptyExpression @@ -12,7 +24,7 @@ public final class Test2 { private var bar: int @MyAnnotation public final fun getBar() : int = UastEmptyExpression - @MyAnnotation + @MyAnnotation2 public final fun setBar(p: int) : void = UastEmptyExpression public fun Test2(bar: int) = UastEmptyExpression } diff --git a/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt index 6b31d234b3d..05861310bee 100644 --- a/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/AbstractKotlinRenderLogTest.kt @@ -60,7 +60,7 @@ abstract class AbstractKotlinRenderLogTest : AbstractKotlinUastTest(), RenderLog if (expectedParents != null) { assertNotNull("Expected to be able to convert PSI element $element", uElement) val parents = generateSequence(uElement!!.uastParent) { it.uastParent }.joinToString { it.asLogString() } - assertEquals("Inconsistent parents for $uElement (converted from $element)", expectedParents, parents) + assertEquals("Inconsistent parents for ${uElement.asLogString()} (converted from $element)", expectedParents, parents) } super.visitElement(element) }