Quick-Fixes: Support USELESS_CAST diagnostic in "Remove cast" quick-fix

#KT-6422 Fixed
This commit is contained in:
Alexey Sedunov
2015-03-13 20:17:56 +03:00
parent f5107be315
commit 71a5e09a0b
12 changed files with 47 additions and 12 deletions
@@ -87,6 +87,7 @@ public class QuickFixRegistrar {
QuickFixes.factories.put(USELESS_CAST_STATIC_ASSERT_IS_FINE, ReplaceOperationInBinaryExpressionFix.createChangeCastToStaticAssertFactory());
QuickFixes.factories.put(USELESS_CAST, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
QuickFixes.factories.put(USELESS_CAST_STATIC_ASSERT_IS_FINE, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
JetSingleIntentionActionFactory changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
QuickFixes.factories.put(WRONG_SETTER_PARAMETER_TYPE, changeAccessorTypeFactory);
@@ -0,0 +1,4 @@
// "Remove cast" "true"
fun foo(a: String) {
val b = a
}
@@ -0,0 +1,7 @@
// "Remove cast" "true"
fun test(x: Any): String? {
if (x is String) {
return x
}
return null
}
@@ -0,0 +1,4 @@
// "Remove cast" "true"
fun foo(a: String) {
val b = a <caret>as Any
}
@@ -0,0 +1,7 @@
// "Remove cast" "true"
fun test(x: Any): String? {
if (x is String) {
return x <caret>as String
}
return null
}
@@ -2825,6 +2825,24 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("beforeRemoveUselessCast.kt")
public void testRemoveUselessCast() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeRemoveUselessCast.kt");
doTest(fileName);
}
@TestMetadata("beforeRemoveUselessCastUnderSmartCast.kt")
public void testRemoveUselessCastUnderSmartCast() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeRemoveUselessCastUnderSmartCast.kt");
doTest(fileName);
}
@TestMetadata("beforeReplaceUselessCastWithStaticAssert.kt")
public void testReplaceUselessCastWithStaticAssert() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeReplaceUselessCastWithStaticAssert.kt");
doTest(fileName);
}
@TestMetadata("beforeUnnecessaryNonNullAssertion1.kt")
public void testUnnecessaryNonNullAssertion1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeUnnecessaryNonNullAssertion1.kt");
@@ -2867,12 +2885,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("beforeUselessCast.kt")
public void testUselessCast() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeUselessCast.kt");
doTest(fileName);
}
@TestMetadata("beforeUselessCastStaticAssertIsFine.kt")
public void testUselessCastStaticAssertIsFine() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeUselessCastStaticAssertIsFine.kt");
@@ -4954,15 +4966,15 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("beforeNonLocalReturn.kt")
public void testNonLocalReturn() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturn.kt");
@TestMetadata("beforeNonLocalReturnRuntime.kt")
public void testNonLocalReturnRuntime() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturnRuntime.kt");
doTest(fileName);
}
@TestMetadata("beforeNonLocalReturnWithLabel.kt")
public void testNonLocalReturnWithLabel() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturnWithLabel.kt");
@TestMetadata("beforeNonLocalReturnWithLabelRuntime.kt")
public void testNonLocalReturnWithLabelRuntime() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturnWithLabelRuntime.kt");
doTest(fileName);
}