From 71a5e09a0bfa0155ef1e641ee9ac73dc8a3e08e2 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Fri, 13 Mar 2015 20:17:56 +0300 Subject: [PATCH] Quick-Fixes: Support USELESS_CAST diagnostic in "Remove cast" quick-fix #KT-6422 Fixed --- .../idea/quickfix/QuickFixRegistrar.java | 1 + .../expressions/afterRemoveUselessCast.kt | 4 +++ .../afterRemoveUselessCastUnderSmartCast.kt | 7 ++++ ...fterReplaceUselessCastWithStaticAssert.kt} | 0 .../expressions/beforeRemoveUselessCast.kt | 4 +++ .../beforeRemoveUselessCastUnderSmartCast.kt | 7 ++++ ...foreReplaceUselessCastWithStaticAssert.kt} | 0 ...eturn.kt => afterNonLocalReturnRuntime.kt} | 0 ...=> afterNonLocalReturnWithLabelRuntime.kt} | 0 ...turn.kt => beforeNonLocalReturnRuntime.kt} | 0 ...> beforeNonLocalReturnWithLabelRuntime.kt} | 0 .../idea/quickfix/QuickFixTestGenerated.java | 36 ++++++++++++------- 12 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 idea/testData/quickfix/expressions/afterRemoveUselessCast.kt create mode 100644 idea/testData/quickfix/expressions/afterRemoveUselessCastUnderSmartCast.kt rename idea/testData/quickfix/expressions/{afterUselessCast.kt => afterReplaceUselessCastWithStaticAssert.kt} (100%) create mode 100644 idea/testData/quickfix/expressions/beforeRemoveUselessCast.kt create mode 100644 idea/testData/quickfix/expressions/beforeRemoveUselessCastUnderSmartCast.kt rename idea/testData/quickfix/expressions/{beforeUselessCast.kt => beforeReplaceUselessCastWithStaticAssert.kt} (100%) rename idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/{afterNonLocalReturn.kt => afterNonLocalReturnRuntime.kt} (100%) rename idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/{afterNonLocalReturnWithLabel.kt => afterNonLocalReturnWithLabelRuntime.kt} (100%) rename idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/{beforeNonLocalReturn.kt => beforeNonLocalReturnRuntime.kt} (100%) rename idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/{beforeNonLocalReturnWithLabel.kt => beforeNonLocalReturnWithLabelRuntime.kt} (100%) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java index fb2b6e6b70c..f2b771605b7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java @@ -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); diff --git a/idea/testData/quickfix/expressions/afterRemoveUselessCast.kt b/idea/testData/quickfix/expressions/afterRemoveUselessCast.kt new file mode 100644 index 00000000000..9a446bec737 --- /dev/null +++ b/idea/testData/quickfix/expressions/afterRemoveUselessCast.kt @@ -0,0 +1,4 @@ +// "Remove cast" "true" +fun foo(a: String) { + val b = a +} diff --git a/idea/testData/quickfix/expressions/afterRemoveUselessCastUnderSmartCast.kt b/idea/testData/quickfix/expressions/afterRemoveUselessCastUnderSmartCast.kt new file mode 100644 index 00000000000..8fc23d973e2 --- /dev/null +++ b/idea/testData/quickfix/expressions/afterRemoveUselessCastUnderSmartCast.kt @@ -0,0 +1,7 @@ +// "Remove cast" "true" +fun test(x: Any): String? { + if (x is String) { + return x + } + return null +} diff --git a/idea/testData/quickfix/expressions/afterUselessCast.kt b/idea/testData/quickfix/expressions/afterReplaceUselessCastWithStaticAssert.kt similarity index 100% rename from idea/testData/quickfix/expressions/afterUselessCast.kt rename to idea/testData/quickfix/expressions/afterReplaceUselessCastWithStaticAssert.kt diff --git a/idea/testData/quickfix/expressions/beforeRemoveUselessCast.kt b/idea/testData/quickfix/expressions/beforeRemoveUselessCast.kt new file mode 100644 index 00000000000..9fc01d92119 --- /dev/null +++ b/idea/testData/quickfix/expressions/beforeRemoveUselessCast.kt @@ -0,0 +1,4 @@ +// "Remove cast" "true" +fun foo(a: String) { + val b = a as Any +} diff --git a/idea/testData/quickfix/expressions/beforeRemoveUselessCastUnderSmartCast.kt b/idea/testData/quickfix/expressions/beforeRemoveUselessCastUnderSmartCast.kt new file mode 100644 index 00000000000..49890c41610 --- /dev/null +++ b/idea/testData/quickfix/expressions/beforeRemoveUselessCastUnderSmartCast.kt @@ -0,0 +1,7 @@ +// "Remove cast" "true" +fun test(x: Any): String? { + if (x is String) { + return x as String + } + return null +} diff --git a/idea/testData/quickfix/expressions/beforeUselessCast.kt b/idea/testData/quickfix/expressions/beforeReplaceUselessCastWithStaticAssert.kt similarity index 100% rename from idea/testData/quickfix/expressions/beforeUselessCast.kt rename to idea/testData/quickfix/expressions/beforeReplaceUselessCastWithStaticAssert.kt diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterNonLocalReturn.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterNonLocalReturnRuntime.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterNonLocalReturn.kt rename to idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterNonLocalReturnRuntime.kt diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterNonLocalReturnWithLabel.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterNonLocalReturnWithLabelRuntime.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterNonLocalReturnWithLabel.kt rename to idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterNonLocalReturnWithLabelRuntime.kt diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturn.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturnRuntime.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturn.kt rename to idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturnRuntime.kt diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturnWithLabel.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturnWithLabelRuntime.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturnWithLabel.kt rename to idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeNonLocalReturnWithLabelRuntime.kt diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index d7fe78d0b4d..67240ea7412 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -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); }