UAST: Fix KotlinUMethod annotation handling, properly handle use site targets
#KT-16834 Fixed #KT-18893 Fixed
This commit is contained in:
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.asJava.elements.isSetter
|
|||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.uast.*
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.java.annotations
|
||||||
import org.jetbrains.uast.java.internal.JavaUElementWithComments
|
import org.jetbrains.uast.java.internal.JavaUElementWithComments
|
||||||
import org.jetbrains.uast.kotlin.*
|
import org.jetbrains.uast.kotlin.*
|
||||||
|
|
||||||
@@ -46,7 +47,9 @@ open class KotlinUMethod(
|
|||||||
override fun getNameIdentifier() = UastLightIdentifier(psi, kotlinOrigin as KtNamedDeclaration?)
|
override fun getNameIdentifier() = UastLightIdentifier(psi, kotlinOrigin as KtNamedDeclaration?)
|
||||||
|
|
||||||
override val annotations by lz {
|
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 {
|
override val uastParameters by lz {
|
||||||
|
|||||||
@@ -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 }
|
||||||
@@ -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)
|
||||||
@@ -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 {
|
||||||
|
}
|
||||||
@@ -28,4 +28,6 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() {
|
|||||||
@Test fun testQualifiedConstructorCall() = doTest("QualifiedConstructorCall")
|
@Test fun testQualifiedConstructorCall() = doTest("QualifiedConstructorCall")
|
||||||
|
|
||||||
@Test fun testPropertyDelegate() = doTest("PropertyDelegate")
|
@Test fun testPropertyDelegate() = doTest("PropertyDelegate")
|
||||||
|
|
||||||
|
@Test fun testPropertyWithAnnotation() = doTest("PropertyWithAnnotation")
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user