From b9e248b00666c10deb56bd8c90bd3749d59a9217 Mon Sep 17 00:00:00 2001 From: Tal Man Date: Fri, 28 Mar 2014 23:21:20 -0400 Subject: [PATCH] Intention for removing explicit type arguments at function calls --- .../jet/generators/tests/GenerateTests.kt | 1 + .../after.kt.template | 3 + .../before.kt.template | 3 + .../description.html | 5 ++ idea/src/META-INF/plugin.xml | 5 ++ .../jetbrains/jet/plugin/JetBundle.properties | 3 +- .../intentions/RemoveExplicitTypeArguments.kt | 86 +++++++++++++++++++ .../fourLiterals.kt | 6 ++ .../fourLiterals.kt.after | 6 ++ ...licableTypeThatIsAFunItCannotBeInferred.kt | 8 ++ .../removeExplicitTypeArguments/lambdaType.kt | 6 ++ .../lambdaType.kt.after | 6 ++ .../removeExplicitTypeArguments/literalAny.kt | 8 ++ .../literalAny.kt.after | 8 ++ .../literalString.kt | 6 ++ .../literalString.kt.after | 6 ++ .../literalStringWithClass.kt | 8 ++ .../literalStringWithClass.kt.after | 8 ++ .../literalsWhenTypeArgHasTypeArg.kt | 8 ++ .../literalsWhenTypeArgHasTypeArg.kt.after | 8 ++ .../notApplicableNotEnoughtInfo.kt | 7 ++ .../notApplicableSupertypeOfInferred.kt | 6 ++ .../notApplicableSupertypeOfInferredClass.kt | 8 ++ .../twoLiteralValues.kt | 6 ++ .../twoLiteralValues.kt.after | 6 ++ .../variableString.kt | 7 ++ .../variableString.kt.after | 7 ++ .../variableString2.kt | 6 ++ .../variableString2.kt.after | 6 ++ .../variableStringFartherScope.kt | 8 ++ .../variableStringFartherScope.kt.after | 8 ++ .../variablesAndLiterals.kt | 8 ++ .../variablesAndLiterals.kt.after | 8 ++ .../AbstractCodeTransformationTest.java | 6 ++ .../CodeTransformationTestGenerated.java | 86 ++++++++++++++++++- 35 files changed, 379 insertions(+), 2 deletions(-) create mode 100644 idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/after.kt.template create mode 100644 idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/before.kt.template create mode 100644 idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/description.html create mode 100644 idea/src/org/jetbrains/jet/plugin/intentions/RemoveExplicitTypeArguments.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/fourLiterals.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/fourLiterals.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/inapplicableTypeThatIsAFunItCannotBeInferred.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/literalString.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/literalString.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/notApplicableNotEnoughtInfo.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferred.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferredClass.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/variableString.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/variableString.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt.after create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt create mode 100644 idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt.after diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index 141d24b9652..e4129b335a1 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -391,6 +391,7 @@ fun main(args: Array) { model("intentions/replaceWithTraditionalAssignment", testMethod = "doTestReplaceWithTraditionalAssignment") model("intentions/simplifyBooleanWithConstants", testMethod = "doTestSimplifyBooleanWithConstants") model("intentions/insertExplicitTypeArguments", testMethod = "doTestInsertExplicitTypeArguments") + model("intentions/removeExplicitTypeArguments", testMethod = "doTestRemoveExplicitTypeArguments") } testClass(javaClass()) { diff --git a/idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/after.kt.template b/idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/after.kt.template new file mode 100644 index 00000000000..e0f5946e400 --- /dev/null +++ b/idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/after.kt.template @@ -0,0 +1,3 @@ +fun foo() { + val x = X("x") +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/before.kt.template b/idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/before.kt.template new file mode 100644 index 00000000000..66a89641e51 --- /dev/null +++ b/idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/before.kt.template @@ -0,0 +1,3 @@ +fun foo() { + val x = X("x") +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/description.html b/idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/description.html new file mode 100644 index 00000000000..4842753ba52 --- /dev/null +++ b/idea/resources/intentionDescriptions/RemoveExplicitTypeArguments/description.html @@ -0,0 +1,5 @@ + + +This intention removes type arguments from function calls when they can be implicitly inferred + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 6d7c4686e3c..768a59f4932 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -553,6 +553,11 @@ Kotlin + + org.jetbrains.jet.plugin.intentions.RemoveExplicitTypeArguments + Kotlin + + org.jetbrains.jet.plugin.intentions.RemoveCurlyBracesFromTemplateIntention Kotlin diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index 14b1c7008ee..8fe5622e72e 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -295,7 +295,8 @@ simplify.boolean.with.constants=Simplify boolean expression simplify.boolean.with.constants.family=Simplify boolean expression insert.explicit.type.arguments=Add explicit type arguments insert.explicit.type.arguments.family=Add explicit type arguments ->>>>>>> Intention for adding explicit type arguments at function calls +remove.explicit.type.arguments=Remove explicit type arguments +remove.explicit.type.arguments.family=Remove explicit type arguments property.is.implemented.too.many=Has implementations property.is.overridden.too.many=Is overridden in subclasses diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/RemoveExplicitTypeArguments.kt b/idea/src/org/jetbrains/jet/plugin/intentions/RemoveExplicitTypeArguments.kt new file mode 100644 index 00000000000..cbdc15fd293 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/RemoveExplicitTypeArguments.kt @@ -0,0 +1,86 @@ +/* + * 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.intentions + +import com.intellij.openapi.editor.Editor +import org.jetbrains.jet.lang.psi.JetCallExpression +import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache +import org.jetbrains.jet.lang.resolve.BindingContext +import org.jetbrains.jet.lang.psi.JetPsiFactory +import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace +import org.jetbrains.jet.lang.resolve.calls.util.DelegatingCall +import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo +import org.jetbrains.jet.lang.types.TypeUtils +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor +import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults +import org.jetbrains.jet.lang.resolve.scopes.JetScope +import org.jetbrains.jet.lang.psi.JetTypeProjection +import org.jetbrains.jet.lang.psi.Call +import java.util.ArrayList +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.di.InjectorForMacros +import org.jetbrains.jet.lang.resolve.BindingTraceContext + +public class RemoveExplicitTypeArguments : JetSelfTargetingIntention( + "remove.explicit.type.arguments", javaClass()) { + + override fun isApplicableTo(element: JetCallExpression): Boolean { + + val context = AnalyzerFacadeWithCache.getContextForElement(element) + if (element.getTypeArguments().isEmpty()) return false + + val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile((element.getContainingFile() as JetFile)) + val injector = InjectorForMacros(element.getProject(), resolveSession.getModuleDescriptor()) + + val scope = context[BindingContext.RESOLUTION_SCOPE, element] + val originalCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()]?.getCall() + if (originalCall == null || scope !is JetScope) return false + val untypedCall = CallWithoutTypeArgs(originalCall) + + val jType = context[BindingContext.EXPECTED_EXPRESSION_TYPE, element] ?: TypeUtils.NO_EXPECTED_TYPE + val dataFlow = context[BindingContext.EXPRESSION_DATA_FLOW_INFO, element] ?: DataFlowInfo.EMPTY + val resolvedCall = injector.getExpressionTypingServices()?.getCallResolver()?.resolveFunctionCall( + BindingTraceContext(), scope, untypedCall, jType, dataFlow, false) + + val args = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()]?.getTypeArguments() + val newArgs = resolvedCall?.getResultingCall()?.getTypeArguments() + + return args == newArgs + } + + class CallWithoutTypeArgs(call: Call) : DelegatingCall(call) { + + override fun getTypeArguments(): MutableList { + return ArrayList() + } + + override fun getTypeArgumentList() = null + + } + + override fun applyTo(element: JetCallExpression, editor: Editor) { + val text = element.getText() + val typeArgs = element.getTypeArgumentList() + if (text == null || typeArgs == null) return + val base = typeArgs.getTextOffset() - element.getTextOffset() + val untypedText = "${text.substring(0, base)}${text.substring(base + typeArgs.getTextLength())}" + element.replace(JetPsiFactory.createExpression(element.getProject(), untypedText)) + } +} + + + diff --git a/idea/testData/intentions/removeExplicitTypeArguments/fourLiterals.kt b/idea/testData/intentions/removeExplicitTypeArguments/fourLiterals.kt new file mode 100644 index 00000000000..dde2eabe069 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/fourLiterals.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo() { + val z = bar("1", 1, 2, "x") +} + +fun bar(t: T, v: V, r: R, k: K): Int = 2 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/fourLiterals.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/fourLiterals.kt.after new file mode 100644 index 00000000000..16df8e6bf22 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/fourLiterals.kt.after @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo() { + val z = bar("1", 1, 2, "x") +} + +fun bar(t: T, v: V, r: R, k: K): Int = 2 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/inapplicableTypeThatIsAFunItCannotBeInferred.kt b/idea/testData/intentions/removeExplicitTypeArguments/inapplicableTypeThatIsAFunItCannotBeInferred.kt new file mode 100644 index 00000000000..859f3ecee61 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/inapplicableTypeThatIsAFunItCannotBeInferred.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false +fun foo() { + bar<(Int) -> Int>({ baz(it) }) +} + +fun baz(x: Int): Int = x + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt b/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt new file mode 100644 index 00000000000..ab238ee3765 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo() { + bar<(Int) -> Int> { (it:Int) -> it } +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt.after new file mode 100644 index 00000000000..9827ee7b7de --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt.after @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo() { + bar {(it: Int) -> it } +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt b/idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt new file mode 100644 index 00000000000..a424eb1e860 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +fun foo() { + val x = Box(Any()) +} + +class Box(t : T) { + var value = t +} \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt.after new file mode 100644 index 00000000000..3eb7b6b324c --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt.after @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +fun foo() { + val x = Box(Any()) +} + +class Box(t : T) { + var value = t +} \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt b/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt new file mode 100644 index 00000000000..de8dfc5c7de --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo() { + bar("x") +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt.after new file mode 100644 index 00000000000..ee0866d36e4 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt.after @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo() { + bar("x") +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt b/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt new file mode 100644 index 00000000000..239de68353f --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +fun foo() { + val x = Box("x") +} + +class Box(t : T) { + var value = t +} \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt.after new file mode 100644 index 00000000000..003baa3ebb7 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt.after @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +fun foo() { + val x = Box("x") +} + +class Box(t : T) { + var value = t +} \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt b/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt new file mode 100644 index 00000000000..876e324feeb --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +fun foo() { + val x = Box>(Box("x")) +} + +class Box(t : T) { + var value = t +} \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt.after new file mode 100644 index 00000000000..191dc24d3e1 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt.after @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +fun foo() { + val x = Box(Box("x")) +} + +class Box(t : T) { + var value = t +} \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/notApplicableNotEnoughtInfo.kt b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableNotEnoughtInfo.kt new file mode 100644 index 00000000000..111325588bd --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableNotEnoughtInfo.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: false +// ERROR: Unresolved reference: LinkedList +fun foo() { + val x = bar() +} + +fun bar() : List = LinkedList(); \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferred.kt b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferred.kt new file mode 100644 index 00000000000..b412a0635cb --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferred.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: false +fun foo() { + val x = bar("x") +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferredClass.kt b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferredClass.kt new file mode 100644 index 00000000000..4a9cf90b057 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferredClass.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false +fun foo() { + val x = Box("x") +} + +class Box(t : T) { + var value = t +} \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt b/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt new file mode 100644 index 00000000000..39a0a8592af --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo() { + val x = bar("x", 0) +} + +fun bar(t: T, v: V): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt.after new file mode 100644 index 00000000000..f81cbd23dc1 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt.after @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo() { + val x = bar("x", 0) +} + +fun bar(t: T, v: V): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/variableString.kt b/idea/testData/intentions/removeExplicitTypeArguments/variableString.kt new file mode 100644 index 00000000000..a3899de67cd --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/variableString.kt @@ -0,0 +1,7 @@ +// IS_APPLICABLE: true +fun foo() { + val x = "x" + bar(x) +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/variableString.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/variableString.kt.after new file mode 100644 index 00000000000..d00a006e5c0 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/variableString.kt.after @@ -0,0 +1,7 @@ +// IS_APPLICABLE: true +fun foo() { + val x = "x" + bar(x) +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt b/idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt new file mode 100644 index 00000000000..e7498d09a1c --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo(x: String) { + bar(x) +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt.after new file mode 100644 index 00000000000..52f8dcca266 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt.after @@ -0,0 +1,6 @@ +// IS_APPLICABLE: true +fun foo(x: String) { + bar(x) +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt b/idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt new file mode 100644 index 00000000000..e1c2defc593 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +val x = "x" + +fun foo() { + bar(x) +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt.after new file mode 100644 index 00000000000..bcb961e4827 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt.after @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +val x = "x" + +fun foo() { + bar(x) +} + +fun bar(t: T): Int = 1 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt b/idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt new file mode 100644 index 00000000000..846d53df886 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +fun foo() { + val x = "1" + val y = 2 + val z = bar(x, 1, y, "x") +} + +fun bar(t: T, v: V, r: R, k: K): Int = 2 \ No newline at end of file diff --git a/idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt.after new file mode 100644 index 00000000000..0e4e97d6a64 --- /dev/null +++ b/idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt.after @@ -0,0 +1,8 @@ +// IS_APPLICABLE: true +fun foo() { + val x = "1" + val y = 2 + val z = bar(x, 1, y, "x") +} + +fun bar(t: T, v: V, r: R, k: K): Int = 2 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java index 153cca5957f..24666e4ccfb 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java @@ -148,9 +148,15 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes public void doTestMoveLambdaOutsideParentheses(@NotNull String path) throws Exception { doTestIntention(path, new MoveLambdaOutsideParenthesesIntention()); } + public void doTestSwapBinaryExpression(@NotNull String path) throws Exception { doTestIntention(path, new SwapBinaryExpression()); } + + public void doTestRemoveExplicitTypeArguments(@NotNull String path) throws Exception { + doTestIntention(path, new RemoveExplicitTypeArguments()); + } + public void doTestConvertMemberToExtension(@NotNull String path) throws Exception { doTestIntention(path, new ConvertMemberToExtension()); } diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java index 234432a2138..ecb9ef564b6 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java @@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@InnerTestClasses({CodeTransformationTestGenerated.ElvisToIfThen.class, CodeTransformationTestGenerated.IfThenToElvis.class, CodeTransformationTestGenerated.SafeAccessToIfThen.class, CodeTransformationTestGenerated.IfThenToSafeAccess.class, CodeTransformationTestGenerated.IfToAssignment.class, CodeTransformationTestGenerated.IfToReturn.class, CodeTransformationTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationTestGenerated.WhenToAssignment.class, CodeTransformationTestGenerated.WhenToReturn.class, CodeTransformationTestGenerated.AssignmentToIf.class, CodeTransformationTestGenerated.AssignmentToWhen.class, CodeTransformationTestGenerated.PropertyToIf.class, CodeTransformationTestGenerated.PropertyToWhen.class, CodeTransformationTestGenerated.ReturnToIf.class, CodeTransformationTestGenerated.ReturnToWhen.class, CodeTransformationTestGenerated.IfToWhen.class, CodeTransformationTestGenerated.WhenToIf.class, CodeTransformationTestGenerated.Flatten.class, CodeTransformationTestGenerated.Merge.class, CodeTransformationTestGenerated.IntroduceSubject.class, CodeTransformationTestGenerated.EliminateSubject.class, CodeTransformationTestGenerated.Split.class, CodeTransformationTestGenerated.Join.class, CodeTransformationTestGenerated.ConvertMemberToExtension.class, CodeTransformationTestGenerated.ReconstructedType.class, CodeTransformationTestGenerated.RemoveUnnecessaryParentheses.class, CodeTransformationTestGenerated.ReplaceWithDotQualifiedMethodCall.class, CodeTransformationTestGenerated.ReplaceWithInfixFunctionCall.class, CodeTransformationTestGenerated.RemoveCurlyBracesFromTemplate.class, CodeTransformationTestGenerated.MoveLambdaInsideParentheses.class, CodeTransformationTestGenerated.MoveLambdaOutsideParentheses.class, CodeTransformationTestGenerated.ReplaceExplicitFunctionLiteralParamWithIt.class, CodeTransformationTestGenerated.ReplaceItWithExplicitFunctionLiteralParam.class, CodeTransformationTestGenerated.RemoveBraces.class, CodeTransformationTestGenerated.AddBraces.class, CodeTransformationTestGenerated.ReplaceGetIntention.class, CodeTransformationTestGenerated.ReplaceContainsIntention.class, CodeTransformationTestGenerated.ReplaceBinaryInfixIntention.class, CodeTransformationTestGenerated.ReplaceUnaryPrefixIntention.class, CodeTransformationTestGenerated.ReplaceInvokeIntention.class, CodeTransformationTestGenerated.SimplifyNegatedBinaryExpressionIntention.class, CodeTransformationTestGenerated.ConvertNegatedBooleanSequence.class, CodeTransformationTestGenerated.ConvertNegatedExpressionWithDemorgansLaw.class, CodeTransformationTestGenerated.SwapBinaryExpression.class, CodeTransformationTestGenerated.SplitIf.class, CodeTransformationTestGenerated.ReplaceWithOperatorAssign.class, CodeTransformationTestGenerated.ReplaceWithTraditionalAssignment.class, CodeTransformationTestGenerated.SimplifyBooleanWithConstants.class, CodeTransformationTestGenerated.InsertExplicitTypeArguments.class}) +@InnerTestClasses({CodeTransformationTestGenerated.ElvisToIfThen.class, CodeTransformationTestGenerated.IfThenToElvis.class, CodeTransformationTestGenerated.SafeAccessToIfThen.class, CodeTransformationTestGenerated.IfThenToSafeAccess.class, CodeTransformationTestGenerated.IfToAssignment.class, CodeTransformationTestGenerated.IfToReturn.class, CodeTransformationTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationTestGenerated.WhenToAssignment.class, CodeTransformationTestGenerated.WhenToReturn.class, CodeTransformationTestGenerated.AssignmentToIf.class, CodeTransformationTestGenerated.AssignmentToWhen.class, CodeTransformationTestGenerated.PropertyToIf.class, CodeTransformationTestGenerated.PropertyToWhen.class, CodeTransformationTestGenerated.ReturnToIf.class, CodeTransformationTestGenerated.ReturnToWhen.class, CodeTransformationTestGenerated.IfToWhen.class, CodeTransformationTestGenerated.WhenToIf.class, CodeTransformationTestGenerated.Flatten.class, CodeTransformationTestGenerated.Merge.class, CodeTransformationTestGenerated.IntroduceSubject.class, CodeTransformationTestGenerated.EliminateSubject.class, CodeTransformationTestGenerated.Split.class, CodeTransformationTestGenerated.Join.class, CodeTransformationTestGenerated.ConvertMemberToExtension.class, CodeTransformationTestGenerated.ReconstructedType.class, CodeTransformationTestGenerated.RemoveUnnecessaryParentheses.class, CodeTransformationTestGenerated.ReplaceWithDotQualifiedMethodCall.class, CodeTransformationTestGenerated.ReplaceWithInfixFunctionCall.class, CodeTransformationTestGenerated.RemoveCurlyBracesFromTemplate.class, CodeTransformationTestGenerated.MoveLambdaInsideParentheses.class, CodeTransformationTestGenerated.MoveLambdaOutsideParentheses.class, CodeTransformationTestGenerated.ReplaceExplicitFunctionLiteralParamWithIt.class, CodeTransformationTestGenerated.ReplaceItWithExplicitFunctionLiteralParam.class, CodeTransformationTestGenerated.RemoveBraces.class, CodeTransformationTestGenerated.AddBraces.class, CodeTransformationTestGenerated.ReplaceGetIntention.class, CodeTransformationTestGenerated.ReplaceContainsIntention.class, CodeTransformationTestGenerated.ReplaceBinaryInfixIntention.class, CodeTransformationTestGenerated.ReplaceUnaryPrefixIntention.class, CodeTransformationTestGenerated.ReplaceInvokeIntention.class, CodeTransformationTestGenerated.SimplifyNegatedBinaryExpressionIntention.class, CodeTransformationTestGenerated.ConvertNegatedBooleanSequence.class, CodeTransformationTestGenerated.ConvertNegatedExpressionWithDemorgansLaw.class, CodeTransformationTestGenerated.SwapBinaryExpression.class, CodeTransformationTestGenerated.SplitIf.class, CodeTransformationTestGenerated.ReplaceWithOperatorAssign.class, CodeTransformationTestGenerated.ReplaceWithTraditionalAssignment.class, CodeTransformationTestGenerated.SimplifyBooleanWithConstants.class, CodeTransformationTestGenerated.InsertExplicitTypeArguments.class, CodeTransformationTestGenerated.RemoveExplicitTypeArguments.class}) public class CodeTransformationTestGenerated extends AbstractCodeTransformationTest { @TestMetadata("idea/testData/intentions/branched/elvisToIfThen") public static class ElvisToIfThen extends AbstractCodeTransformationTest { @@ -3427,6 +3427,89 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT } + @TestMetadata("idea/testData/intentions/removeExplicitTypeArguments") + 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); + } + + @TestMetadata("fourLiterals.kt") + public void testFourLiterals() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/fourLiterals.kt"); + } + + @TestMetadata("inapplicableTypeThatIsAFunItCannotBeInferred.kt") + public void testInapplicableTypeThatIsAFunItCannotBeInferred() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/inapplicableTypeThatIsAFunItCannotBeInferred.kt"); + } + + @TestMetadata("lambdaType.kt") + public void testLambdaType() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt"); + } + + @TestMetadata("literalAny.kt") + public void testLiteralAny() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt"); + } + + @TestMetadata("literalString.kt") + public void testLiteralString() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/literalString.kt"); + } + + @TestMetadata("literalStringWithClass.kt") + public void testLiteralStringWithClass() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt"); + } + + @TestMetadata("literalsWhenTypeArgHasTypeArg.kt") + public void testLiteralsWhenTypeArgHasTypeArg() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt"); + } + + @TestMetadata("notApplicableNotEnoughtInfo.kt") + public void testNotApplicableNotEnoughtInfo() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/notApplicableNotEnoughtInfo.kt"); + } + + @TestMetadata("notApplicableSupertypeOfInferred.kt") + public void testNotApplicableSupertypeOfInferred() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferred.kt"); + } + + @TestMetadata("notApplicableSupertypeOfInferredClass.kt") + public void testNotApplicableSupertypeOfInferredClass() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferredClass.kt"); + } + + @TestMetadata("twoLiteralValues.kt") + public void testTwoLiteralValues() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt"); + } + + @TestMetadata("variableString.kt") + public void testVariableString() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/variableString.kt"); + } + + @TestMetadata("variableString2.kt") + public void testVariableString2() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt"); + } + + @TestMetadata("variableStringFartherScope.kt") + public void testVariableStringFartherScope() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt"); + } + + @TestMetadata("variablesAndLiterals.kt") + public void testVariablesAndLiterals() throws Exception { + doTestRemoveExplicitTypeArguments("idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt"); + } + + } + public static Test suite() { TestSuite suite = new TestSuite("CodeTransformationTestGenerated"); suite.addTestSuite(ElvisToIfThen.class); @@ -3478,6 +3561,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT suite.addTestSuite(ReplaceWithTraditionalAssignment.class); suite.addTestSuite(SimplifyBooleanWithConstants.class); suite.addTestSuite(InsertExplicitTypeArguments.class); + suite.addTestSuite(RemoveExplicitTypeArguments.class); return suite; } }