Uast: AbstractKotlinUVariable annotations now are retrieved from Kotlin Psi, not from compiled (KT-21025)
and `KotlinNullabilityUAnnotation` now is created for every `AbstractKotlinUVariable`
This commit is contained in:
committed by
Nikolay Krasko
parent
f0723a5c07
commit
260c549cd7
@@ -17,12 +17,14 @@
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||
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.containingClassOrObject
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isPropertyParameter
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kotlin.expressions.KotlinUElvisExpression
|
||||
@@ -51,6 +53,15 @@ abstract class KotlinAbstractUElement(private val givenParent: UElement?) : UEle
|
||||
parent = (parentUnwrapped as? KtProperty)?.setter
|
||||
?: (parentUnwrapped as? KtParameter)?.toLightSetter()
|
||||
?: parent
|
||||
AnnotationUseSiteTarget.FIELD ->
|
||||
parent = (parentUnwrapped as? KtProperty)
|
||||
?: (parentUnwrapped as? KtParameter)
|
||||
?.takeIf { it.isPropertyParameter() }
|
||||
?.let(LightClassUtil::getLightClassBackingField)
|
||||
?: parent
|
||||
AnnotationUseSiteTarget.SETTER_PARAMETER ->
|
||||
parent = (parentUnwrapped as? KtParameter)
|
||||
?.toLightSetter()?.parameterList?.parameters?.firstOrNull() ?: parent
|
||||
}
|
||||
}
|
||||
if (psi is UastKotlinPsiVariable && parent != null) {
|
||||
|
||||
@@ -17,19 +17,26 @@
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import org.jetbrains.kotlin.types.typeUtil.nullability
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.java.JavaAbstractUExpression
|
||||
import org.jetbrains.uast.java.JavaUAnnotation
|
||||
import org.jetbrains.uast.java.annotations
|
||||
import org.jetbrains.uast.kotlin.declarations.UastLightIdentifier
|
||||
import org.jetbrains.uast.kotlin.internal.KotlinUElementWithComments
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
import org.jetbrains.uast.visitor.UastTypedVisitor
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
abstract class AbstractKotlinUVariable(givenParent: UElement?)
|
||||
@@ -72,7 +79,19 @@ abstract class AbstractKotlinUVariable(givenParent: UElement?)
|
||||
|
||||
override fun getContainingFile(): PsiFile = unwrapFakeFileForLightClass(psi.containingFile)
|
||||
|
||||
override val annotations: List<UAnnotation> by lz { psi.annotations.map { WrappedUAnnotation(it, this) } }
|
||||
override val annotations by lz {
|
||||
val sourcePsi = sourcePsi ?: return@lz psi.annotations.map { WrappedUAnnotation(it, this) }
|
||||
val annotations = SmartList<UAnnotation>(KotlinNullabilityUAnnotation(sourcePsi, this))
|
||||
if (sourcePsi is KtModifierListOwner) {
|
||||
sourcePsi.annotationEntries.
|
||||
filter { acceptsAnnotationTarget(it.useSiteTarget?.getAnnotationUseSiteTarget()) }.
|
||||
mapTo(annotations) { KotlinUAnnotation(it, this) }
|
||||
}
|
||||
annotations
|
||||
}
|
||||
|
||||
|
||||
abstract protected fun acceptsAnnotationTarget(target: AnnotationUseSiteTarget?): Boolean
|
||||
|
||||
override val typeReference by lz { getLanguagePlugin().convertOpt<UTypeReferenceExpression>(psi.typeElement, this) }
|
||||
|
||||
@@ -122,6 +141,8 @@ class KotlinUVariable(
|
||||
|
||||
override val typeReference by lz { getLanguagePlugin().convertOpt<UTypeReferenceExpression>(psi.typeElement, this) }
|
||||
|
||||
override fun acceptsAnnotationTarget(target: AnnotationUseSiteTarget?): Boolean = true
|
||||
|
||||
override fun getInitializer(): PsiExpression? {
|
||||
return super<AbstractKotlinUVariable>.getInitializer()
|
||||
}
|
||||
@@ -142,14 +163,28 @@ class KotlinUVariable(
|
||||
|
||||
open class KotlinUParameter(
|
||||
psi: PsiParameter,
|
||||
override val sourcePsi: KtElement?,
|
||||
final override val sourcePsi: KtElement?,
|
||||
givenParent: UElement?
|
||||
) : AbstractKotlinUVariable(givenParent), UParameter, PsiParameter by psi {
|
||||
|
||||
override val javaPsi = unwrap<UParameter, PsiParameter>(psi)
|
||||
final override val javaPsi = unwrap<UParameter, PsiParameter>(psi)
|
||||
|
||||
override val psi = javaPsi
|
||||
|
||||
private val isLightConstructorParam by lz { psi.getParentOfType<PsiMethod>(true)?.isConstructor }
|
||||
|
||||
private val isKtConstructorParam by lz { sourcePsi?.getParentOfType<KtCallableDeclaration>(true)?.let { it is KtConstructor<*> } }
|
||||
|
||||
override fun acceptsAnnotationTarget(target: AnnotationUseSiteTarget?): Boolean {
|
||||
if (sourcePsi !is KtParameter) return false
|
||||
if (isKtConstructorParam == isLightConstructorParam && target == null) return true
|
||||
when (target) {
|
||||
AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER -> return isLightConstructorParam == true
|
||||
AnnotationUseSiteTarget.SETTER_PARAMETER -> return isLightConstructorParam != true
|
||||
else -> return false
|
||||
}
|
||||
}
|
||||
|
||||
override fun getInitializer(): PsiExpression? {
|
||||
return super<AbstractKotlinUVariable>.getInitializer()
|
||||
}
|
||||
@@ -167,6 +202,51 @@ open class KotlinUParameter(
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinNullabilityUAnnotation(val annotatedElement: PsiElement, override val uastParent: UElement) : UAnnotation, JvmDeclarationUElement {
|
||||
|
||||
private fun getTargetType(annotatedElement: PsiElement): KotlinType? {
|
||||
if (annotatedElement is KtCallableDeclaration) {
|
||||
annotatedElement.typeReference?.getType()?.let { return it }
|
||||
}
|
||||
if (annotatedElement is KtProperty) {
|
||||
annotatedElement.initializer?.let { it.getType(it.analyze()) }?.let { return it }
|
||||
annotatedElement.delegateExpression?.let { it.getType(it.analyze())?.arguments?.firstOrNull()?.type }?.let { return it }
|
||||
}
|
||||
annotatedElement.getParentOfType<KtProperty>(false)?.let {
|
||||
it.typeReference?.getType() ?: it.initializer?.let { it.getType(it.analyze()) }
|
||||
}?.let { return it }
|
||||
return null
|
||||
}
|
||||
|
||||
val nullability by lz { getTargetType(annotatedElement)?.nullability() }
|
||||
|
||||
override val attributeValues: List<UNamedExpression>
|
||||
get() = emptyList()
|
||||
override val psi: PsiElement?
|
||||
get() = null
|
||||
override val javaPsi: PsiElement?
|
||||
get() = null
|
||||
override val sourcePsi: PsiElement?
|
||||
get() = null
|
||||
override val qualifiedName: String?
|
||||
get() = when (nullability) {
|
||||
TypeNullability.NOT_NULL -> NotNull::class.qualifiedName
|
||||
TypeNullability.NULLABLE -> Nullable::class.qualifiedName
|
||||
TypeNullability.FLEXIBLE -> null
|
||||
null -> null
|
||||
}
|
||||
|
||||
override fun findAttributeValue(name: String?): UExpression? = null
|
||||
|
||||
override fun findDeclaredAttributeValue(name: String?): UExpression? = null
|
||||
|
||||
override fun resolve(): PsiClass? = qualifiedName?.let {
|
||||
val project = annotatedElement.project
|
||||
JavaPsiFacade.getInstance(project).findClass(it, GlobalSearchScope.allScope(project))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
open class KotlinUField(
|
||||
psi: PsiField,
|
||||
override val sourcePsi: KtElement?,
|
||||
@@ -177,6 +257,11 @@ open class KotlinUField(
|
||||
|
||||
override val psi = javaPsi
|
||||
|
||||
override fun acceptsAnnotationTarget(target: AnnotationUseSiteTarget?): Boolean =
|
||||
target == AnnotationUseSiteTarget.FIELD ||
|
||||
target == AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD ||
|
||||
(sourcePsi is KtProperty) && (target == null || target == AnnotationUseSiteTarget.PROPERTY)
|
||||
|
||||
override fun getInitializer(): PsiExpression? {
|
||||
return super<AbstractKotlinUVariable>.getInitializer()
|
||||
}
|
||||
@@ -214,6 +299,8 @@ open class KotlinULocalVariable(
|
||||
|
||||
override val javaPsi = unwrap<ULocalVariable, PsiLocalVariable>(psi)
|
||||
|
||||
override fun acceptsAnnotationTarget(target: AnnotationUseSiteTarget?): Boolean = true
|
||||
|
||||
override val psi = javaPsi
|
||||
|
||||
override fun getInitializer(): PsiExpression? {
|
||||
@@ -267,6 +354,8 @@ open class KotlinUEnumConstant(
|
||||
|
||||
override val psi = javaPsi
|
||||
|
||||
override fun acceptsAnnotationTarget(target: AnnotationUseSiteTarget?): Boolean = true
|
||||
|
||||
override fun getContainingFile(): PsiFile {
|
||||
return super.getContainingFile()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ UFile (package = )
|
||||
UClass (name = DefaultParameterValuesKt)
|
||||
UAnnotationMethod (name = foo)
|
||||
UParameter (name = a)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
ULiteralExpression (value = 1)
|
||||
UParameter (name = foo)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
public final class DefaultParameterValuesKt {
|
||||
public static final fun foo(@null a: int, @org.jetbrains.annotations.Nullable foo: java.lang.String) : void {
|
||||
public static final fun foo(@org.jetbrains.annotations.NotNull a: int, @org.jetbrains.annotations.Nullable foo: java.lang.String) : void {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,19 @@ UFile (package = )
|
||||
UBlockExpression
|
||||
UDeclarationsExpression
|
||||
ULocalVariable (name = var268d4034)
|
||||
UAnnotation (fqName = null)
|
||||
UBinaryExpression (operator = <other>)
|
||||
ULiteralExpression (value = "foo")
|
||||
ULiteralExpression (value = 1)
|
||||
ULocalVariable (name = a)
|
||||
UAnnotation (fqName = null)
|
||||
UQualifiedReferenceExpression
|
||||
USimpleNameReferenceExpression (identifier = var268d4034)
|
||||
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
|
||||
UIdentifier (Identifier (component1))
|
||||
USimpleNameReferenceExpression (identifier = <anonymous class>)
|
||||
ULocalVariable (name = b)
|
||||
UAnnotation (fqName = null)
|
||||
UQualifiedReferenceExpression
|
||||
USimpleNameReferenceExpression (identifier = var268d4034)
|
||||
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
public final class DestructuringDeclarationKt {
|
||||
public static final fun foo() : void {
|
||||
var var268d4034: <ErrorType> = "foo" <other> 1
|
||||
var a: java.lang.String = var268d4034.<anonymous class>()
|
||||
var b: int = var268d4034.<anonymous class>()
|
||||
@null var var268d4034: <ErrorType> = "foo" <other> 1
|
||||
@null var a: java.lang.String = var268d4034.<anonymous class>()
|
||||
@null var b: int = var268d4034.<anonymous class>()
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -12,9 +12,11 @@ UFile (package = )
|
||||
UExpressionList (elvis)
|
||||
UDeclarationsExpression
|
||||
ULocalVariable (name = var243c51a0)
|
||||
UAnnotation (fqName = null)
|
||||
UExpressionList (elvis)
|
||||
UDeclarationsExpression
|
||||
ULocalVariable (name = varc4aef569)
|
||||
UAnnotation (fqName = null)
|
||||
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
|
||||
UIdentifier (Identifier (foo))
|
||||
USimpleNameReferenceExpression (identifier = foo)
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ public final class ElvisKt {
|
||||
public static final fun bar() : int = 42
|
||||
public static final fun baz() : java.lang.String {
|
||||
return elvis {
|
||||
var var243c51a0: java.lang.String = elvis {
|
||||
var varc4aef569: java.lang.String = foo("Lorem ipsum")
|
||||
@null var var243c51a0: java.lang.String = elvis {
|
||||
@null var varc4aef569: java.lang.String = foo("Lorem ipsum")
|
||||
if (varc4aef569 != null) varc4aef569 else foo("dolor sit amet")
|
||||
}
|
||||
if (var243c51a0 != null) var243c51a0 else bar().toString()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
UFile (package = )
|
||||
UClass (name = Style)
|
||||
UEnumConstant (name = SHEET)
|
||||
UAnnotation (fqName = null)
|
||||
USimpleNameReferenceExpression (identifier = Style)
|
||||
UClass (name = null)
|
||||
UAnnotationMethod (name = getExitAnimation)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
public enum Style {
|
||||
SHEET {
|
||||
@null SHEET {
|
||||
public fun getExitAnimation() : java.lang.String = "bar"
|
||||
fun SHEET() = UastEmptyExpression
|
||||
}
|
||||
|
||||
+4
-4
@@ -3,9 +3,9 @@ UFile (package = )
|
||||
UAnnotationMethod (name = Foo)
|
||||
UClass (name = Bar)
|
||||
UField (name = a)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UField (name = b)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotationMethod (name = getAPlusB)
|
||||
UBinaryExpression (operator = +)
|
||||
USimpleNameReferenceExpression (identifier = a)
|
||||
@@ -14,9 +14,9 @@ UFile (package = )
|
||||
UAnnotationMethod (name = getB)
|
||||
UAnnotationMethod (name = Bar)
|
||||
UParameter (name = a)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UParameter (name = b)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UClass (name = Baz)
|
||||
UAnnotationMethod (name = doNothing)
|
||||
USimpleNameReferenceExpression (identifier = Unit)
|
||||
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
public final class Foo {
|
||||
public fun Foo() = UastEmptyExpression
|
||||
public static final class Bar {
|
||||
@null private final var a: int
|
||||
@null private final var b: int
|
||||
@org.jetbrains.annotations.NotNull private final var a: int
|
||||
@org.jetbrains.annotations.NotNull private final var b: int
|
||||
public final fun getAPlusB() : int = a + b
|
||||
public final fun getA() : int = UastEmptyExpression
|
||||
public final fun getB() : int = UastEmptyExpression
|
||||
public fun Bar(@null a: int, @null b: int) = UastEmptyExpression
|
||||
public fun Bar(@org.jetbrains.annotations.NotNull a: int, @org.jetbrains.annotations.NotNull b: int) = UastEmptyExpression
|
||||
public static final class Baz {
|
||||
public final fun doNothing() : void = Unit
|
||||
public fun Baz() = UastEmptyExpression
|
||||
|
||||
@@ -22,6 +22,7 @@ UFile (package = )
|
||||
UVariable (name = someLocalFun)
|
||||
ULambdaExpression
|
||||
UParameter (name = text)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
ULiteralExpression (value = 42)
|
||||
UReturnExpression
|
||||
UBinaryExpression (operator = ==)
|
||||
|
||||
@@ -9,7 +9,7 @@ public final class LocalDeclarationsKt {
|
||||
var baz: kotlin.jvm.functions.Function0<? extends kotlin.Unit> = fun () {
|
||||
<init>()
|
||||
}
|
||||
var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (var text: java.lang.String) {
|
||||
var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) {
|
||||
42
|
||||
}
|
||||
return bar() == <init>()
|
||||
|
||||
@@ -18,10 +18,11 @@ UFile (package = ) [public final class LocalDeclarationsKt {...]
|
||||
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [<init>()] : PsiType:<ErrorType>
|
||||
UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))]
|
||||
USimpleNameReferenceExpression (identifier = <init>) [<init>] : PsiType:<ErrorType>
|
||||
UDeclarationsExpression [var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (var text: java.lang.String) {...}]
|
||||
UVariable (name = someLocalFun) [var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (var text: java.lang.String) {...}]
|
||||
ULambdaExpression [fun (var text: java.lang.String) {...}]
|
||||
UParameter (name = text) [var text: java.lang.String]
|
||||
UDeclarationsExpression [var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) {...}]
|
||||
UVariable (name = someLocalFun) [var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) {...}]
|
||||
ULambdaExpression [fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) {...}]
|
||||
UParameter (name = text) [@org.jetbrains.annotations.NotNull var text: java.lang.String]
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
|
||||
ULiteralExpression (value = 42) [42] : PsiType:int
|
||||
UReturnExpression [return bar() == <init>()] : PsiType:Void
|
||||
UBinaryExpression (operator = ==) [bar() == <init>()] : PsiType:boolean
|
||||
|
||||
@@ -18,10 +18,11 @@ UFile (package = ) [public final class LocalDeclarationsKt {...]
|
||||
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [<init>()] = external <init>()()
|
||||
UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))]
|
||||
USimpleNameReferenceExpression (identifier = <init>) [<init>] = external <init>()()
|
||||
UDeclarationsExpression [var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (var text: java.lang.String) {...}] = Undetermined
|
||||
UVariable (name = someLocalFun) [var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (var text: java.lang.String) {...}]
|
||||
ULambdaExpression [fun (var text: java.lang.String) {...}] = Undetermined
|
||||
UParameter (name = text) [var text: java.lang.String]
|
||||
UDeclarationsExpression [var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) {...}] = Undetermined
|
||||
UVariable (name = someLocalFun) [var someLocalFun: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.String,? extends java.lang.Integer> = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) {...}]
|
||||
ULambdaExpression [fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) {...}] = Undetermined
|
||||
UParameter (name = text) [@org.jetbrains.annotations.NotNull var text: java.lang.String]
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
|
||||
ULiteralExpression (value = 42) [42] = 42
|
||||
UReturnExpression [return bar() == <init>()] = Nothing
|
||||
UBinaryExpression (operator = ==) [bar() == <init>()] = Undetermined
|
||||
|
||||
@@ -6,26 +6,26 @@ UFile (package = )
|
||||
UClass (name = MyAnnotation5)
|
||||
UClass (name = Test1)
|
||||
UField (name = bar)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotationMethod (name = getBar)
|
||||
UAnnotationMethod (name = setBar)
|
||||
UParameter (name = p)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotationMethod (name = Test1)
|
||||
UParameter (name = bar)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotation (fqName = MyAnnotation)
|
||||
UAnnotation (fqName = null)
|
||||
UClass (name = Test2)
|
||||
UField (name = bar)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotation (fqName = MyAnnotation5)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotationMethod (name = getBar)
|
||||
UAnnotation (fqName = MyAnnotation)
|
||||
UAnnotationMethod (name = setBar)
|
||||
UAnnotation (fqName = MyAnnotation2)
|
||||
UParameter (name = p)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotation (fqName = MyAnnotation3)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotationMethod (name = Test2)
|
||||
UParameter (name = bar)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
|
||||
@@ -14,17 +14,17 @@ public abstract annotation MyAnnotation5 {
|
||||
}
|
||||
|
||||
public final class Test1 {
|
||||
@null private var bar: int
|
||||
@org.jetbrains.annotations.NotNull private var bar: int
|
||||
public final fun getBar() : int = UastEmptyExpression
|
||||
public final fun setBar(@null p: int) : void = UastEmptyExpression
|
||||
public fun Test1(@MyAnnotation @null bar: int) = UastEmptyExpression
|
||||
public final fun setBar(@org.jetbrains.annotations.NotNull p: int) : void = UastEmptyExpression
|
||||
public fun Test1(@org.jetbrains.annotations.NotNull @MyAnnotation bar: int) = UastEmptyExpression
|
||||
}
|
||||
|
||||
public final class Test2 {
|
||||
@MyAnnotation5 @null private var bar: int
|
||||
@org.jetbrains.annotations.NotNull @MyAnnotation5 private var bar: int
|
||||
@MyAnnotation
|
||||
public final fun getBar() : int = UastEmptyExpression
|
||||
@MyAnnotation2
|
||||
public final fun setBar(@MyAnnotation3 @null p: int) : void = UastEmptyExpression
|
||||
public fun Test2(@null bar: int) = UastEmptyExpression
|
||||
public final fun setBar(@org.jetbrains.annotations.NotNull @MyAnnotation3 p: int) : void = UastEmptyExpression
|
||||
public fun Test2(@org.jetbrains.annotations.NotNull bar: int) = UastEmptyExpression
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ UFile (package = )
|
||||
UClass (name = ParametersWithDefaultValuesKt)
|
||||
UAnnotationMethod (name = foo)
|
||||
UParameter (name = a)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UParameter (name = b)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UParameter (name = c)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
ULiteralExpression (value = 0)
|
||||
UParameter (name = flag)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
ULiteralExpression (value = false)
|
||||
UBlockExpression
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
public final class ParametersWithDefaultValuesKt {
|
||||
public static final fun foo(@null a: int, @org.jetbrains.annotations.NotNull b: java.lang.String, @null c: int, @null flag: boolean) : void {
|
||||
public static final fun foo(@org.jetbrains.annotations.NotNull a: int, @org.jetbrains.annotations.NotNull b: java.lang.String, @org.jetbrains.annotations.NotNull c: int, @org.jetbrains.annotations.NotNull flag: boolean) : void {
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -2,4 +2,7 @@ val sdCardPath by lazy { "/sdcard" }
|
||||
|
||||
fun localPropertyTest() {
|
||||
val sdCardPathLocal by lazy { "/sdcard" }
|
||||
}
|
||||
}
|
||||
|
||||
@delegate:Suppress
|
||||
val annotatedDelegate by lazy { 1 + 1 }
|
||||
@@ -8,6 +8,17 @@ UFile (package = )
|
||||
ULambdaExpression
|
||||
UBlockExpression
|
||||
ULiteralExpression (value = "/sdcard")
|
||||
UField (name = annotatedDelegate$delegate)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotation (fqName = kotlin.Suppress)
|
||||
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
|
||||
UIdentifier (Identifier (lazy))
|
||||
USimpleNameReferenceExpression (identifier = lazy)
|
||||
ULambdaExpression
|
||||
UBlockExpression
|
||||
UBinaryExpression (operator = +)
|
||||
ULiteralExpression (value = 1)
|
||||
ULiteralExpression (value = 1)
|
||||
UAnnotationMethod (name = getSdCardPath)
|
||||
UAnnotationMethod (name = localPropertyTest)
|
||||
UBlockExpression
|
||||
@@ -19,3 +30,4 @@ UFile (package = )
|
||||
ULambdaExpression
|
||||
UBlockExpression
|
||||
ULiteralExpression (value = "/sdcard")
|
||||
UAnnotationMethod (name = getAnnotatedDelegate)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
public final class PropertyDelegateKt {
|
||||
@org.jetbrains.annotations.NotNull private static final var sdCardPath$delegate: kotlin.Lazy
|
||||
@org.jetbrains.annotations.NotNull @kotlin.Suppress private static final var annotatedDelegate$delegate: kotlin.Lazy
|
||||
public static final fun getSdCardPath() : java.lang.String = UastEmptyExpression
|
||||
public static final fun localPropertyTest() : void {
|
||||
var sdCardPathLocal: java.lang.String
|
||||
}
|
||||
public static final fun getAnnotatedDelegate() : int = UastEmptyExpression
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
UFile (package = )
|
||||
UClass (name = PropertyWithAnnotationKt)
|
||||
UField (name = prop1)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotation (fqName = TestAnnotation)
|
||||
ULiteralExpression (value = 0)
|
||||
UField (name = prop3)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
ULiteralExpression (value = 0)
|
||||
UAnnotationMethod (name = getProp1)
|
||||
UAnnotationMethod (name = getProp2)
|
||||
@@ -15,7 +16,7 @@ UFile (package = )
|
||||
UAnnotationMethod (name = setProp3)
|
||||
UAnnotation (fqName = TestAnnotation)
|
||||
UParameter (name = value)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UBlockExpression
|
||||
UBinaryExpression (operator = =)
|
||||
USimpleNameReferenceExpression (identifier = field)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
public final class PropertyWithAnnotationKt {
|
||||
@null private static final var prop1: int = 0
|
||||
@null private static var prop3: int = 0
|
||||
@org.jetbrains.annotations.NotNull @TestAnnotation private static final var prop1: int = 0
|
||||
@org.jetbrains.annotations.NotNull 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(@null value: int) : void {
|
||||
public static final fun setProp3(@org.jetbrains.annotations.NotNull value: int) : void {
|
||||
field = value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class SimpleAnnotated {
|
||||
@Suppress("abc")
|
||||
fun method() {
|
||||
println("Hello, world!")
|
||||
}
|
||||
|
||||
@SinceKotlin("1.0")
|
||||
val property: String = "Mary"
|
||||
}
|
||||
+4
-4
@@ -2,7 +2,7 @@ UFile (package = )
|
||||
UClass (name = SimpleScript)
|
||||
UAnnotationMethod (name = getBarOrNull)
|
||||
UParameter (name = flag)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UBlockExpression
|
||||
UReturnExpression
|
||||
UIfExpression
|
||||
@@ -30,10 +30,10 @@ UFile (package = )
|
||||
ULiteralExpression (value = "Goodbye World!")
|
||||
UClass (name = Bar)
|
||||
UField (name = b)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
ULiteralExpression (value = 0)
|
||||
UField (name = a)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotationMethod (name = getB)
|
||||
UAnnotationMethod (name = getAPlusB)
|
||||
UBinaryExpression (operator = +)
|
||||
@@ -42,7 +42,7 @@ UFile (package = )
|
||||
UAnnotationMethod (name = getA)
|
||||
UAnnotationMethod (name = Bar)
|
||||
UParameter (name = a)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UClass (name = Baz)
|
||||
UAnnotationMethod (name = doSomething)
|
||||
UBlockExpression
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
public class SimpleScript : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public final fun getBarOrNull(@null flag: boolean) : SimpleScript.Bar {
|
||||
public final fun getBarOrNull(@org.jetbrains.annotations.NotNull flag: boolean) : SimpleScript.Bar {
|
||||
return if (flag) <init>(42) else null
|
||||
}
|
||||
public fun SimpleScript(@null p: java.lang.String[]) {
|
||||
@@ -8,12 +8,12 @@ public class SimpleScript : kotlin.script.templates.standard.ScriptTemplateWithA
|
||||
println("Goodbye World!")
|
||||
}
|
||||
public static final class Bar {
|
||||
@null private final var b: int = 0
|
||||
@null private final var a: int
|
||||
@org.jetbrains.annotations.NotNull private final var b: int = 0
|
||||
@org.jetbrains.annotations.NotNull private final var a: int
|
||||
public final fun getB() : int = UastEmptyExpression
|
||||
public final fun getAPlusB() : int = a + b
|
||||
public final fun getA() : int = UastEmptyExpression
|
||||
public fun Bar(@null a: int) = UastEmptyExpression
|
||||
public fun Bar(@org.jetbrains.annotations.NotNull a: int) = UastEmptyExpression
|
||||
public static final class Baz {
|
||||
public final fun doSomething() : void {
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ UFile (package = )
|
||||
UAnnotationMethod (name = getLiteralInLiteral2)
|
||||
UAnnotationMethod (name = simpleForTemplate)
|
||||
UParameter (name = i)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
ULiteralExpression (value = 0)
|
||||
USimpleNameReferenceExpression (identifier = i)
|
||||
UAnnotationMethod (name = foo)
|
||||
|
||||
@@ -9,7 +9,7 @@ public final class StringTemplateComplexKt {
|
||||
public static final fun getCase5() : java.lang.String = UastEmptyExpression
|
||||
public static final fun getLiteralInLiteral() : java.lang.String = UastEmptyExpression
|
||||
public static final fun getLiteralInLiteral2() : java.lang.String = UastEmptyExpression
|
||||
public static final fun simpleForTemplate(@null i: int) : java.lang.String = i
|
||||
public static final fun simpleForTemplate(@org.jetbrains.annotations.NotNull i: int) : java.lang.String = i
|
||||
public static final fun foo() : void {
|
||||
println(baz)
|
||||
var template1: java.lang.String = simpleForTemplate()
|
||||
|
||||
+5
-5
@@ -17,7 +17,7 @@ UFile (package = )
|
||||
UAnnotationMethod (name = SuperCallsKt$anon$1)
|
||||
UClass (name = innerObject)
|
||||
UField (name = INSTANCE)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotationMethod (name = innerObject)
|
||||
UBlockExpression
|
||||
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1))
|
||||
@@ -41,7 +41,7 @@ UFile (package = )
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotationMethod (name = foo)
|
||||
UParameter (name = a)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UBlockExpression
|
||||
UAnnotationMethod (name = getStr)
|
||||
UAnnotationMethod (name = A)
|
||||
@@ -49,7 +49,7 @@ UFile (package = )
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UAnnotationMethod (name = A)
|
||||
UParameter (name = i)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UBlockExpression
|
||||
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1))
|
||||
UIdentifier (Identifier (this))
|
||||
@@ -71,7 +71,7 @@ UFile (package = )
|
||||
UClass (name = C)
|
||||
UAnnotationMethod (name = foo)
|
||||
UParameter (name = a)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UBlockExpression
|
||||
UQualifiedReferenceExpression
|
||||
USuperExpression (label = null)
|
||||
@@ -89,7 +89,7 @@ UFile (package = )
|
||||
USimpleNameReferenceExpression (identifier = p)
|
||||
UAnnotationMethod (name = C)
|
||||
UParameter (name = i)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
UBlockExpression
|
||||
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 1))
|
||||
UIdentifier (Identifier (super))
|
||||
|
||||
+4
-4
@@ -15,11 +15,11 @@ public final class SuperCallsKt {
|
||||
|
||||
public class A {
|
||||
@org.jetbrains.annotations.NotNull private final var str: java.lang.String
|
||||
public fun foo(@null a: long) : void {
|
||||
public fun foo(@org.jetbrains.annotations.NotNull a: long) : void {
|
||||
}
|
||||
public final fun getStr() : java.lang.String = UastEmptyExpression
|
||||
public fun A(@org.jetbrains.annotations.NotNull str: java.lang.String) = UastEmptyExpression
|
||||
public fun A(@null i: int) {
|
||||
public fun A(@org.jetbrains.annotations.NotNull i: int) {
|
||||
<init>(i.toString())
|
||||
}
|
||||
}
|
||||
@@ -31,13 +31,13 @@ public final class B : A {
|
||||
}
|
||||
|
||||
public final class C : A {
|
||||
public fun foo(@null a: long) : void {
|
||||
public fun foo(@org.jetbrains.annotations.NotNull a: long) : void {
|
||||
super.foo(a)
|
||||
}
|
||||
public fun C(@org.jetbrains.annotations.NotNull p: java.lang.String) {
|
||||
<init>(p)
|
||||
}
|
||||
public fun C(@null i: int) {
|
||||
public fun C(@org.jetbrains.annotations.NotNull i: int) {
|
||||
<init>(i)
|
||||
println()
|
||||
}
|
||||
|
||||
@@ -24,14 +24,17 @@ UFile (package = )
|
||||
UExpressionList (when_entry)
|
||||
UDeclarationsExpression
|
||||
ULocalVariable (name = var837f1e82)
|
||||
UAnnotation (fqName = null)
|
||||
USimpleNameReferenceExpression (identifier = arr)
|
||||
ULocalVariable (name = bindingContext)
|
||||
UAnnotation (fqName = null)
|
||||
UQualifiedReferenceExpression
|
||||
USimpleNameReferenceExpression (identifier = var837f1e82)
|
||||
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
|
||||
UIdentifier (Identifier (component1))
|
||||
USimpleNameReferenceExpression (identifier = <anonymous class>)
|
||||
ULocalVariable (name = statementFilter)
|
||||
UAnnotation (fqName = null)
|
||||
UQualifiedReferenceExpression
|
||||
USimpleNameReferenceExpression (identifier = var837f1e82)
|
||||
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
|
||||
|
||||
@@ -8,9 +8,9 @@ public final class WhenAndDestructingKt {
|
||||
}
|
||||
|
||||
-> {
|
||||
var var837f1e82: <ErrorType> = arr
|
||||
var bindingContext: java.lang.String = var837f1e82.<anonymous class>()
|
||||
var statementFilter: java.lang.String = var837f1e82.<anonymous class>()
|
||||
@null var var837f1e82: <ErrorType> = arr
|
||||
@null var bindingContext: java.lang.String = var837f1e82.<anonymous class>()
|
||||
@null var statementFilter: java.lang.String = var837f1e82.<anonymous class>()
|
||||
return bindingContext
|
||||
break
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ UFile (package = )
|
||||
UIdentifier (Identifier (readLine))
|
||||
USimpleNameReferenceExpression (identifier = readLine)
|
||||
UField (name = b)
|
||||
UAnnotation (fqName = null)
|
||||
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||
USwitchExpression
|
||||
USimpleNameReferenceExpression (identifier = a)
|
||||
UExpressionList (when)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
public final class WhenStringLiteralKt {
|
||||
@org.jetbrains.annotations.Nullable private static final var a: java.lang.String = readLine()
|
||||
@null private static final var b: int = switch (a) {
|
||||
@org.jetbrains.annotations.NotNull private static final var b: int = switch (a) {
|
||||
"abc" -> {
|
||||
1
|
||||
break
|
||||
|
||||
@@ -217,4 +217,16 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleAnnotated() {
|
||||
doTest("SimpleAnnotated") { _, file ->
|
||||
file.findElementByTextFromPsi<UField>("@SinceKotlin(\"1.0\")\n val property: String = \"Mary\"").let { field ->
|
||||
val annotation = field.annotations.assertedFind("kotlin.SinceKotlin") { it.qualifiedName }
|
||||
Assert.assertEquals(annotation.findDeclaredAttributeValue("version")?.evaluateString(), "1.0")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <T, R> Iterable<T>.assertedFind(value: R, transform: (T) -> R): T = find { transform(it) == value } ?: throw AssertionError("'$value' not found, only ${this.joinToString { transform(it).toString() }}")
|
||||
|
||||
Reference in New Issue
Block a user