diff --git a/idea/src/org/jetbrains/jet/plugin/inspections/RemoveExplicitTypeArgsInspection.kt b/idea/src/org/jetbrains/jet/plugin/inspections/RemoveExplicitTypeArgsInspection.kt index 3b2daffa5c2..3bd1e3a6d0b 100644 --- a/idea/src/org/jetbrains/jet/plugin/inspections/RemoveExplicitTypeArgsInspection.kt +++ b/idea/src/org/jetbrains/jet/plugin/inspections/RemoveExplicitTypeArgsInspection.kt @@ -17,6 +17,6 @@ package org.jetbrains.jet.plugin.inspections import org.jetbrains.jet.plugin.intentions.RemoveExplicitTypeArguments -import org.jetbrains.jet.lang.psi.JetCallExpression +import org.jetbrains.jet.lang.psi.JetTypeArgumentList -public class RemoveExplicitTypeArgsInspection : IntentionBasedInspection(RemoveExplicitTypeArguments()) +public class RemoveExplicitTypeArgsInspection : IntentionBasedInspection(RemoveExplicitTypeArguments()) diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/RemoveExplicitTypeArguments.kt b/idea/src/org/jetbrains/jet/plugin/intentions/RemoveExplicitTypeArguments.kt index 35739c463d7..d9067918d06 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/RemoveExplicitTypeArguments.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/RemoveExplicitTypeArguments.kt @@ -20,7 +20,6 @@ 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.calls.util.DelegatingCall import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo import org.jetbrains.jet.lang.types.TypeUtils @@ -37,20 +36,23 @@ import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.jet.lang.psi.JetReturnExpression import org.jetbrains.jet.lang.psi.JetDeclaration import org.jetbrains.jet.lang.psi.JetDeclarationWithBody +import com.intellij.psi.util.PsiTreeUtil -public class RemoveExplicitTypeArguments : JetSelfTargetingIntention( +public class RemoveExplicitTypeArguments : JetSelfTargetingIntention( "remove.explicit.type.arguments", javaClass()) { - override fun isApplicableTo(element: JetCallExpression): Boolean { + override fun isApplicableTo(element: JetTypeArgumentList): Boolean { + val callExpression = element.getParent() + if (callExpression !is JetCallExpression) return false - val context = AnalyzerFacadeWithCache.getContextForElement(element) - if (element.getTypeArguments().isEmpty()) return false + val context = AnalyzerFacadeWithCache.getContextForElement(callExpression) + if (callExpression.getTypeArguments().isEmpty()) return false - val resolveSession = element.getLazyResolveSession() - val injector = InjectorForMacros(element.getProject(), resolveSession.getModuleDescriptor()) + val resolveSession = callExpression.getLazyResolveSession() + val injector = InjectorForMacros(callExpression.getProject(), resolveSession.getModuleDescriptor()) - val scope = context[BindingContext.RESOLUTION_SCOPE, element] - val originalCall = context[BindingContext.RESOLVED_CALL, element.getCalleeExpression()]?.getCall() + val scope = context[BindingContext.RESOLUTION_SCOPE, callExpression] + val originalCall = context[BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression()]?.getCall() if (originalCall == null || scope !is JetScope) return false val untypedCall = CallWithoutTypeArgs(originalCall) @@ -58,8 +60,8 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntention parent.getInitializer() == callExpression && parent.getTypeRef() != null is JetDeclarationWithBody -> parent.getBodyExpression() == callExpression is JetReturnExpression -> true @@ -71,11 +73,11 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntentionbar("1", 1, 2, "x") + 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 index 859f3ecee61..0c358729509 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/inapplicableTypeThatIsAFunItCannotBeInferred.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/inapplicableTypeThatIsAFunItCannotBeInferred.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: false fun foo() { - bar<(Int) -> Int>({ baz(it) }) + bar<(Int) -> Int>({ baz(it) }) } fun baz(x: Int): Int = x diff --git a/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt b/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt index ab238ee3765..5194ae4609e 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: true fun foo() { - bar<(Int) -> Int> { (it:Int) -> it } + 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 index 9827ee7b7de..209981efb70 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt.after +++ b/idea/testData/intentions/removeExplicitTypeArguments/lambdaType.kt.after @@ -1,6 +1,6 @@ // IS_APPLICABLE: true fun foo() { - bar {(it: Int) -> it } + 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 index a424eb1e860..5615ca55810 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalAny.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: true fun foo() { - val x = Box(Any()) + val x = Box(Any()) } class Box(t : T) { diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt b/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt index de8dfc5c7de..e457ba564bb 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalString.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: true fun foo() { - bar("x") + 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 index 239de68353f..454aab50537 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: true fun foo() { - val x = Box("x") + val x = Box("x") } class Box(t : T) { diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt.after b/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt.after index 003baa3ebb7..3f0e1d222d2 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt.after +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalStringWithClass.kt.after @@ -1,6 +1,6 @@ // IS_APPLICABLE: true fun foo() { - val x = Box("x") + val x = Box("x") } class Box(t : T) { diff --git a/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt b/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt index 876e324feeb..91407cf2bd2 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/literalsWhenTypeArgHasTypeArg.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: true fun foo() { - val x = Box>(Box("x")) + val x = Box>(Box("x")) } class Box(t : T) { diff --git a/idea/testData/intentions/removeExplicitTypeArguments/notApplicableNotEnoughtInfo.kt b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableNotEnoughtInfo.kt index 111325588bd..c3a940a71fc 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/notApplicableNotEnoughtInfo.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableNotEnoughtInfo.kt @@ -1,7 +1,7 @@ // IS_APPLICABLE: false // ERROR: Unresolved reference: LinkedList fun foo() { - val x = bar() + 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 index b412a0635cb..870090562b7 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferred.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferred.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: false fun foo() { - val x = bar("x") + 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 index 4a9cf90b057..01e257578f9 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferredClass.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/notApplicableSupertypeOfInferredClass.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: false fun foo() { - val x = Box("x") + val x = Box("x") } class Box(t : T) { diff --git a/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt b/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt index 39a0a8592af..6f073a228c3 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/twoLiteralValues.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: true fun foo() { - val x = bar("x", 0) + 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 index a3899de67cd..117371cd4b9 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/variableString.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/variableString.kt @@ -1,7 +1,7 @@ // IS_APPLICABLE: true fun foo() { val x = "x" - bar(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 index e7498d09a1c..d8aaba0eab6 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/variableString2.kt @@ -1,6 +1,6 @@ // IS_APPLICABLE: true fun foo(x: String) { - bar(x) + 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 index e1c2defc593..f6f85d02be8 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/variableStringFartherScope.kt @@ -2,7 +2,7 @@ val x = "x" fun foo() { - bar(x) + 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 index 846d53df886..411eb4909b8 100644 --- a/idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt +++ b/idea/testData/intentions/removeExplicitTypeArguments/variablesAndLiterals.kt @@ -2,7 +2,7 @@ fun foo() { val x = "1" val y = 2 - val z = bar(x, 1, y, "x") + 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