RemoveExplicitTypeArguments - no i18n + minor
This commit is contained in:
@@ -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.multiple=Add name to argument...
|
||||||
add.name.to.argument.action=Add name to argument...
|
add.name.to.argument.action=Add name to argument...
|
||||||
add.name.to.parameter.name.chooser.title=Choose parameter name
|
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<T>() with T::class
|
replace.java.class.argument=Replace javaClass<T>() with T::class
|
||||||
replace.java.class.argument.family=Replace javaClass<T>() with T::class
|
replace.java.class.argument.family=Replace javaClass<T>() with T::class
|
||||||
|
|||||||
@@ -31,21 +31,14 @@ import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
|
|
||||||
public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentIntention<JetTypeArgumentList>(
|
public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentIntention<JetTypeArgumentList>(javaClass(), "Remove explicit type arguments") {
|
||||||
"remove.explicit.type.arguments", javaClass()) {
|
|
||||||
|
|
||||||
override fun isApplicableTo(element: JetTypeArgumentList): Boolean {
|
override fun isApplicableTo(element: JetTypeArgumentList): Boolean {
|
||||||
val callExpression = element.getParent()
|
val callExpression = element.getParent() as? JetCallExpression ?: return false
|
||||||
if (callExpression !is JetCallExpression) return false
|
|
||||||
|
|
||||||
val context = callExpression.analyze()
|
|
||||||
if (callExpression.getTypeArguments().isEmpty()) return false
|
if (callExpression.getTypeArguments().isEmpty()) return false
|
||||||
|
|
||||||
val injector = InjectorForMacros(callExpression.getProject(), callExpression.findModuleDescriptor())
|
val context = callExpression.analyze()
|
||||||
|
val scope = context[BindingContext.RESOLUTION_SCOPE, callExpression] ?: return false
|
||||||
val scope = context[BindingContext.RESOLUTION_SCOPE, callExpression]
|
val originalCall = callExpression.getResolvedCall(context) ?: return false
|
||||||
val originalCall = callExpression.getResolvedCall(context)
|
|
||||||
if (originalCall == null || scope !is JetScope) return false
|
|
||||||
val untypedCall = CallWithoutTypeArgs(originalCall.getCall())
|
val untypedCall = CallWithoutTypeArgs(originalCall.getCall())
|
||||||
|
|
||||||
// todo Check with expected type for other expressions
|
// todo Check with expected type for other expressions
|
||||||
@@ -59,17 +52,19 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentInte
|
|||||||
is JetReturnExpression -> true
|
is JetReturnExpression -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
val jType = if (expectedTypeIsExplicitInCode) {
|
val expectedType = if (expectedTypeIsExplicitInCode) {
|
||||||
context[BindingContext.EXPECTED_EXPRESSION_TYPE, callExpression] ?: TypeUtils.NO_EXPECTED_TYPE
|
context[BindingContext.EXPECTED_EXPRESSION_TYPE, callExpression] ?: TypeUtils.NO_EXPECTED_TYPE
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TypeUtils.NO_EXPECTED_TYPE
|
TypeUtils.NO_EXPECTED_TYPE
|
||||||
}
|
}
|
||||||
val dataFlow = context.getDataFlowInfo(callExpression)
|
val dataFlow = context.getDataFlowInfo(callExpression)
|
||||||
|
val injector = InjectorForMacros(callExpression.getProject(), callExpression.findModuleDescriptor())
|
||||||
val resolutionResults = injector.getCallResolver().resolveFunctionCall(
|
val resolutionResults = injector.getCallResolver().resolveFunctionCall(
|
||||||
BindingTraceContext(), scope, untypedCall, jType, dataFlow, false)
|
BindingTraceContext(), scope, untypedCall, expectedType, dataFlow, false)
|
||||||
assert (resolutionResults.isSingleResult()) { "Removing type arguments changed resolve for: " +
|
assert (resolutionResults.isSingleResult()) {
|
||||||
"${callExpression.getTextWithLocation()} to ${resolutionResults.getResultCode()}" }
|
"Removing type arguments changed resolve for: ${callExpression.getTextWithLocation()} to ${resolutionResults.getResultCode()}"
|
||||||
|
}
|
||||||
|
|
||||||
val args = originalCall.getTypeArguments()
|
val args = originalCall.getTypeArguments()
|
||||||
val newArgs = resolutionResults.getResultingCall().getTypeArguments()
|
val newArgs = resolutionResults.getResultingCall().getTypeArguments()
|
||||||
@@ -78,7 +73,7 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingOffsetIndependentInte
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class CallWithoutTypeArgs(call: Call) : DelegatingCall(call) {
|
private class CallWithoutTypeArgs(call: Call) : DelegatingCall(call) {
|
||||||
override fun getTypeArguments(): List<JetTypeProjection> = listOf()
|
override fun getTypeArguments() = emptyList<JetTypeProjection>()
|
||||||
override fun getTypeArgumentList() = null
|
override fun getTypeArgumentList() = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user