From cda1a7edbe2cb9d34fd41ff3a11c028f44ffbc7c Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Fri, 18 Jun 2021 23:34:18 -0700 Subject: [PATCH] FIR/UAST: commonize UAnnotationMethod --- .../BaseKotlinUAnnotationMethod.kt | 23 +++++++++++++++++++ .../FirKotlinUAnnotationMethod.kt | 17 ++++++++++++++ .../kotlin/declarations/FirKotlinUMethod.kt | 9 +++++--- .../AnnotationComplex.identifiers.fir.txt | 6 ++--- .../AnnotationParameters.identifiers.fir.txt | 12 +++++----- .../ClassAnnotation.identifiers.fir.txt | 2 +- .../ReceiverFun.identifiers.fir.txt | 2 +- .../AnnotationComplex.log.fir.txt | 6 ++--- .../AnnotationParameters.log.fir.txt | 13 ++++++----- .../ClassAnnotation.log.fir.txt | 2 +- .../legacyRenderLog/ReceiverFun.log.fir.txt | 3 ++- .../AnnotationComplex.types.fir.txt | 6 ++--- .../AnnotationParameters.types.fir.txt | 13 ++++++----- .../legacyTypes/ClassAnnotation.types.fir.txt | 2 +- .../legacyTypes/ReceiverFun.types.fir.txt | 3 ++- .../AnnotationComplex.values.fir.txt | 6 ++--- .../AnnotationParameters.values.fir.txt | 13 ++++++----- .../ClassAnnotation.values.fir.txt | 2 +- .../legacyValues/ReceiverFun.values.fir.txt | 3 ++- .../declarations/KotlinUAnnotationMethod.kt | 17 ++++++++++++++ .../uast/kotlin/declarations/KotlinUMethod.kt | 15 ------------ 21 files changed, 113 insertions(+), 62 deletions(-) create mode 100644 plugins/uast-kotlin-base/src/org/jetbrains/uast/kotlin/declarations/BaseKotlinUAnnotationMethod.kt create mode 100644 plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/declarations/FirKotlinUAnnotationMethod.kt create mode 100644 plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUAnnotationMethod.kt diff --git a/plugins/uast-kotlin-base/src/org/jetbrains/uast/kotlin/declarations/BaseKotlinUAnnotationMethod.kt b/plugins/uast-kotlin-base/src/org/jetbrains/uast/kotlin/declarations/BaseKotlinUAnnotationMethod.kt new file mode 100644 index 00000000000..6ac82c73a8c --- /dev/null +++ b/plugins/uast-kotlin-base/src/org/jetbrains/uast/kotlin/declarations/BaseKotlinUAnnotationMethod.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.uast.kotlin + +import org.jetbrains.kotlin.asJava.elements.KtLightMethod +import org.jetbrains.kotlin.psi.KtParameter +import org.jetbrains.uast.* + +abstract class BaseKotlinUAnnotationMethod( + psi: KtLightMethod, + givenParent: UElement? +) : BaseKotlinUMethod(psi, psi.kotlinOrigin, givenParent), UAnnotationMethod { + override val psi: KtLightMethod = unwrap(psi) + + override val uastDefaultValue: UExpression? by lz { + val annotationParameter = sourcePsi as? KtParameter ?: return@lz null + val defaultValue = annotationParameter.defaultValue ?: return@lz null + languagePlugin?.convertElement(defaultValue, this) as? UExpression + } +} diff --git a/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/declarations/FirKotlinUAnnotationMethod.kt b/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/declarations/FirKotlinUAnnotationMethod.kt new file mode 100644 index 00000000000..190efba6e0e --- /dev/null +++ b/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/declarations/FirKotlinUAnnotationMethod.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.uast.kotlin + +import org.jetbrains.kotlin.asJava.elements.KtLightMethod +import org.jetbrains.uast.UElement + +class FirKotlinUAnnotationMethod( + psi: KtLightMethod, + givenParent: UElement? +) : BaseKotlinUAnnotationMethod(psi, givenParent), FirKotlinUMethodParametersProducer { + + override val uastParameters by lz { produceUastParameters(this, receiverTypeReference) } +} diff --git a/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/declarations/FirKotlinUMethod.kt b/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/declarations/FirKotlinUMethod.kt index e19d046cfc5..c42288bdbac 100644 --- a/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/declarations/FirKotlinUMethod.kt +++ b/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/declarations/FirKotlinUMethod.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.asJava.LightClassUtil import org.jetbrains.kotlin.asJava.elements.* import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject +import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.uast.* class FirKotlinUMethod( @@ -29,10 +30,12 @@ class FirKotlinUMethod( psi: KtLightMethod, givenParent: UElement? ): UMethod { - return when (val kotlinOrigin = psi.kotlinOrigin) { - is KtConstructor<*> -> + val kotlinOrigin = psi.kotlinOrigin + return when { + kotlinOrigin is KtConstructor<*> -> FirKotlinConstructorUMethod(kotlinOrigin.containingClassOrObject, psi, givenParent) - // TODO: FirKotlinUAnnotationMethod + kotlinOrigin is KtParameter && kotlinOrigin.getParentOfType(true)?.isAnnotation() == true -> + FirKotlinUAnnotationMethod(psi, givenParent) else -> FirKotlinUMethod(psi, givenParent) } diff --git a/plugins/uast-kotlin-fir/testData/legacyIdentifiers/AnnotationComplex.identifiers.fir.txt b/plugins/uast-kotlin-fir/testData/legacyIdentifiers/AnnotationComplex.identifiers.fir.txt index be20f3bcd07..9fbe8738f54 100644 --- a/plugins/uast-kotlin-fir/testData/legacyIdentifiers/AnnotationComplex.identifiers.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyIdentifiers/AnnotationComplex.identifiers.fir.txt @@ -1,10 +1,10 @@ Annotation -> UClass (name = Annotation) -strings -> UMethod (name = strings) +strings -> UAnnotationMethod (name = strings) String -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) Annotation -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) A -> UClass (name = A) AnnotationInner -> UClass (name = AnnotationInner) -value -> UMethod (name = value) +value -> UAnnotationMethod (name = value) Annotation -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) AnnotationArray -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) Annotation -> [!] UnknownKotlinExpression (CALL_EXPRESSION) @@ -14,7 +14,7 @@ value -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) Annotation -> [!] UnknownKotlinExpression (CALL_EXPRESSION) B2 -> UClass (name = B2) AnnotationArray -> UClass (name = AnnotationArray) -value -> UMethod (name = value) +value -> UAnnotationMethod (name = value) Annotation -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) AnnotationArray -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) Annotation -> [!] UnknownKotlinExpression (CALL_EXPRESSION) diff --git a/plugins/uast-kotlin-fir/testData/legacyIdentifiers/AnnotationParameters.identifiers.fir.txt b/plugins/uast-kotlin-fir/testData/legacyIdentifiers/AnnotationParameters.identifiers.fir.txt index 21578d2d034..79b16c8e192 100644 --- a/plugins/uast-kotlin-fir/testData/legacyIdentifiers/AnnotationParameters.identifiers.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyIdentifiers/AnnotationParameters.identifiers.fir.txt @@ -1,20 +1,20 @@ IntRange -> UClass (name = IntRange) -from -> UMethod (name = from) +from -> UAnnotationMethod (name = from) Long -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) -to -> UMethod (name = to) +to -> UAnnotationMethod (name = to) Long -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) RequiresPermission -> UClass (name = RequiresPermission) -anyOf -> UMethod (name = anyOf) +anyOf -> UAnnotationMethod (name = anyOf) IntArray -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) RequiresStrPermission -> UClass (name = RequiresStrPermission) -strs -> UMethod (name = strs) +strs -> UAnnotationMethod (name = strs) Array -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) String -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) WithDefaultValue -> UClass (name = WithDefaultValue) -value -> UMethod (name = value) +value -> UAnnotationMethod (name = value) Int -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) SuppressLint -> UClass (name = SuppressLint) -value -> UMethod (name = value) +value -> UAnnotationMethod (name = value) String -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) RequiresPermission -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) anyOf -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) diff --git a/plugins/uast-kotlin-fir/testData/legacyIdentifiers/ClassAnnotation.identifiers.fir.txt b/plugins/uast-kotlin-fir/testData/legacyIdentifiers/ClassAnnotation.identifiers.fir.txt index c1830ef2420..aabf6e4a05f 100644 --- a/plugins/uast-kotlin-fir/testData/legacyIdentifiers/ClassAnnotation.identifiers.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyIdentifiers/ClassAnnotation.identifiers.fir.txt @@ -1,7 +1,7 @@ Test -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) A -> UClass (name = A) MyAnnotation -> UClass (name = MyAnnotation) -text -> UMethod (name = text) +text -> UAnnotationMethod (name = text) String -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) MyAnnotation -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) B -> UClass (name = B) diff --git a/plugins/uast-kotlin-fir/testData/legacyIdentifiers/ReceiverFun.identifiers.fir.txt b/plugins/uast-kotlin-fir/testData/legacyIdentifiers/ReceiverFun.identifiers.fir.txt index 24653b199cc..32fd4235e82 100644 --- a/plugins/uast-kotlin-fir/testData/legacyIdentifiers/ReceiverFun.identifiers.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyIdentifiers/ReceiverFun.identifiers.fir.txt @@ -1,5 +1,5 @@ MyReceiverAnnotation -> UClass (name = MyReceiverAnnotation) -name -> UMethod (name = name) +name -> UAnnotationMethod (name = name) String -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) MyReceiverAnnotation -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) String -> [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) diff --git a/plugins/uast-kotlin-fir/testData/legacyRenderLog/AnnotationComplex.log.fir.txt b/plugins/uast-kotlin-fir/testData/legacyRenderLog/AnnotationComplex.log.fir.txt index 7d79eddcbef..60e8f6a98f7 100644 --- a/plugins/uast-kotlin-fir/testData/legacyRenderLog/AnnotationComplex.log.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyRenderLog/AnnotationComplex.log.fir.txt @@ -1,11 +1,11 @@ UFile (package = ) UClass (name = Annotation) - UMethod (name = strings) + UAnnotationMethod (name = strings) UClass (name = A) UAnnotation (fqName = not-implemented-annotation) UMethod (name = A) UClass (name = AnnotationInner) - UMethod (name = value) + UAnnotationMethod (name = value) UClass (name = B1) UAnnotation (fqName = not-implemented-annotation) UMethod (name = B1) @@ -13,7 +13,7 @@ UFile (package = ) UAnnotation (fqName = not-implemented-annotation) UMethod (name = B2) UClass (name = AnnotationArray) - UMethod (name = value) + UAnnotationMethod (name = value) UClass (name = C) UAnnotation (fqName = not-implemented-annotation) UMethod (name = C) diff --git a/plugins/uast-kotlin-fir/testData/legacyRenderLog/AnnotationParameters.log.fir.txt b/plugins/uast-kotlin-fir/testData/legacyRenderLog/AnnotationParameters.log.fir.txt index bcd84fe8720..2f71b52d015 100644 --- a/plugins/uast-kotlin-fir/testData/legacyRenderLog/AnnotationParameters.log.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyRenderLog/AnnotationParameters.log.fir.txt @@ -17,13 +17,14 @@ UFile (package = ) UReturnExpression ULiteralExpression (value = "not-yet-compile-time-constant") UClass (name = IntRange) - UMethod (name = from) - UMethod (name = to) + UAnnotationMethod (name = from) + UAnnotationMethod (name = to) UClass (name = RequiresPermission) - UMethod (name = anyOf) + UAnnotationMethod (name = anyOf) UClass (name = RequiresStrPermission) - UMethod (name = strs) + UAnnotationMethod (name = strs) UClass (name = WithDefaultValue) - UMethod (name = value) + UAnnotationMethod (name = value) + ULiteralExpression (value = "not-yet-compile-time-constant") UClass (name = SuppressLint) - UMethod (name = value) + UAnnotationMethod (name = value) diff --git a/plugins/uast-kotlin-fir/testData/legacyRenderLog/ClassAnnotation.log.fir.txt b/plugins/uast-kotlin-fir/testData/legacyRenderLog/ClassAnnotation.log.fir.txt index 92da0e23935..6e76e48cd9d 100644 --- a/plugins/uast-kotlin-fir/testData/legacyRenderLog/ClassAnnotation.log.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyRenderLog/ClassAnnotation.log.fir.txt @@ -3,7 +3,7 @@ UFile (package = ) UAnnotation (fqName = not-implemented-annotation) UMethod (name = A) UClass (name = MyAnnotation) - UMethod (name = text) + UAnnotationMethod (name = text) UClass (name = B) UAnnotation (fqName = not-implemented-annotation) UField (name = Companion) diff --git a/plugins/uast-kotlin-fir/testData/legacyRenderLog/ReceiverFun.log.fir.txt b/plugins/uast-kotlin-fir/testData/legacyRenderLog/ReceiverFun.log.fir.txt index 6e177b805d7..3b65b1f227a 100644 --- a/plugins/uast-kotlin-fir/testData/legacyRenderLog/ReceiverFun.log.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyRenderLog/ReceiverFun.log.fir.txt @@ -11,4 +11,5 @@ UFile (package = ) UReturnExpression [!] UnknownKotlinExpression (CALL_EXPRESSION) UClass (name = MyReceiverAnnotation) - UMethod (name = name) + UAnnotationMethod (name = name) + ULiteralExpression (value = "") diff --git a/plugins/uast-kotlin-fir/testData/legacyTypes/AnnotationComplex.types.fir.txt b/plugins/uast-kotlin-fir/testData/legacyTypes/AnnotationComplex.types.fir.txt index 3ae491923ff..216fcd5c82f 100644 --- a/plugins/uast-kotlin-fir/testData/legacyTypes/AnnotationComplex.types.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyTypes/AnnotationComplex.types.fir.txt @@ -1,11 +1,11 @@ UFile (package = ) [public abstract annotation Annotation {...] UClass (name = Annotation) [public abstract annotation Annotation {...}] - UMethod (name = strings) [public abstract fun strings() : java.lang.String[] = UastEmptyExpression] + UAnnotationMethod (name = strings) [public abstract fun strings() : java.lang.String[] = UastEmptyExpression] UClass (name = A) [public final class A {...}] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = A) [public fun A() = UastEmptyExpression] UClass (name = AnnotationInner) [public abstract annotation AnnotationInner {...}] - UMethod (name = value) [public abstract fun value() : Annotation = UastEmptyExpression] + UAnnotationMethod (name = value) [public abstract fun value() : Annotation = UastEmptyExpression] UClass (name = B1) [public final class B1 {...}] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = B1) [public fun B1() = UastEmptyExpression] @@ -13,7 +13,7 @@ UFile (package = ) [public abstract annotation Annotation {...] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = B2) [public fun B2() = UastEmptyExpression] UClass (name = AnnotationArray) [public abstract annotation AnnotationArray {...}] - UMethod (name = value) [public abstract fun value() : Annotation[] = UastEmptyExpression] + UAnnotationMethod (name = value) [public abstract fun value() : Annotation[] = UastEmptyExpression] UClass (name = C) [public final class C {...}] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = C) [public fun C() = UastEmptyExpression] diff --git a/plugins/uast-kotlin-fir/testData/legacyTypes/AnnotationParameters.types.fir.txt b/plugins/uast-kotlin-fir/testData/legacyTypes/AnnotationParameters.types.fir.txt index efdea5526a8..d6000967617 100644 --- a/plugins/uast-kotlin-fir/testData/legacyTypes/AnnotationParameters.types.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyTypes/AnnotationParameters.types.fir.txt @@ -17,13 +17,14 @@ UFile (package = ) [public final class AnnotationParametersKt {...] UReturnExpression [return "not-yet-compile-time-constant"] ULiteralExpression (value = "not-yet-compile-time-constant") ["not-yet-compile-time-constant"] : PsiType:int UClass (name = IntRange) [public abstract annotation IntRange {...}] - UMethod (name = from) [public abstract fun from() : long = UastEmptyExpression] - UMethod (name = to) [public abstract fun to() : long = UastEmptyExpression] + UAnnotationMethod (name = from) [public abstract fun from() : long = UastEmptyExpression] + UAnnotationMethod (name = to) [public abstract fun to() : long = UastEmptyExpression] UClass (name = RequiresPermission) [public abstract annotation RequiresPermission {...}] - UMethod (name = anyOf) [public abstract fun anyOf() : int[] = UastEmptyExpression] + UAnnotationMethod (name = anyOf) [public abstract fun anyOf() : int[] = UastEmptyExpression] UClass (name = RequiresStrPermission) [public abstract annotation RequiresStrPermission {...}] - UMethod (name = strs) [public abstract fun strs() : java.lang.String[] = UastEmptyExpression] + UAnnotationMethod (name = strs) [public abstract fun strs() : java.lang.String[] = UastEmptyExpression] UClass (name = WithDefaultValue) [public abstract annotation WithDefaultValue {...}] - UMethod (name = value) [public abstract fun value() : int = UastEmptyExpression] + UAnnotationMethod (name = value) [public abstract fun value() : int = UastEmptyExpression] + ULiteralExpression (value = "not-yet-compile-time-constant") ["not-yet-compile-time-constant"] : PsiType:int UClass (name = SuppressLint) [public abstract annotation SuppressLint {...}] - UMethod (name = value) [public abstract fun value() : java.lang.String[] = UastEmptyExpression] + UAnnotationMethod (name = value) [public abstract fun value() : java.lang.String[] = UastEmptyExpression] diff --git a/plugins/uast-kotlin-fir/testData/legacyTypes/ClassAnnotation.types.fir.txt b/plugins/uast-kotlin-fir/testData/legacyTypes/ClassAnnotation.types.fir.txt index 3afd0b924ec..c3e368d71d5 100644 --- a/plugins/uast-kotlin-fir/testData/legacyTypes/ClassAnnotation.types.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyTypes/ClassAnnotation.types.fir.txt @@ -3,7 +3,7 @@ UFile (package = ) [public final class A {...] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = A) [public fun A() = UastEmptyExpression] UClass (name = MyAnnotation) [public abstract annotation MyAnnotation {...}] - UMethod (name = text) [public abstract fun text() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = text) [public abstract fun text() : java.lang.String = UastEmptyExpression] UClass (name = B) [public final class B {...}] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UField (name = Companion) [public static final var Companion: B.Companion] diff --git a/plugins/uast-kotlin-fir/testData/legacyTypes/ReceiverFun.types.fir.txt b/plugins/uast-kotlin-fir/testData/legacyTypes/ReceiverFun.types.fir.txt index 4a0faf74c47..73e56d4cce6 100644 --- a/plugins/uast-kotlin-fir/testData/legacyTypes/ReceiverFun.types.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyTypes/ReceiverFun.types.fir.txt @@ -11,4 +11,5 @@ UFile (package = ) [public final class ReceiverFunKt {...] UReturnExpression [return [!] UnknownKotlinExpression (CALL_EXPRESSION)] : PsiType:Void [!] UnknownKotlinExpression (CALL_EXPRESSION) [[!] UnknownKotlinExpression (CALL_EXPRESSION)] UClass (name = MyReceiverAnnotation) [public abstract annotation MyReceiverAnnotation {...}] - UMethod (name = name) [public abstract fun name() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = name) [public abstract fun name() : java.lang.String = UastEmptyExpression] + ULiteralExpression (value = "") [""] : PsiType:String diff --git a/plugins/uast-kotlin-fir/testData/legacyValues/AnnotationComplex.values.fir.txt b/plugins/uast-kotlin-fir/testData/legacyValues/AnnotationComplex.values.fir.txt index 3ae491923ff..216fcd5c82f 100644 --- a/plugins/uast-kotlin-fir/testData/legacyValues/AnnotationComplex.values.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyValues/AnnotationComplex.values.fir.txt @@ -1,11 +1,11 @@ UFile (package = ) [public abstract annotation Annotation {...] UClass (name = Annotation) [public abstract annotation Annotation {...}] - UMethod (name = strings) [public abstract fun strings() : java.lang.String[] = UastEmptyExpression] + UAnnotationMethod (name = strings) [public abstract fun strings() : java.lang.String[] = UastEmptyExpression] UClass (name = A) [public final class A {...}] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = A) [public fun A() = UastEmptyExpression] UClass (name = AnnotationInner) [public abstract annotation AnnotationInner {...}] - UMethod (name = value) [public abstract fun value() : Annotation = UastEmptyExpression] + UAnnotationMethod (name = value) [public abstract fun value() : Annotation = UastEmptyExpression] UClass (name = B1) [public final class B1 {...}] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = B1) [public fun B1() = UastEmptyExpression] @@ -13,7 +13,7 @@ UFile (package = ) [public abstract annotation Annotation {...] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = B2) [public fun B2() = UastEmptyExpression] UClass (name = AnnotationArray) [public abstract annotation AnnotationArray {...}] - UMethod (name = value) [public abstract fun value() : Annotation[] = UastEmptyExpression] + UAnnotationMethod (name = value) [public abstract fun value() : Annotation[] = UastEmptyExpression] UClass (name = C) [public final class C {...}] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = C) [public fun C() = UastEmptyExpression] diff --git a/plugins/uast-kotlin-fir/testData/legacyValues/AnnotationParameters.values.fir.txt b/plugins/uast-kotlin-fir/testData/legacyValues/AnnotationParameters.values.fir.txt index 5ff24c1562f..c2db46a3513 100644 --- a/plugins/uast-kotlin-fir/testData/legacyValues/AnnotationParameters.values.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyValues/AnnotationParameters.values.fir.txt @@ -17,13 +17,14 @@ UFile (package = ) [public final class AnnotationParametersKt {...] UReturnExpression [return "not-yet-compile-time-constant"] = Nothing ULiteralExpression (value = "not-yet-compile-time-constant") ["not-yet-compile-time-constant"] = "not-yet-compile-time-constant" UClass (name = IntRange) [public abstract annotation IntRange {...}] - UMethod (name = from) [public abstract fun from() : long = UastEmptyExpression] - UMethod (name = to) [public abstract fun to() : long = UastEmptyExpression] + UAnnotationMethod (name = from) [public abstract fun from() : long = UastEmptyExpression] + UAnnotationMethod (name = to) [public abstract fun to() : long = UastEmptyExpression] UClass (name = RequiresPermission) [public abstract annotation RequiresPermission {...}] - UMethod (name = anyOf) [public abstract fun anyOf() : int[] = UastEmptyExpression] + UAnnotationMethod (name = anyOf) [public abstract fun anyOf() : int[] = UastEmptyExpression] UClass (name = RequiresStrPermission) [public abstract annotation RequiresStrPermission {...}] - UMethod (name = strs) [public abstract fun strs() : java.lang.String[] = UastEmptyExpression] + UAnnotationMethod (name = strs) [public abstract fun strs() : java.lang.String[] = UastEmptyExpression] UClass (name = WithDefaultValue) [public abstract annotation WithDefaultValue {...}] - UMethod (name = value) [public abstract fun value() : int = UastEmptyExpression] + UAnnotationMethod (name = value) [public abstract fun value() : int = UastEmptyExpression] + ULiteralExpression (value = "not-yet-compile-time-constant") ["not-yet-compile-time-constant"] = "not-yet-compile-time-constant" UClass (name = SuppressLint) [public abstract annotation SuppressLint {...}] - UMethod (name = value) [public abstract fun value() : java.lang.String[] = UastEmptyExpression] + UAnnotationMethod (name = value) [public abstract fun value() : java.lang.String[] = UastEmptyExpression] diff --git a/plugins/uast-kotlin-fir/testData/legacyValues/ClassAnnotation.values.fir.txt b/plugins/uast-kotlin-fir/testData/legacyValues/ClassAnnotation.values.fir.txt index 3afd0b924ec..c3e368d71d5 100644 --- a/plugins/uast-kotlin-fir/testData/legacyValues/ClassAnnotation.values.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyValues/ClassAnnotation.values.fir.txt @@ -3,7 +3,7 @@ UFile (package = ) [public final class A {...] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UMethod (name = A) [public fun A() = UastEmptyExpression] UClass (name = MyAnnotation) [public abstract annotation MyAnnotation {...}] - UMethod (name = text) [public abstract fun text() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = text) [public abstract fun text() : java.lang.String = UastEmptyExpression] UClass (name = B) [public final class B {...}] UAnnotation (fqName = not-implemented-annotation) [@not-implemented-annotation] UField (name = Companion) [public static final var Companion: B.Companion] diff --git a/plugins/uast-kotlin-fir/testData/legacyValues/ReceiverFun.values.fir.txt b/plugins/uast-kotlin-fir/testData/legacyValues/ReceiverFun.values.fir.txt index 273d576cf96..3ba653b900e 100644 --- a/plugins/uast-kotlin-fir/testData/legacyValues/ReceiverFun.values.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyValues/ReceiverFun.values.fir.txt @@ -11,4 +11,5 @@ UFile (package = ) [public final class ReceiverFunKt {...] UReturnExpression [return [!] UnknownKotlinExpression (CALL_EXPRESSION)] = Nothing [!] UnknownKotlinExpression (CALL_EXPRESSION) [[!] UnknownKotlinExpression (CALL_EXPRESSION)] = Undetermined UClass (name = MyReceiverAnnotation) [public abstract annotation MyReceiverAnnotation {...}] - UMethod (name = name) [public abstract fun name() : java.lang.String = UastEmptyExpression] + UAnnotationMethod (name = name) [public abstract fun name() : java.lang.String = UastEmptyExpression] + ULiteralExpression (value = "") [""] = "" diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUAnnotationMethod.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUAnnotationMethod.kt new file mode 100644 index 00000000000..b290341f433 --- /dev/null +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUAnnotationMethod.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.uast.kotlin + +import org.jetbrains.kotlin.asJava.elements.KtLightMethod +import org.jetbrains.uast.UElement + +class KotlinUAnnotationMethod( + psi: KtLightMethod, + givenParent: UElement? +) : BaseKotlinUAnnotationMethod(psi, givenParent), KotlinUMethodParametersProducer { + + override val uastParameters by lz { produceUastParameters(this, receiverTypeReference) } +} 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 61b6abe8256..53d8d72b4d5 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 @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.uast.* -import org.jetbrains.uast.kotlin.* import org.jetbrains.uast.kotlin.psi.UastFakeLightMethod open class KotlinUMethod( @@ -54,20 +53,6 @@ open class KotlinUMethod( } } -open class KotlinUAnnotationMethod( - psi: KtLightMethod, - givenParent: UElement? -) : KotlinUMethod(psi, psi.kotlinOrigin, givenParent), UAnnotationMethod { - - override val psi: KtLightMethod = unwrap(psi) - - override val uastDefaultValue by lz { - val annotationParameter = sourcePsi as? KtParameter ?: return@lz null - val defaultValue = annotationParameter.defaultValue ?: return@lz null - getLanguagePlugin().convertElement(defaultValue, this) as? UExpression - } -} - class KotlinUMethodWithFakeLightDelegate internal constructor( val original: KtFunction, fakePsi: UastFakeLightMethod,