Quickfix for RETURN_TYPE_MISMATCH and NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY

This commit is contained in:
Wojciech Lopata
2013-04-24 11:32:33 +02:00
parent dde4260d10
commit 893cbd6b48
9 changed files with 52 additions and 0 deletions
@@ -173,4 +173,16 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
}
};
}
@NotNull
public static JetIntentionActionFactory createFactoryForChangingReturnTypeToUnit() {
return new JetIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetNamedFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetNamedFunction.class);
return function == null ? null : new ChangeFunctionReturnTypeFix(function, KotlinBuiltIns.getInstance().getUnitType());
}
};
}
}
@@ -215,6 +215,9 @@ public class QuickFixes {
factories.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, changeVariableTypeFix);
factories.put(COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, ChangeVariableTypeFix.createFactoryForComponentFunctionReturnTypeMismatch());
JetIntentionActionFactory changeFunctionReturnTypeFix = ChangeFunctionReturnTypeFix.createFactoryForChangingReturnTypeToUnit();
factories.put(RETURN_TYPE_MISMATCH, changeFunctionReturnTypeFix);
factories.put(NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY, changeFunctionReturnTypeFix);
factories.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, ChangeFunctionReturnTypeFix.createFactoryForReturnTypeMismatchOnOverride());
factories.put(COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForComponentFunctionReturnTypeMismatch());
factories.put(HAS_NEXT_FUNCTION_TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForHasNextFunctionTypeMismatch());
@@ -0,0 +1,4 @@
// "Remove explicitly specified function return type" "true"
fun () {
return<caret>
}
@@ -0,0 +1,3 @@
// "Remove explicitly specified return type in 'foo' function" "true"
fun foo() {
<caret>}
@@ -0,0 +1,4 @@
// "Remove explicitly specified return type in 'foo' function" "true"
fun foo() {
return<caret>
}
@@ -0,0 +1,4 @@
// "Remove explicitly specified function return type" "true"
fun (): Int {
return<caret>
}
@@ -0,0 +1,3 @@
// "Remove explicitly specified return type in 'foo' function" "true"
fun foo(): Int {
<caret>}
@@ -0,0 +1,4 @@
// "Remove explicitly specified return type in 'foo' function" "true"
fun foo(): Int {
return<caret>
}
@@ -998,6 +998,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/typeMismatch"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforeChangeReturnTypeWhenFunctionNameIsMissing.kt")
public void testChangeReturnTypeWhenFunctionNameIsMissing() throws Exception {
doTest("idea/testData/quickfix/typeMismatch/beforeChangeReturnTypeWhenFunctionNameIsMissing.kt");
}
@TestMetadata("beforeChangeReturnTypeWhenValueParameterListIsAbsent.kt")
public void testChangeReturnTypeWhenValueParameterListIsAbsent() throws Exception {
doTest("idea/testData/quickfix/typeMismatch/beforeChangeReturnTypeWhenValueParameterListIsAbsent.kt");
@@ -1048,6 +1053,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest("idea/testData/quickfix/typeMismatch/beforeHasNextFunctionReturnTypeMismatch.kt");
}
@TestMetadata("beforeNoReturnInFunctionWithBlockBody.kt")
public void testNoReturnInFunctionWithBlockBody() throws Exception {
doTest("idea/testData/quickfix/typeMismatch/beforeNoReturnInFunctionWithBlockBody.kt");
}
@TestMetadata("beforeReturnTypeMismatch.kt")
public void testReturnTypeMismatch() throws Exception {
doTest("idea/testData/quickfix/typeMismatch/beforeReturnTypeMismatch.kt");
}
}
@TestMetadata("idea/testData/quickfix/typeProjection")