FIR IDE: Remove multiple nested params in RemoveUselessElvisFix and
RemoveUselessCastFix.
This commit is contained in:
committed by
TeamCityServer
parent
a778cc673e
commit
d12a24418e
Generated
+30
@@ -561,6 +561,16 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
|
|||||||
runTest("idea/testData/quickfix/expressions/removeUselessCast.kt");
|
runTest("idea/testData/quickfix/expressions/removeUselessCast.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeUselessCastForLambdaInNecessaryNestedParens2.kt")
|
||||||
|
public void testRemoveUselessCastForLambdaInNecessaryNestedParens2() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInNecessaryNestedParens2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeUselessCastForLambdaInNestedParens.kt")
|
||||||
|
public void testRemoveUselessCastForLambdaInNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("removeUselessCastForLambdaInParens1.kt")
|
@TestMetadata("removeUselessCastForLambdaInParens1.kt")
|
||||||
public void testRemoveUselessCastForLambdaInParens1() throws Exception {
|
public void testRemoveUselessCastForLambdaInParens1() throws Exception {
|
||||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens1.kt");
|
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens1.kt");
|
||||||
@@ -591,6 +601,11 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
|
|||||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens6.kt");
|
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens6.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeUselessCastInNestedParens.kt")
|
||||||
|
public void testRemoveUselessCastInNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/removeUselessCastInNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("removeUselessCastInParens.kt")
|
@TestMetadata("removeUselessCastInParens.kt")
|
||||||
public void testRemoveUselessCastInParens() throws Exception {
|
public void testRemoveUselessCastInParens() throws Exception {
|
||||||
runTest("idea/testData/quickfix/expressions/removeUselessCastInParens.kt");
|
runTest("idea/testData/quickfix/expressions/removeUselessCastInParens.kt");
|
||||||
@@ -691,6 +706,21 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
|
|||||||
runTest("idea/testData/quickfix/expressions/uselessElvis.kt");
|
runTest("idea/testData/quickfix/expressions/uselessElvis.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("uselessElvisForLambdaInNecessaryNestedParens.kt")
|
||||||
|
public void testUselessElvisForLambdaInNecessaryNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/uselessElvisForLambdaInNecessaryNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("uselessElvisForLambdaInNestedParens.kt")
|
||||||
|
public void testUselessElvisForLambdaInNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/uselessElvisForLambdaInNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("uselessElvisInNestedParens.kt")
|
||||||
|
public void testUselessElvisInNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/uselessElvisInNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("uselessElvisRightIsNull.kt")
|
@TestMetadata("uselessElvisRightIsNull.kt")
|
||||||
public void testUselessElvisRightIsNull() throws Exception {
|
public void testUselessElvisRightIsNull() throws Exception {
|
||||||
runTest("idea/testData/quickfix/expressions/uselessElvisRightIsNull.kt");
|
runTest("idea/testData/quickfix/expressions/uselessElvisRightIsNull.kt");
|
||||||
|
|||||||
+10
-6
@@ -11,14 +11,21 @@ import org.jetbrains.kotlin.psi.KtParenthesizedExpression
|
|||||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||||
|
|
||||||
inline fun <reified T : PsiElement> PsiElement.replaced(newElement: T): T {
|
inline fun <reified T : PsiElement> PsiElement.replaced(newElement: T): T {
|
||||||
|
if (this == newElement) return newElement
|
||||||
val result = replace(newElement)
|
val result = replace(newElement)
|
||||||
return result as? T ?: (result as KtParenthesizedExpression).expression as T
|
return result as? T ?: (result as KtParenthesizedExpression).expression as T
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtExpression.dropEnclosingParenthesesIfPossible(): KtExpression {
|
fun KtExpression.dropEnclosingParenthesesIfPossible(): KtExpression {
|
||||||
val parent = parent as? KtParenthesizedExpression ?: return this
|
val innermostExpression = this
|
||||||
if (!KtPsiUtil.areParenthesesUseless(parent)) return this
|
var current = innermostExpression
|
||||||
return parent.replaced(this)
|
|
||||||
|
while (true) {
|
||||||
|
val parent = current.parent as? KtParenthesizedExpression ?: break
|
||||||
|
if (!KtPsiUtil.areParenthesesUseless(parent)) break
|
||||||
|
current = parent
|
||||||
|
}
|
||||||
|
return current.replaced(innermostExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo make inline
|
//todo make inline
|
||||||
@@ -26,6 +33,3 @@ fun KtExpression.dropEnclosingParenthesesIfPossible(): KtExpression {
|
|||||||
fun <T : PsiElement> T.copied(): T = copy() as T
|
fun <T : PsiElement> T.copied(): T = copy() as T
|
||||||
|
|
||||||
fun String.unquote(): String = KtPsiUtil.unquoteIdentifier(this)
|
fun String.unquote(): String = KtPsiUtil.unquoteIdentifier(this)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// "Remove useless cast" "true"
|
||||||
|
fun foo() {}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo()
|
||||||
|
// comment
|
||||||
|
((({ "" } as<caret> () -> String)))
|
||||||
|
}
|
||||||
|
/* IGNORE_FIR */
|
||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// "Remove useless cast" "true"
|
||||||
|
fun foo() {}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo()
|
||||||
|
// comment
|
||||||
|
({ "" })
|
||||||
|
}
|
||||||
|
/* IGNORE_FIR */
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Remove useless cast" "true"
|
||||||
|
fun test() {
|
||||||
|
((({ "" } as<caret> () -> String)))
|
||||||
|
}
|
||||||
|
/* IGNORE_FIR */
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Remove useless cast" "true"
|
||||||
|
fun test() {
|
||||||
|
{ "" }
|
||||||
|
}
|
||||||
|
/* IGNORE_FIR */
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// "Remove useless cast" "true"
|
||||||
|
fun test(x: Any): Int {
|
||||||
|
if (x is String) {
|
||||||
|
return (((x <caret>as String))).length
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IGNORE_FIR */
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// "Remove useless cast" "true"
|
||||||
|
fun test(x: Any): Int {
|
||||||
|
if (x is String) {
|
||||||
|
return x.length
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IGNORE_FIR */
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Remove useless elvis operator" "true"
|
||||||
|
fun foo() {}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo()
|
||||||
|
// comment
|
||||||
|
((({ "" } <caret>?: null)))
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Remove useless elvis operator" "true"
|
||||||
|
fun foo() {}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo()
|
||||||
|
// comment
|
||||||
|
({ "" })
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Remove useless elvis operator" "true"
|
||||||
|
fun test() {
|
||||||
|
((({ "" } <caret>?: null)))
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
// "Remove useless elvis operator" "true"
|
||||||
|
fun test() {
|
||||||
|
{ "" }
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Remove useless elvis operator" "true"
|
||||||
|
fun foo(a: String) {
|
||||||
|
val b : String = (((a <caret>?: "s")))
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Remove useless elvis operator" "true"
|
||||||
|
fun foo(a: String) {
|
||||||
|
val b : String = a<caret>
|
||||||
|
}
|
||||||
@@ -7750,6 +7750,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/expressions/removeUselessCast.kt");
|
runTest("idea/testData/quickfix/expressions/removeUselessCast.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeUselessCastForLambdaInNecessaryNestedParens2.kt")
|
||||||
|
public void testRemoveUselessCastForLambdaInNecessaryNestedParens2() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInNecessaryNestedParens2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeUselessCastForLambdaInNestedParens.kt")
|
||||||
|
public void testRemoveUselessCastForLambdaInNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("removeUselessCastForLambdaInParens1.kt")
|
@TestMetadata("removeUselessCastForLambdaInParens1.kt")
|
||||||
public void testRemoveUselessCastForLambdaInParens1() throws Exception {
|
public void testRemoveUselessCastForLambdaInParens1() throws Exception {
|
||||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens1.kt");
|
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens1.kt");
|
||||||
@@ -7780,6 +7790,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens6.kt");
|
runTest("idea/testData/quickfix/expressions/removeUselessCastForLambdaInParens6.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeUselessCastInNestedParens.kt")
|
||||||
|
public void testRemoveUselessCastInNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/removeUselessCastInNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("removeUselessCastInParens.kt")
|
@TestMetadata("removeUselessCastInParens.kt")
|
||||||
public void testRemoveUselessCastInParens() throws Exception {
|
public void testRemoveUselessCastInParens() throws Exception {
|
||||||
runTest("idea/testData/quickfix/expressions/removeUselessCastInParens.kt");
|
runTest("idea/testData/quickfix/expressions/removeUselessCastInParens.kt");
|
||||||
@@ -7880,6 +7895,21 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/expressions/uselessElvis.kt");
|
runTest("idea/testData/quickfix/expressions/uselessElvis.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("uselessElvisForLambdaInNecessaryNestedParens.kt")
|
||||||
|
public void testUselessElvisForLambdaInNecessaryNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/uselessElvisForLambdaInNecessaryNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("uselessElvisForLambdaInNestedParens.kt")
|
||||||
|
public void testUselessElvisForLambdaInNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/uselessElvisForLambdaInNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("uselessElvisInNestedParens.kt")
|
||||||
|
public void testUselessElvisInNestedParens() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/uselessElvisInNestedParens.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("uselessElvisRightIsNull.kt")
|
@TestMetadata("uselessElvisRightIsNull.kt")
|
||||||
public void testUselessElvisRightIsNull() throws Exception {
|
public void testUselessElvisRightIsNull() throws Exception {
|
||||||
runTest("idea/testData/quickfix/expressions/uselessElvisRightIsNull.kt");
|
runTest("idea/testData/quickfix/expressions/uselessElvisRightIsNull.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user