QuickFix: change property type to match it's initializer type

This commit is contained in:
Wojciech Lopata
2013-05-09 22:24:15 +02:00
parent ed6e734c14
commit d3492d8e6f
4 changed files with 19 additions and 0 deletions
@@ -50,6 +50,12 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
actions.add(new CastExpressionFix(expression, expectedType));
}
// Property initializer type mismatch property type:
JetProperty property = PsiTreeUtil.getParentOfType(expression, JetProperty.class);
if (property != null && QuickFixUtil.canEvaluateTo(property.getInitializer(), expression)) {
actions.add(new ChangeVariableTypeFix(property, expressionType));
}
// Mismatch in returned expression:
JetFunction function = PsiTreeUtil.getParentOfType(expression, JetFunction.class, true);
if (function != null && QuickFixUtil.canFunctionReturnExpression(function, expression)) {
@@ -0,0 +1,4 @@
// "Change 'f' type to '(Long) -> Unit'" "true"
fun foo() {
var f: (Long) -> Unit = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
}
@@ -0,0 +1,4 @@
// "Change 'f' type to '(Long) -> Unit'" "true"
fun foo() {
var f: Int = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
}
@@ -1286,6 +1286,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest("idea/testData/quickfix/typeMismatch/beforeNoReturnInFunctionWithBlockBody.kt");
}
@TestMetadata("beforePropertyTypeMismatch.kt")
public void testPropertyTypeMismatch() throws Exception {
doTest("idea/testData/quickfix/typeMismatch/beforePropertyTypeMismatch.kt");
}
@TestMetadata("beforeReturnTypeMismatch.kt")
public void testReturnTypeMismatch() throws Exception {
doTest("idea/testData/quickfix/typeMismatch/beforeReturnTypeMismatch.kt");