From ab2ca539fe83a4ae68f4c13dda98373cc400f683 Mon Sep 17 00:00:00 2001 From: Tal Man Date: Thu, 1 May 2014 10:22:34 -0400 Subject: [PATCH] Inspection to report explicit type arguments that can be removed from function calls --- .../RemoveExplicitTypeArgs.html | 5 + idea/src/META-INF/plugin.xml | 8 +- .../RemoveExplicitTypeArgsInspection.kt | 22 ++++ .../inspectionData/expected.xml | 101 ++++++++++++++++++ .../inspectionData/inspections.test | 1 + .../JetInspectionTestGenerated.java | 5 + .../CodeTransformationTestGenerated.java | 9 +- 7 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 idea/resources/inspectionDescriptions/RemoveExplicitTypeArgs.html create mode 100644 idea/src/org/jetbrains/jet/plugin/inspections/RemoveExplicitTypeArgsInspection.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/inspectionData/expected.xml create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/inspectionData/inspections.test diff --git a/idea/resources/inspectionDescriptions/RemoveExplicitTypeArgs.html b/idea/resources/inspectionDescriptions/RemoveExplicitTypeArgs.html new file mode 100644 index 00000000000..869aea11393 --- /dev/null +++ b/idea/resources/inspectionDescriptions/RemoveExplicitTypeArgs.html @@ -0,0 +1,5 @@ + + +This inspection reports any function call wiith type arguments that can be safely removed and inferred + + diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 850f7b2eb7d..633746d1417 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -655,7 +655,6 @@ org.jetbrains.jet.plugin.intentions.SimplifyBooleanWithConstantsIntention Kotlin - org.jetbrains.jet.plugin.intentions.SwapBinaryExpression @@ -718,6 +717,13 @@ level="WARNING" /> + + diff --git a/idea/src/org/jetbrains/jet/plugin/inspections/RemoveExplicitTypeArgsInspection.kt b/idea/src/org/jetbrains/jet/plugin/inspections/RemoveExplicitTypeArgsInspection.kt new file mode 100644 index 00000000000..3b2daffa5c2 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/inspections/RemoveExplicitTypeArgsInspection.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.inspections + +import org.jetbrains.jet.plugin.intentions.RemoveExplicitTypeArguments +import org.jetbrains.jet.lang.psi.JetCallExpression + +public class RemoveExplicitTypeArgsInspection : IntentionBasedInspection(RemoveExplicitTypeArguments()) diff --git a/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/expected.xml b/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/expected.xml new file mode 100644 index 00000000000..4d264d64d72 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/expected.xml @@ -0,0 +1,101 @@ + + + variableStringFartherScope.kt + 5 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + fourLiterals.kt + 3 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + literalStringWithClass.kt + 3 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + lambdaType.kt + 3 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + literalAny.kt + 3 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + literalString.kt + 3 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + variablesAndLiterals.kt + 5 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + literalsWhenTypeArgHasTypeArg.kt + 3 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + variableString.kt + 4 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + variableString2.kt + 3 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + + twoLiteralValues.kt + 3 + light_idea_test_case + + Type arguments are unnecessary + Remove explicit type arguments + + + \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/inspections.test b/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/inspections.test new file mode 100644 index 00000000000..d174e685ea5 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/inspectionData/inspections.test @@ -0,0 +1 @@ +// INSPECTION_CLASS: org.jetbrains.jet.plugin.inspections.RemoveExplicitTypeArgsInspection \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java index f19fe976751..a7fd8694937 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/JetInspectionTestGenerated.java @@ -51,4 +51,9 @@ public class JetInspectionTestGenerated extends AbstractJetInspectionTest { doTest("idea/testData/intentions/branched/ifThenToSafeAccess/inspectionData/inspections.test"); } + @TestMetadata("removeExplicitTypeArguments/inspectionData/inspections.test") + public void testRemoveExplicitTypeArguments_inspectionData_Inspections_test() throws Exception { + doTest("idea/testData/intentions/removeExplicitTypeArguments/inspectionData/inspections.test"); + } + } diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java index 4aa336609be..74ba43ff25f 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java @@ -7,6 +7,7 @@ * * http://www.apache.org/licenses/LICENSE-2.0 * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -3719,6 +3720,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT } @TestMetadata("idea/testData/intentions/removeExplicitTypeArguments") + @InnerTestClasses({}) public static class RemoveExplicitTypeArguments extends AbstractCodeTransformationTest { public void testAllFilesPresentInRemoveExplicitTypeArguments() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions/removeExplicitTypeArguments"), Pattern.compile("^(.+)\\.kt$"), true); @@ -3799,6 +3801,11 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt"); } + public static Test innerSuite() { + TestSuite suite = new TestSuite("RemoveExplicitTypeArguments"); + suite.addTestSuite(RemoveExplicitTypeArguments.class); + return suite; + } } @TestMetadata("idea/testData/intentions/convertAssertToIf") @@ -4171,7 +4178,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT suite.addTestSuite(ReplaceWithTraditionalAssignment.class); suite.addTestSuite(SimplifyBooleanWithConstants.class); suite.addTestSuite(InsertExplicitTypeArguments.class); - suite.addTestSuite(RemoveExplicitTypeArguments.class); + suite.addTest(RemoveExplicitTypeArguments.innerSuite()); suite.addTestSuite(ConvertAssertToIf.class); suite.addTestSuite(ConvertIfToAssert.class); suite.addTestSuite(MakeTypeExplicitInLambda.class);