diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUAnnotation.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUAnnotation.kt index 3ede78c513d..c7b24c96887 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUAnnotation.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/declarations/KotlinUAnnotation.kt @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance +import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.jetbrains.uast.* import org.jetbrains.uast.kotlin.declarations.KotlinUIdentifier @@ -103,7 +103,7 @@ abstract class KotlinUAnnotationBase( val superParent = super.convertParent() ?: return null if (annotationUseSiteTarget() == AnnotationUseSiteTarget.RECEIVER) { - (superParent.uastParent as? KotlinUMethod)?.uastParameters?.firstIsInstance()?.let { + (superParent.uastParent as? KotlinUMethod)?.uastParameters?.firstIsInstanceOrNull()?.let { return it } } diff --git a/plugins/uast-kotlin/testData/ReceiverFun.kt b/plugins/uast-kotlin/testData/ReceiverFun.kt index c4581c6f980..ea10d0cee5e 100644 --- a/plugins/uast-kotlin/testData/ReceiverFun.kt +++ b/plugins/uast-kotlin/testData/ReceiverFun.kt @@ -1,3 +1,6 @@ -annotation class MyReceiverAnnotation +annotation class MyReceiverAnnotation(val name: String = "") -fun @receiver:MyReceiverAnnotation String.foo() = this.length \ No newline at end of file +fun @receiver:MyReceiverAnnotation String.foo() = this.length + +val @receiver:MyReceiverAnnotation("RegExp") String.rx : Regex + get() { return toRegex() } \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/ReceiverFun.log-ide.txt b/plugins/uast-kotlin/testData/ReceiverFun.log-ide.txt new file mode 100644 index 00000000000..72e9e538fcd --- /dev/null +++ b/plugins/uast-kotlin/testData/ReceiverFun.log-ide.txt @@ -0,0 +1,22 @@ +UFile (package = ) + UClass (name = ReceiverFunKt) + UMethod (name = foo) + UParameter (name = $this$foo) + UAnnotation (fqName = MyReceiverAnnotation) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + UQualifiedReferenceExpression + UThisExpression (label = null) + USimpleNameReferenceExpression (identifier = length) + UMethod (name = getRx) + UParameter (name = $this$getRx) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toRegex)) + USimpleNameReferenceExpression (identifier = toRegex, resolvesTo = null) + UClass (name = MyReceiverAnnotation) + UAnnotationMethod (name = name) + ULiteralExpression (value = "") diff --git a/plugins/uast-kotlin/testData/ReceiverFun.log.txt b/plugins/uast-kotlin/testData/ReceiverFun.log.txt index 60748825fcf..f977ea5f40f 100644 --- a/plugins/uast-kotlin/testData/ReceiverFun.log.txt +++ b/plugins/uast-kotlin/testData/ReceiverFun.log.txt @@ -9,4 +9,14 @@ UFile (package = ) UQualifiedReferenceExpression UThisExpression (label = null) USimpleNameReferenceExpression (identifier = length) + UMethod (name = getRx) + UParameter (name = $this$rx) + UAnnotation (fqName = org.jetbrains.annotations.NotNull) + UBlockExpression + UReturnExpression + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) + UIdentifier (Identifier (toRegex)) + USimpleNameReferenceExpression (identifier = toRegex, resolvesTo = null) UClass (name = MyReceiverAnnotation) + UAnnotationMethod (name = name) + ULiteralExpression (value = "") diff --git a/plugins/uast-kotlin/testData/ReceiverFun.render-ide.txt b/plugins/uast-kotlin/testData/ReceiverFun.render-ide.txt new file mode 100644 index 00000000000..9426e0b5506 --- /dev/null +++ b/plugins/uast-kotlin/testData/ReceiverFun.render-ide.txt @@ -0,0 +1,12 @@ +public final class ReceiverFunKt { + public static final fun foo(@MyReceiverAnnotation @org.jetbrains.annotations.NotNull $this$foo: java.lang.String) : int { + return this.length + } + public static final fun getRx(@org.jetbrains.annotations.NotNull $this$getRx: java.lang.String) : kotlin.text.Regex { + return toRegex() + } +} + +public abstract annotation MyReceiverAnnotation { + public abstract fun name() : java.lang.String = UastEmptyExpression +} diff --git a/plugins/uast-kotlin/testData/ReceiverFun.render.txt b/plugins/uast-kotlin/testData/ReceiverFun.render.txt index dcf96df9bbc..f4a6fd680ec 100644 --- a/plugins/uast-kotlin/testData/ReceiverFun.render.txt +++ b/plugins/uast-kotlin/testData/ReceiverFun.render.txt @@ -2,7 +2,11 @@ public final class ReceiverFunKt { public static final fun foo(@MyReceiverAnnotation @org.jetbrains.annotations.NotNull $this$foo: java.lang.String) : int { return this.length } + public static final fun getRx(@org.jetbrains.annotations.NotNull $this$rx: java.lang.String) : kotlin.text.Regex { + return toRegex() + } } public abstract annotation MyReceiverAnnotation { + public abstract fun name() : java.lang.String = UastEmptyExpression }