diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties index 3c6ea7392fa..e635a72d808 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties @@ -220,8 +220,6 @@ add.name.to.argument.single=Add name to argument\: ''{0}'' add.name.to.argument.multiple=Add name to argument... add.name.to.argument.action=Add name to argument... add.name.to.parameter.name.chooser.title=Choose parameter name -remove.explicit.type.arguments=Remove explicit type arguments -remove.explicit.type.arguments.family=Remove Explicit Type Arguments replace.java.class.argument=Replace javaClass() with T::class replace.java.class.argument.family=Replace javaClass() with T::class diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArguments.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArguments.kt index 3a773315ac6..ffd79eae9e9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArguments.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/RemoveExplicitTypeArguments.kt @@ -31,21 +31,14 @@ import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.types.TypeUtils -public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentIntention( - "remove.explicit.type.arguments", javaClass()) { - +public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Remove explicit type arguments") { override fun isApplicableTo(element: JetTypeArgumentList): Boolean { - val callExpression = element.getParent() - if (callExpression !is JetCallExpression) return false - - val context = callExpression.analyze() + val callExpression = element.getParent() as? JetCallExpression ?: return false if (callExpression.getTypeArguments().isEmpty()) return false - val injector = InjectorForMacros(callExpression.getProject(), callExpression.findModuleDescriptor()) - - val scope = context[BindingContext.RESOLUTION_SCOPE, callExpression] - val originalCall = callExpression.getResolvedCall(context) - if (originalCall == null || scope !is JetScope) return false + val context = callExpression.analyze() + val scope = context[BindingContext.RESOLUTION_SCOPE, callExpression] ?: return false + val originalCall = callExpression.getResolvedCall(context) ?: return false val untypedCall = CallWithoutTypeArgs(originalCall.getCall()) // todo Check with expected type for other expressions @@ -59,17 +52,19 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentInte is JetReturnExpression -> true else -> false } - val jType = if (expectedTypeIsExplicitInCode) { + val expectedType = if (expectedTypeIsExplicitInCode) { context[BindingContext.EXPECTED_EXPRESSION_TYPE, callExpression] ?: TypeUtils.NO_EXPECTED_TYPE } else { TypeUtils.NO_EXPECTED_TYPE } val dataFlow = context.getDataFlowInfo(callExpression) + val injector = InjectorForMacros(callExpression.getProject(), callExpression.findModuleDescriptor()) val resolutionResults = injector.getCallResolver().resolveFunctionCall( - BindingTraceContext(), scope, untypedCall, jType, dataFlow, false) - assert (resolutionResults.isSingleResult()) { "Removing type arguments changed resolve for: " + - "${callExpression.getTextWithLocation()} to ${resolutionResults.getResultCode()}" } + BindingTraceContext(), scope, untypedCall, expectedType, dataFlow, false) + assert (resolutionResults.isSingleResult()) { + "Removing type arguments changed resolve for: ${callExpression.getTextWithLocation()} to ${resolutionResults.getResultCode()}" + } val args = originalCall.getTypeArguments() val newArgs = resolutionResults.getResultingCall().getTypeArguments() @@ -78,7 +73,7 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentInte } private class CallWithoutTypeArgs(call: Call) : DelegatingCall(call) { - override fun getTypeArguments(): List = listOf() + override fun getTypeArguments() = emptyList() override fun getTypeArgumentList() = null }