Uast: fallback to call braces in getting the anchor for call-expressions in complex cases (KT-36273)
This commit is contained in:
+4
-1
@@ -82,7 +82,10 @@ class KotlinUFunctionCallExpression(
|
|||||||
)
|
)
|
||||||
is KtLambdaExpression ->
|
is KtLambdaExpression ->
|
||||||
KotlinUIdentifier(calleeExpression.functionLiteral.lBrace, this)
|
KotlinUIdentifier(calleeExpression.functionLiteral.lBrace, this)
|
||||||
else -> KotlinUIdentifier(calleeExpression, this)
|
else -> KotlinUIdentifier(
|
||||||
|
sourcePsi.valueArgumentList?.leftParenthesis
|
||||||
|
?: sourcePsi.lambdaArguments.singleOrNull()?.getLambdaExpression()?.functionLiteral?.lBrace
|
||||||
|
?: calleeExpression, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
A -> UClass (name = A)
|
||||||
|
invoke -> UMethod (name = invoke)
|
||||||
|
this -> USimpleNameReferenceExpression (identifier = this)
|
||||||
|
invoke -> UMethod (name = invoke)
|
||||||
|
f -> UParameter (name = f)
|
||||||
|
Unit -> USimpleNameReferenceExpression (identifier = Unit)
|
||||||
|
main -> UMethod (name = main)
|
||||||
|
a -> UParameter (name = a)
|
||||||
|
A -> USimpleNameReferenceExpression (identifier = A)
|
||||||
|
a -> USimpleNameReferenceExpression (identifier = a)
|
||||||
|
!! -> USimpleNameReferenceExpression (identifier = !!)
|
||||||
|
p -> ULocalVariable (name = p)
|
||||||
|
A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))
|
||||||
|
a -> USimpleNameReferenceExpression (identifier = a)
|
||||||
|
!! -> USimpleNameReferenceExpression (identifier = !!)
|
||||||
|
p -> UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
|
||||||
|
A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
class A {
|
||||||
|
|
||||||
|
operator fun invoke(){
|
||||||
|
this()
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun invoke(f: ()-> Unit){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(a: A?){
|
||||||
|
a!!()
|
||||||
|
val p = A()
|
||||||
|
a!! {
|
||||||
|
p {
|
||||||
|
A()()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
UFile (package = )
|
||||||
|
UClass (name = NonTrivialIdentifiersKt)
|
||||||
|
UMethod (name = main)
|
||||||
|
UParameter (name = a)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
|
UBlockExpression
|
||||||
|
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
|
||||||
|
UIdentifier (Identifier (())
|
||||||
|
USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null)
|
||||||
|
UDeclarationsExpression
|
||||||
|
ULocalVariable (name = p)
|
||||||
|
UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0))
|
||||||
|
UIdentifier (Identifier (A))
|
||||||
|
USimpleNameReferenceExpression (identifier = <init>, resolvesTo = A)
|
||||||
|
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
|
||||||
|
UIdentifier (Identifier ({))
|
||||||
|
USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null)
|
||||||
|
ULambdaExpression
|
||||||
|
UBlockExpression
|
||||||
|
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1))
|
||||||
|
UIdentifier (Identifier (p))
|
||||||
|
USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null)
|
||||||
|
ULambdaExpression
|
||||||
|
UBlockExpression
|
||||||
|
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
|
||||||
|
UIdentifier (Identifier (())
|
||||||
|
USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null)
|
||||||
|
UClass (name = A)
|
||||||
|
UMethod (name = invoke)
|
||||||
|
UBlockExpression
|
||||||
|
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0))
|
||||||
|
UIdentifier (Identifier (())
|
||||||
|
USimpleNameReferenceExpression (identifier = invoke, resolvesTo = null)
|
||||||
|
UMethod (name = invoke)
|
||||||
|
UParameter (name = f)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UMethod (name = A)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
Unit -> USimpleNameReferenceExpression (identifier = Unit) from KtNameReferenceExpression
|
||||||
|
A -> USimpleNameReferenceExpression (identifier = A) from KtNameReferenceExpression
|
||||||
|
a -> USimpleNameReferenceExpression (identifier = a) from KtNameReferenceExpression
|
||||||
|
A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) from KtNameReferenceExpression
|
||||||
|
a -> USimpleNameReferenceExpression (identifier = a) from KtNameReferenceExpression
|
||||||
|
p -> UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) from KtNameReferenceExpression
|
||||||
|
A -> UCallExpression (kind = UastCallKind(name='constructor_call'), argCount = 0)) from KtNameReferenceExpression
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
public final class NonTrivialIdentifiersKt {
|
||||||
|
public static final fun main(@org.jetbrains.annotations.Nullable a: A) : void {
|
||||||
|
invoke()
|
||||||
|
var p: A = <init>()
|
||||||
|
invoke({
|
||||||
|
invoke({
|
||||||
|
invoke()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class A {
|
||||||
|
public final fun invoke() : void {
|
||||||
|
invoke()
|
||||||
|
}
|
||||||
|
public final fun invoke(@org.jetbrains.annotations.NotNull f: kotlin.jvm.functions.Function0<kotlin.Unit>) : void {
|
||||||
|
}
|
||||||
|
public fun A() = UastEmptyExpression
|
||||||
|
}
|
||||||
@@ -36,4 +36,7 @@ class KotlinUastIdentifiersTest : AbstractKotlinIdentifiersTest() {
|
|||||||
@Test
|
@Test
|
||||||
fun testEnumValuesConstructors() = doTest("EnumValuesConstructors")
|
fun testEnumValuesConstructors() = doTest("EnumValuesConstructors")
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testNonTrivialIdentifiers() = doTest("NonTrivialIdentifiers")
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -147,6 +147,9 @@ class SimpleKotlinRenderLogTest : AbstractKotlinUastTest(), AbstractKotlinRender
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAnnotatedExpressions() = doTest("AnnotatedExpressions")
|
fun testAnnotatedExpressions() = doTest("AnnotatedExpressions")
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testNonTrivialIdentifiers() = doTest("NonTrivialIdentifiers")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun withForceUInjectionHostValue(call: () -> Unit) {
|
fun withForceUInjectionHostValue(call: () -> Unit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user