diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt index bc8dbc1ae7d..4145d470b50 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUMethod.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.asJava.elements.isSetter import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.uast.* +import org.jetbrains.uast.java.annotations import org.jetbrains.uast.java.internal.JavaUElementWithComments import org.jetbrains.uast.kotlin.* @@ -46,7 +47,9 @@ open class KotlinUMethod( override fun getNameIdentifier() = UastLightIdentifier(psi, kotlinOrigin as KtNamedDeclaration?) override val annotations by lz { - (kotlinOrigin as? KtDeclaration)?.annotationEntries?.map { KotlinUAnnotation(it, this) } ?: emptyList() + psi.annotations + .mapNotNull { (it as? KtLightElement<*, *>)?.kotlinOrigin as? KtAnnotationEntry } + .map { KotlinUAnnotation(it, this) } } override val uastParameters by lz { diff --git a/plugins/uast-kotlin/testData/PropertyWithAnnotation.kt b/plugins/uast-kotlin/testData/PropertyWithAnnotation.kt new file mode 100644 index 00000000000..854cd7ee550 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyWithAnnotation.kt @@ -0,0 +1,13 @@ +annotation class TestAnnotation + +@TestAnnotation +val prop1: Int = 0 + +@get:TestAnnotation +val prop2: Int + get() = 0 + +@set:TestAnnotation +var prop3: Int = 0 + get() = 0 + set(value) { field = value } \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/PropertyWithAnnotation.log.txt b/plugins/uast-kotlin/testData/PropertyWithAnnotation.log.txt new file mode 100644 index 00000000000..d4625e3e500 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyWithAnnotation.log.txt @@ -0,0 +1,23 @@ +UFile (package = ) + UClass (name = PropertyWithAnnotationKt) + UField (name = prop1) + UAnnotation (fqName = null) + ULiteralExpression (value = 0) + UField (name = prop3) + UAnnotation (fqName = null) + ULiteralExpression (value = 0) + UAnnotationMethod (name = getProp1) + UAnnotationMethod (name = getProp2) + UAnnotation (fqName = TestAnnotation) + ULiteralExpression (value = 0) + UAnnotationMethod (name = getProp3) + ULiteralExpression (value = 0) + UAnnotationMethod (name = setProp3) + UAnnotation (fqName = TestAnnotation) + UParameter (name = value) + UAnnotation (fqName = null) + UBlockExpression + UBinaryExpression (operator = =) + USimpleNameReferenceExpression (identifier = field) + USimpleNameReferenceExpression (identifier = value) + UClass (name = TestAnnotation) diff --git a/plugins/uast-kotlin/testData/PropertyWithAnnotation.render.txt b/plugins/uast-kotlin/testData/PropertyWithAnnotation.render.txt new file mode 100644 index 00000000000..2f5bca1a4b3 --- /dev/null +++ b/plugins/uast-kotlin/testData/PropertyWithAnnotation.render.txt @@ -0,0 +1,15 @@ +public final class PropertyWithAnnotationKt { + private static final var prop1: int = 0 + private static var prop3: int = 0 + public static final fun getProp1() : int = UastEmptyExpression + @TestAnnotation + public static final fun getProp2() : int = 0 + public static final fun getProp3() : int = 0 + @TestAnnotation + public static final fun setProp3(value: int) : void { + field = value + } +} + +public abstract annotation TestAnnotation { +} diff --git a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt index 365856c0f0f..a7512fddab7 100644 --- a/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt +++ b/plugins/uast-kotlin/tests/SimpleKotlinRenderLogTest.kt @@ -28,4 +28,6 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() { @Test fun testQualifiedConstructorCall() = doTest("QualifiedConstructorCall") @Test fun testPropertyDelegate() = doTest("PropertyDelegate") + + @Test fun testPropertyWithAnnotation() = doTest("PropertyWithAnnotation") } \ No newline at end of file