Update trailing lambda quickfix, add tests

Case of incorrect call expression as the receiver of dot-qualified expression
was not handled properly.

Now the following order is used:
- If parent is a call expression or if this call is a receiver of parent
dot-qualified expression, parent must get last lambda as a new receiver;
- Otherwise, if parent is a dot-qualified expression, this call is in selector position.
Then grandparent is checked for being call or dot-qualified expression. If so, trailing
lambda must become grandparent's new receiver. If not, trailing nodes become standalone
epressions after parent.
- Otherwise, incorrect call expression is a standalone expression, so trailing nodes
may be lifted and put after it.
This commit is contained in:
Pavel Kirpichenkov
2019-11-12 14:22:08 +03:00
parent f1934fa49d
commit 9a231bbbfa
16 changed files with 165 additions and 21 deletions
@@ -0,0 +1,8 @@
// "Terminate preceding call with semicolon" "true"
fun foo() {}
fun test() {
foo()
{<caret>"test"}.invoke().toString().toString()
}
@@ -0,0 +1,8 @@
// "Terminate preceding call with semicolon" "true"
fun foo() {}
fun test() {
foo();
{"test"}.invoke().toString().toString()
}
@@ -0,0 +1,6 @@
// "Terminate preceding call with semicolon" "true"
fun test() {
"test".toString().toString().toString()
{<caret>}
}
@@ -0,0 +1,6 @@
// "Terminate preceding call with semicolon" "true"
fun test() {
"test".toString().toString().toString();
{}
}
@@ -0,0 +1,6 @@
// "Terminate preceding call with semicolon" "true"
fun test() {
"test".toString().toString().toString()
{<caret>"test"}.invoke().toString().toString()
}
@@ -0,0 +1,6 @@
// "Terminate preceding call with semicolon" "true"
fun test() {
"test".toString().toString().toString();
{"test"}.invoke().toString().toString()
}
@@ -0,0 +1,14 @@
// "Terminate preceding call with semicolon" "true"
fun foo() {}
fun String.withLambda(lambda: (String) -> Unit) {}
fun test {
{ { "test" } }.invoke()().toString().withLambda()
// comment and formatting
{} // correct trailing lambda
/*
block comment
*/
{ { { foo() }<caret> } }.invoke()().invoke()
}
@@ -0,0 +1,14 @@
// "Terminate preceding call with semicolon" "true"
fun foo() {}
fun String.withLambda(lambda: (String) -> Unit) {}
fun test {
{ { "test" } }.invoke()().toString().withLambda()
// comment and formatting
{}; // correct trailing lambda
/*
block comment
*/
{ { { foo() } } }.invoke()().invoke()
}
@@ -6,4 +6,4 @@ fun test {
foo()
// comment and formatting
{ { { foo() }<caret> } }()()()
}
}
@@ -6,4 +6,4 @@ fun test {
foo();
// comment and formatting
{ { { foo() } } }()()()
}
}
@@ -0,0 +1,9 @@
// "Terminate preceding call with semicolon" "true"
fun foo() {}
fun test {
{ { { foo() } } }()()()
// comment and formatting
{<caret>}
}
@@ -0,0 +1,9 @@
// "Terminate preceding call with semicolon" "true"
fun foo() {}
fun test {
{ { { foo() } } }()()();
// comment and formatting
{}
}
@@ -0,0 +1,9 @@
// "Terminate preceding call with semicolon" "true"
fun foo() {}
fun test {
{ { { foo() } } }()()()
// comment and formatting
{ { { foo() }<caret> } }()()()
}
@@ -0,0 +1,9 @@
// "Terminate preceding call with semicolon" "true"
fun foo() {}
fun test {
{ { { foo() } } }()()();
// comment and formatting
{ { { foo() } } }()()()
}