From 260c549cd760bc1fd32fe351bccf159388d258e7 Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Sun, 15 Oct 2017 15:17:15 +0300 Subject: [PATCH] Uast: `AbstractKotlinUVariable` annotations now are retrieved from Kotlin Psi, not from compiled (KT-21025) and `KotlinNullabilityUAnnotation` now is created for every `AbstractKotlinUVariable` --- .../uast/kotlin/KotlinAbstractUElement.kt | 11 ++ .../kotlin/declarations/KotlinUVariable.kt | 101 ++++++++++++++++-- .../testData/DefaultParameterValues.log.txt | 2 +- .../DefaultParameterValues.render.txt | 2 +- .../testData/DestructuringDeclaration.log.txt | 3 + .../DestructuringDeclaration.render.txt | 6 +- plugins/uast-kotlin/testData/Elvis.log.txt | 2 + plugins/uast-kotlin/testData/Elvis.render.txt | 4 +- .../testData/EnumValueMembers.log.txt | 1 + .../testData/EnumValueMembers.render.txt | 2 +- .../uast-kotlin/testData/InnerClasses.log.txt | 8 +- .../testData/InnerClasses.render.txt | 6 +- .../testData/LocalDeclarations.log.txt | 1 + .../testData/LocalDeclarations.render.txt | 2 +- .../testData/LocalDeclarations.types.txt | 9 +- .../testData/LocalDeclarations.values.txt | 9 +- .../ParameterPropertyWithAnnotation.log.txt | 12 +-- ...ParameterPropertyWithAnnotation.render.txt | 12 +-- .../ParametersWithDefaultValues.log.txt | 6 +- .../ParametersWithDefaultValues.render.txt | 2 +- .../uast-kotlin/testData/PropertyDelegate.kt | 5 +- .../testData/PropertyDelegate.log.txt | 12 +++ .../testData/PropertyDelegate.render.txt | 2 + .../testData/PropertyWithAnnotation.log.txt | 7 +- .../PropertyWithAnnotation.render.txt | 6 +- .../uast-kotlin/testData/SimpleAnnotated.kt | 9 ++ .../uast-kotlin/testData/SimpleScript.log.txt | 8 +- .../testData/SimpleScript.render.txt | 8 +- .../testData/StringTemplateComplex.log.txt | 2 +- .../testData/StringTemplateComplex.render.txt | 2 +- .../uast-kotlin/testData/SuperCalls.log.txt | 10 +- .../testData/SuperCalls.render.txt | 8 +- .../testData/WhenAndDestructing.log.txt | 3 + .../testData/WhenAndDestructing.render.txt | 6 +- .../testData/WhenStringLiteral.log.txt | 2 +- .../testData/WhenStringLiteral.render.txt | 2 +- .../uast-kotlin/tests/KotlinUastApiTest.kt | 12 +++ 37 files changed, 228 insertions(+), 77 deletions(-) create mode 100644 plugins/uast-kotlin/testData/SimpleAnnotated.kt 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 124dc4805cf..7e6d0f35f97 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinAbstractUElement.kt @@ -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) { diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt index 69b0d6afb1c..7e283f487ea 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUVariable.kt @@ -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 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(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(psi.typeElement, this) } @@ -122,6 +141,8 @@ class KotlinUVariable( override val typeReference by lz { getLanguagePlugin().convertOpt(psi.typeElement, this) } + override fun acceptsAnnotationTarget(target: AnnotationUseSiteTarget?): Boolean = true + override fun getInitializer(): PsiExpression? { return super.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(psi) + final override val javaPsi = unwrap(psi) override val psi = javaPsi + private val isLightConstructorParam by lz { psi.getParentOfType(true)?.isConstructor } + + private val isKtConstructorParam by lz { sourcePsi?.getParentOfType(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.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(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 + 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.getInitializer() } @@ -214,6 +299,8 @@ open class KotlinULocalVariable( override val javaPsi = unwrap(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() } diff --git a/plugins/uast-kotlin/testData/DefaultParameterValues.log.txt b/plugins/uast-kotlin/testData/DefaultParameterValues.log.txt index d2f13973781..66766f98fe6 100644 --- a/plugins/uast-kotlin/testData/DefaultParameterValues.log.txt +++ b/plugins/uast-kotlin/testData/DefaultParameterValues.log.txt @@ -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) diff --git a/plugins/uast-kotlin/testData/DefaultParameterValues.render.txt b/plugins/uast-kotlin/testData/DefaultParameterValues.render.txt index 9ce163e3ad2..02a2140841f 100644 --- a/plugins/uast-kotlin/testData/DefaultParameterValues.render.txt +++ b/plugins/uast-kotlin/testData/DefaultParameterValues.render.txt @@ -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 { } } diff --git a/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt b/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt index aa299050640..9cd62857b00 100644 --- a/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt +++ b/plugins/uast-kotlin/testData/DestructuringDeclaration.log.txt @@ -4,16 +4,19 @@ UFile (package = ) UBlockExpression UDeclarationsExpression ULocalVariable (name = var268d4034) + UAnnotation (fqName = null) UBinaryExpression (operator = ) 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 = ) ULocalVariable (name = b) + UAnnotation (fqName = null) UQualifiedReferenceExpression USimpleNameReferenceExpression (identifier = var268d4034) UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) diff --git a/plugins/uast-kotlin/testData/DestructuringDeclaration.render.txt b/plugins/uast-kotlin/testData/DestructuringDeclaration.render.txt index 1517c3ae90e..991072a9502 100644 --- a/plugins/uast-kotlin/testData/DestructuringDeclaration.render.txt +++ b/plugins/uast-kotlin/testData/DestructuringDeclaration.render.txt @@ -1,7 +1,7 @@ public final class DestructuringDeclarationKt { public static final fun foo() : void { - var var268d4034: = "foo" 1 - var a: java.lang.String = var268d4034.() - var b: int = var268d4034.() + @null var var268d4034: = "foo" 1 + @null var a: java.lang.String = var268d4034.() + @null var b: int = var268d4034.() } } diff --git a/plugins/uast-kotlin/testData/Elvis.log.txt b/plugins/uast-kotlin/testData/Elvis.log.txt index ae0dd88b8df..7fc21a02702 100644 --- a/plugins/uast-kotlin/testData/Elvis.log.txt +++ b/plugins/uast-kotlin/testData/Elvis.log.txt @@ -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) diff --git a/plugins/uast-kotlin/testData/Elvis.render.txt b/plugins/uast-kotlin/testData/Elvis.render.txt index 1e60d647063..383bb3799ec 100644 --- a/plugins/uast-kotlin/testData/Elvis.render.txt +++ b/plugins/uast-kotlin/testData/Elvis.render.txt @@ -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() diff --git a/plugins/uast-kotlin/testData/EnumValueMembers.log.txt b/plugins/uast-kotlin/testData/EnumValueMembers.log.txt index ae7d9e2e759..4b8fb5ad913 100644 --- a/plugins/uast-kotlin/testData/EnumValueMembers.log.txt +++ b/plugins/uast-kotlin/testData/EnumValueMembers.log.txt @@ -1,6 +1,7 @@ UFile (package = ) UClass (name = Style) UEnumConstant (name = SHEET) + UAnnotation (fqName = null) USimpleNameReferenceExpression (identifier = Style) UClass (name = null) UAnnotationMethod (name = getExitAnimation) diff --git a/plugins/uast-kotlin/testData/EnumValueMembers.render.txt b/plugins/uast-kotlin/testData/EnumValueMembers.render.txt index 9544478939e..ec6fdb1951f 100644 --- a/plugins/uast-kotlin/testData/EnumValueMembers.render.txt +++ b/plugins/uast-kotlin/testData/EnumValueMembers.render.txt @@ -1,5 +1,5 @@ public enum Style { - SHEET { + @null SHEET { public fun getExitAnimation() : java.lang.String = "bar" fun SHEET() = UastEmptyExpression } diff --git a/plugins/uast-kotlin/testData/InnerClasses.log.txt b/plugins/uast-kotlin/testData/InnerClasses.log.txt index 1c97aa71f89..78be157651f 100644 --- a/plugins/uast-kotlin/testData/InnerClasses.log.txt +++ b/plugins/uast-kotlin/testData/InnerClasses.log.txt @@ -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) diff --git a/plugins/uast-kotlin/testData/InnerClasses.render.txt b/plugins/uast-kotlin/testData/InnerClasses.render.txt index 8d5cfd523a0..b91a0c1ff40 100644 --- a/plugins/uast-kotlin/testData/InnerClasses.render.txt +++ b/plugins/uast-kotlin/testData/InnerClasses.render.txt @@ -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 diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.log.txt b/plugins/uast-kotlin/testData/LocalDeclarations.log.txt index 9dadf83072a..26480d28ca7 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.log.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.log.txt @@ -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 = ==) diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.render.txt b/plugins/uast-kotlin/testData/LocalDeclarations.render.txt index 8768433111f..b287c0bb920 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.render.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.render.txt @@ -9,7 +9,7 @@ public final class LocalDeclarationsKt { var baz: kotlin.jvm.functions.Function0 = fun () { () } - var someLocalFun: kotlin.jvm.functions.Function2 = fun (var text: java.lang.String) { + var someLocalFun: kotlin.jvm.functions.Function2 = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) { 42 } return bar() == () diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.types.txt b/plugins/uast-kotlin/testData/LocalDeclarations.types.txt index 2d879604d74..8310b9965b3 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.types.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.types.txt @@ -18,10 +18,11 @@ UFile (package = ) [public final class LocalDeclarationsKt {...] UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [()] : PsiType: UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))] USimpleNameReferenceExpression (identifier = ) [] : PsiType: - UDeclarationsExpression [var someLocalFun: kotlin.jvm.functions.Function2 = fun (var text: java.lang.String) {...}] - UVariable (name = someLocalFun) [var someLocalFun: kotlin.jvm.functions.Function2 = 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 = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) {...}] + UVariable (name = someLocalFun) [var someLocalFun: kotlin.jvm.functions.Function2 = 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() == ()] : PsiType:Void UBinaryExpression (operator = ==) [bar() == ()] : PsiType:boolean diff --git a/plugins/uast-kotlin/testData/LocalDeclarations.values.txt b/plugins/uast-kotlin/testData/LocalDeclarations.values.txt index d4f166a086e..69f4beabfb2 100644 --- a/plugins/uast-kotlin/testData/LocalDeclarations.values.txt +++ b/plugins/uast-kotlin/testData/LocalDeclarations.values.txt @@ -18,10 +18,11 @@ UFile (package = ) [public final class LocalDeclarationsKt {...] UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) [()] = external ()() UIdentifier (Identifier (Local)) [UIdentifier (Identifier (Local))] USimpleNameReferenceExpression (identifier = ) [] = external ()() - UDeclarationsExpression [var someLocalFun: kotlin.jvm.functions.Function2 = fun (var text: java.lang.String) {...}] = Undetermined - UVariable (name = someLocalFun) [var someLocalFun: kotlin.jvm.functions.Function2 = 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 = fun (@org.jetbrains.annotations.NotNull var text: java.lang.String) {...}] = Undetermined + UVariable (name = someLocalFun) [var someLocalFun: kotlin.jvm.functions.Function2 = 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() == ()] = Nothing UBinaryExpression (operator = ==) [bar() == ()] = Undetermined diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log.txt b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log.txt index 69573a72273..671ec7fa53a 100644 --- a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log.txt +++ b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.log.txt @@ -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) diff --git a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render.txt b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render.txt index efd21da3642..5f93a65c995 100644 --- a/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render.txt +++ b/plugins/uast-kotlin/testData/ParameterPropertyWithAnnotation.render.txt @@ -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 } diff --git a/plugins/uast-kotlin/testData/ParametersWithDefaultValues.log.txt b/plugins/uast-kotlin/testData/ParametersWithDefaultValues.log.txt index 325d638ff65..3c196401c77 100644 --- a/plugins/uast-kotlin/testData/ParametersWithDefaultValues.log.txt +++ b/plugins/uast-kotlin/testData/ParametersWithDefaultValues.log.txt @@ -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 diff --git a/plugins/uast-kotlin/testData/ParametersWithDefaultValues.render.txt b/plugins/uast-kotlin/testData/ParametersWithDefaultValues.render.txt index febae6d0326..c47f8f69528 100644 --- a/plugins/uast-kotlin/testData/ParametersWithDefaultValues.render.txt +++ b/plugins/uast-kotlin/testData/ParametersWithDefaultValues.render.txt @@ -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 { } } diff --git a/plugins/uast-kotlin/testData/PropertyDelegate.kt b/plugins/uast-kotlin/testData/PropertyDelegate.kt index 4cc642ec36f..1d019d904d6 100644 --- a/plugins/uast-kotlin/testData/PropertyDelegate.kt +++ b/plugins/uast-kotlin/testData/PropertyDelegate.kt @@ -2,4 +2,7 @@ val sdCardPath by lazy { "/sdcard" } fun localPropertyTest() { val sdCardPathLocal by lazy { "/sdcard" } -} \ No newline at end of file +} + +@delegate:Suppress +val annotatedDelegate by lazy { 1 + 1 } \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/PropertyDelegate.log.txt b/plugins/uast-kotlin/testData/PropertyDelegate.log.txt index 04df9270c82..39a57572fe6 100644 --- a/plugins/uast-kotlin/testData/PropertyDelegate.log.txt +++ b/plugins/uast-kotlin/testData/PropertyDelegate.log.txt @@ -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) diff --git a/plugins/uast-kotlin/testData/PropertyDelegate.render.txt b/plugins/uast-kotlin/testData/PropertyDelegate.render.txt index d496ac695d7..0f4ec9edd55 100644 --- a/plugins/uast-kotlin/testData/PropertyDelegate.render.txt +++ b/plugins/uast-kotlin/testData/PropertyDelegate.render.txt @@ -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 } diff --git a/plugins/uast-kotlin/testData/PropertyWithAnnotation.log.txt b/plugins/uast-kotlin/testData/PropertyWithAnnotation.log.txt index d4625e3e500..e9c6442768e 100644 --- a/plugins/uast-kotlin/testData/PropertyWithAnnotation.log.txt +++ b/plugins/uast-kotlin/testData/PropertyWithAnnotation.log.txt @@ -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) diff --git a/plugins/uast-kotlin/testData/PropertyWithAnnotation.render.txt b/plugins/uast-kotlin/testData/PropertyWithAnnotation.render.txt index d844e862b87..d299e0a3c06 100644 --- a/plugins/uast-kotlin/testData/PropertyWithAnnotation.render.txt +++ b/plugins/uast-kotlin/testData/PropertyWithAnnotation.render.txt @@ -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 } } diff --git a/plugins/uast-kotlin/testData/SimpleAnnotated.kt b/plugins/uast-kotlin/testData/SimpleAnnotated.kt new file mode 100644 index 00000000000..b0742abd2f4 --- /dev/null +++ b/plugins/uast-kotlin/testData/SimpleAnnotated.kt @@ -0,0 +1,9 @@ +class SimpleAnnotated { + @Suppress("abc") + fun method() { + println("Hello, world!") + } + + @SinceKotlin("1.0") + val property: String = "Mary" +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/SimpleScript.log.txt b/plugins/uast-kotlin/testData/SimpleScript.log.txt index c58b3aab5d2..040fa7aebce 100644 --- a/plugins/uast-kotlin/testData/SimpleScript.log.txt +++ b/plugins/uast-kotlin/testData/SimpleScript.log.txt @@ -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 diff --git a/plugins/uast-kotlin/testData/SimpleScript.render.txt b/plugins/uast-kotlin/testData/SimpleScript.render.txt index c12f849cd71..1c119e63966 100644 --- a/plugins/uast-kotlin/testData/SimpleScript.render.txt +++ b/plugins/uast-kotlin/testData/SimpleScript.render.txt @@ -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) (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 { } diff --git a/plugins/uast-kotlin/testData/StringTemplateComplex.log.txt b/plugins/uast-kotlin/testData/StringTemplateComplex.log.txt index 06361791488..1e7bf058643 100644 --- a/plugins/uast-kotlin/testData/StringTemplateComplex.log.txt +++ b/plugins/uast-kotlin/testData/StringTemplateComplex.log.txt @@ -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) diff --git a/plugins/uast-kotlin/testData/StringTemplateComplex.render.txt b/plugins/uast-kotlin/testData/StringTemplateComplex.render.txt index f6ddce4f5a4..6ccc195d743 100644 --- a/plugins/uast-kotlin/testData/StringTemplateComplex.render.txt +++ b/plugins/uast-kotlin/testData/StringTemplateComplex.render.txt @@ -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() diff --git a/plugins/uast-kotlin/testData/SuperCalls.log.txt b/plugins/uast-kotlin/testData/SuperCalls.log.txt index 72f6c3fd797..6868c230648 100644 --- a/plugins/uast-kotlin/testData/SuperCalls.log.txt +++ b/plugins/uast-kotlin/testData/SuperCalls.log.txt @@ -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)) diff --git a/plugins/uast-kotlin/testData/SuperCalls.render.txt b/plugins/uast-kotlin/testData/SuperCalls.render.txt index b93fdf2fa81..874e70453b2 100644 --- a/plugins/uast-kotlin/testData/SuperCalls.render.txt +++ b/plugins/uast-kotlin/testData/SuperCalls.render.txt @@ -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) { (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) { (p) } - public fun C(@null i: int) { + public fun C(@org.jetbrains.annotations.NotNull i: int) { (i) println() } diff --git a/plugins/uast-kotlin/testData/WhenAndDestructing.log.txt b/plugins/uast-kotlin/testData/WhenAndDestructing.log.txt index fe1b4642d28..83ae1d3adc1 100644 --- a/plugins/uast-kotlin/testData/WhenAndDestructing.log.txt +++ b/plugins/uast-kotlin/testData/WhenAndDestructing.log.txt @@ -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 = ) ULocalVariable (name = statementFilter) + UAnnotation (fqName = null) UQualifiedReferenceExpression USimpleNameReferenceExpression (identifier = var837f1e82) UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) diff --git a/plugins/uast-kotlin/testData/WhenAndDestructing.render.txt b/plugins/uast-kotlin/testData/WhenAndDestructing.render.txt index 958e1b76605..91e017bb1e5 100644 --- a/plugins/uast-kotlin/testData/WhenAndDestructing.render.txt +++ b/plugins/uast-kotlin/testData/WhenAndDestructing.render.txt @@ -8,9 +8,9 @@ public final class WhenAndDestructingKt { } -> { - var var837f1e82: = arr - var bindingContext: java.lang.String = var837f1e82.() - var statementFilter: java.lang.String = var837f1e82.() + @null var var837f1e82: = arr + @null var bindingContext: java.lang.String = var837f1e82.() + @null var statementFilter: java.lang.String = var837f1e82.() return bindingContext break } diff --git a/plugins/uast-kotlin/testData/WhenStringLiteral.log.txt b/plugins/uast-kotlin/testData/WhenStringLiteral.log.txt index af5adb2662f..6976fdd45ba 100644 --- a/plugins/uast-kotlin/testData/WhenStringLiteral.log.txt +++ b/plugins/uast-kotlin/testData/WhenStringLiteral.log.txt @@ -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) diff --git a/plugins/uast-kotlin/testData/WhenStringLiteral.render.txt b/plugins/uast-kotlin/testData/WhenStringLiteral.render.txt index 2992788c0d5..07cf0439387 100644 --- a/plugins/uast-kotlin/testData/WhenStringLiteral.render.txt +++ b/plugins/uast-kotlin/testData/WhenStringLiteral.render.txt @@ -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 diff --git a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt index 8d2fd514e2e..368818d347d 100644 --- a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt +++ b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt @@ -217,4 +217,16 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { }) } } + + @Test + fun testSimpleAnnotated() { + doTest("SimpleAnnotated") { _, file -> + file.findElementByTextFromPsi("@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 Iterable.assertedFind(value: R, transform: (T) -> R): T = find { transform(it) == value } ?: throw AssertionError("'$value' not found, only ${this.joinToString { transform(it).toString() }}")