Uast: don't throw exception if can't get a receiver parameter for annotation (KT-40494)
This commit is contained in:
@@ -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<T : KtCallElement>(
|
||||
|
||||
val superParent = super.convertParent() ?: return null
|
||||
if (annotationUseSiteTarget() == AnnotationUseSiteTarget.RECEIVER) {
|
||||
(superParent.uastParent as? KotlinUMethod)?.uastParameters?.firstIsInstance<KotlinReceiverUParameter>()?.let {
|
||||
(superParent.uastParent as? KotlinUMethod)?.uastParameters?.firstIsInstanceOrNull<KotlinReceiverUParameter>()?.let {
|
||||
return it
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,3 +1,6 @@
|
||||
annotation class MyReceiverAnnotation
|
||||
annotation class MyReceiverAnnotation(val name: String = "")
|
||||
|
||||
fun @receiver:MyReceiverAnnotation String.foo() = this.length
|
||||
fun @receiver:MyReceiverAnnotation String.foo() = this.length
|
||||
|
||||
val @receiver:MyReceiverAnnotation("RegExp") String.rx : Regex
|
||||
get() { return toRegex() }
|
||||
@@ -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 = "")
|
||||
@@ -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 = "")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user