Remove useless cast: don't remove parentheses for lambda
#KT-28641 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
d02867a831
commit
05d8932fa6
@@ -448,6 +448,11 @@ public class KtPsiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if (innerExpression instanceof KtLambdaExpression) {
|
||||
PsiElement prevSibling = PsiTreeUtil.skipWhitespacesAndCommentsBackward(currentInner);
|
||||
if (prevSibling != null && prevSibling.getText().endsWith(KtTokens.RPAR.getValue())) return true;
|
||||
}
|
||||
|
||||
if (parentElement instanceof KtCallExpression && currentInner == ((KtCallExpression) parentElement).getCalleeExpression()) {
|
||||
KtCallExpression parentCall = (KtCallExpression) parentElement;
|
||||
if (innerExpression instanceof KtSimpleNameExpression) return false;
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Remove useless cast" "true"
|
||||
fun test() {
|
||||
({ "" } as<caret> () -> String)
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Remove useless cast" "true"
|
||||
fun test() {
|
||||
{ "" }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove useless cast" "true"
|
||||
fun foo() {}
|
||||
|
||||
fun test() {
|
||||
foo()
|
||||
// comment
|
||||
({ "" } as<caret> () -> String)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Remove useless cast" "true"
|
||||
fun foo() {}
|
||||
|
||||
fun test() {
|
||||
foo()
|
||||
// comment
|
||||
({ "" })
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Remove useless cast" "true"
|
||||
class A {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
A().foo()
|
||||
({ "" } as<caret> () -> String)
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Remove useless cast" "true"
|
||||
class A {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
A().foo()
|
||||
({ "" })
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Remove useless cast" "true"
|
||||
fun test() {
|
||||
class A()
|
||||
({ "" } as<caret> () -> String)
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Remove useless cast" "true"
|
||||
fun test() {
|
||||
class A()
|
||||
({ "" })
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Remove useless cast" "true"
|
||||
open class A
|
||||
|
||||
fun test() {
|
||||
class B : A()
|
||||
({ "" } as<caret> () -> String)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Remove useless cast" "true"
|
||||
open class A
|
||||
|
||||
fun test() {
|
||||
class B : A()
|
||||
({ "" })
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Remove useless cast" "true"
|
||||
fun foo() {}
|
||||
|
||||
fun main() {
|
||||
foo();
|
||||
({ "" } as<caret> () -> String)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Remove useless cast" "true"
|
||||
fun foo() {}
|
||||
|
||||
fun main() {
|
||||
foo();
|
||||
{ "" }
|
||||
}
|
||||
@@ -6674,6 +6674,36 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
runTest("idea/testData/quickfix/expressions/removeUselessCast.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUselessCastForLambdaInParens1.kt")
|
||||
public void testRemoveUselessCastForLambdaInParens1() throws Exception {
|
||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUselessCastForLambdaInParens2.kt")
|
||||
public void testRemoveUselessCastForLambdaInParens2() throws Exception {
|
||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUselessCastForLambdaInParens3.kt")
|
||||
public void testRemoveUselessCastForLambdaInParens3() throws Exception {
|
||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUselessCastForLambdaInParens4.kt")
|
||||
public void testRemoveUselessCastForLambdaInParens4() throws Exception {
|
||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens4.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUselessCastForLambdaInParens5.kt")
|
||||
public void testRemoveUselessCastForLambdaInParens5() throws Exception {
|
||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens5.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUselessCastForLambdaInParens6.kt")
|
||||
public void testRemoveUselessCastForLambdaInParens6() throws Exception {
|
||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens6.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUselessCastInParens.kt")
|
||||
public void testRemoveUselessCastInParens() throws Exception {
|
||||
runTest("idea/testData/quickfix/expressions/removeUselessCastInParens.kt");
|
||||
|
||||
Reference in New Issue
Block a user