QuickFix: change function return type to match expexted type of call

This commit is contained in:
Wojciech Lopata
2013-05-10 00:57:45 +02:00
parent 76e648ded3
commit 1a5d515972
4 changed files with 23 additions and 0 deletions
@@ -91,6 +91,18 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
}
}
// Change function return type when TYPE_MISMATCH is reported on call expression:
if (expression instanceof JetCallExpression) {
ResolvedCall<? extends CallableDescriptor> resolvedCall =
context.get(BindingContext.RESOLVED_CALL, ((JetCallExpression) expression).getCalleeExpression());
if (resolvedCall != null) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getResultingDescriptor());
if (declaration instanceof JetFunction) {
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) declaration, expectedType));
}
}
}
// Change type of a function parameter in case TYPE_MISMATCH is reported on expression passed as value argument of call.
// 1) When an argument is a dangling function literal:
JetFunctionLiteralExpression functionLiteralExpression =
@@ -0,0 +1,3 @@
// "Change 'bar' function return type to 'String'" "true"
fun bar(): String = ""
fun foo(): String = bar(<caret>)
@@ -0,0 +1,3 @@
// "Change 'bar' function return type to 'String'" "true"
fun bar(): Any = ""
fun foo(): String = bar(<caret>)
@@ -1251,6 +1251,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest("idea/testData/quickfix/typeMismatch/beforeChangeFunctionLiteralParameterTypeToFunctionType.kt");
}
@TestMetadata("beforeChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt")
public void testChangeFunctionReturnTypeToMatchExpectedTypeOfCall() throws Exception {
doTest("idea/testData/quickfix/typeMismatch/beforeChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt");
}
@TestMetadata("beforeChangeReturnTypeWhenFunctionNameIsMissing.kt")
public void testChangeReturnTypeWhenFunctionNameIsMissing() throws Exception {
doTest("idea/testData/quickfix/typeMismatch/beforeChangeReturnTypeWhenFunctionNameIsMissing.kt");