IDEA-168343 Suggest to change called method return type when used in return statement

This commit is contained in:
Tagir Valeev
2017-09-22 14:15:40 +07:00
parent 1b92dad9dc
commit cade4517aa
4 changed files with 25 additions and 1 deletions
@@ -231,11 +231,15 @@ public class HighlightFixUtil {
for (IntentionAction action : getChangeVariableTypeFixes(parameter, itemType)) {
QuickFixAction.registerQuickFixAction(highlightInfo, action);
}
registerChangeReturnTypeFix(highlightInfo, expr, parameter.getType());
}
static void registerChangeReturnTypeFix(@NotNull HighlightInfo highlightInfo, @Nullable PsiExpression expr, @NotNull PsiType toType) {
if (expr instanceof PsiMethodCallExpression) {
final PsiMethod method = ((PsiMethodCallExpression)expr).resolveMethod();
if (method != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, PriorityActionWrapper
.lowPriority(method, QUICK_FIX_FACTORY.createMethodReturnFix(method, parameter.getType(), true)));
.lowPriority(method, QUICK_FIX_FACTORY.createMethodReturnFix(method, toType, true)));
}
}
}
@@ -499,6 +499,7 @@ public class HighlightUtil extends HighlightUtilBase {
QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createWrapWithAdapterFix(lType, expression));
AddTypeArgumentsConditionalFix.register(highlightInfo, expression, lType);
HighlightFixUtil.registerCollectionToArrayFixAction(highlightInfo, rType, lType, expression);
HighlightFixUtil.registerChangeReturnTypeFix(highlightInfo, expression, lType);
}
ChangeNewOperatorTypeFix.register(highlightInfo, expression, lType);
return highlightInfo;
@@ -0,0 +1,10 @@
// "Make 'bar' return 'java.lang.String'" "true"
public class Foo {
String foo() {
return bar();
}
String bar() {
return null;
}
}
@@ -0,0 +1,9 @@
// "Make 'bar' return 'java.lang.String'" "true"
public class Foo {
String foo() {
return <caret>bar();
}
void bar() {
}
}