diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java index c6def7d992fe..d1dd5faf14d7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java @@ -68,7 +68,7 @@ public class HighlightControlFlowUtil { context, JavaErrorMessages.message("missing.return.statement")); QuickFixAction.registerQuickFixAction(highlightInfo, new AddReturnFix(method)); - IntentionAction fix = QUICK_FIX_FACTORY.createMethodReturnFix(method, PsiType.VOID, false); + IntentionAction fix = QUICK_FIX_FACTORY.createMethodReturnFix(method, PsiType.VOID, true); QuickFixAction.registerQuickFixAction(highlightInfo, fix); return highlightInfo; } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 2702e4528645..775cf7597b22 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -502,14 +502,14 @@ public class HighlightUtil { description = JavaErrorMessages.message("return.from.void.method"); errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, statement, description); if (valueType != null) { - IntentionAction fix = QUICK_FIX_FACTORY.createMethodReturnFix(method, valueType, false); + IntentionAction fix = QUICK_FIX_FACTORY.createMethodReturnFix(method, valueType, true); QuickFixAction.registerQuickFixAction(errorResult, fix); } } else { errorResult = checkAssignability(returnType, valueType, returnValue, statement); if (errorResult != null && valueType != null) { - IntentionAction fix = QUICK_FIX_FACTORY.createMethodReturnFix(method, valueType, false); + IntentionAction fix = QUICK_FIX_FACTORY.createMethodReturnFix(method, valueType, true); QuickFixAction.registerQuickFixAction(errorResult, fix); if (returnType instanceof PsiArrayType && TypeConversionUtil.isAssignable(((PsiArrayType)returnType).getComponentType(), valueType)) { QuickFixAction.registerQuickFixAction(errorResult, new SurroundWithArrayFix(null){ @@ -527,7 +527,7 @@ public class HighlightUtil { if (!isMethodVoid) { description = JavaErrorMessages.message("missing.return.value"); errorResult = HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, statement, description); - IntentionAction fix = QUICK_FIX_FACTORY.createMethodReturnFix(method, PsiType.VOID, false); + IntentionAction fix = QUICK_FIX_FACTORY.createMethodReturnFix(method, PsiType.VOID, true); QuickFixAction.registerQuickFixAction(errorResult, fix); navigationShift = PsiKeyword.RETURN.length(); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodReturnFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodReturnFix.java index 9e24af9a0802..a29204cd117f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodReturnFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodReturnFix.java @@ -18,6 +18,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.codeInsight.daemon.QuickFixBundle; import com.intellij.codeInspection.IntentionAndQuickFixAction; +import com.intellij.ide.util.SuperMethodWarningUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.undo.UndoUtil; import com.intellij.openapi.project.Project; @@ -27,6 +28,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiType; import com.intellij.psi.util.TypeConversionUtil; +import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.changeSignature.ChangeSignatureProcessor; import org.jetbrains.annotations.NotNull; @@ -66,8 +68,18 @@ public class MethodReturnFix extends IntentionAndQuickFixAction { public void applyFix(final Project project, final PsiFile file, final Editor editor) { if (!CodeInsightUtilBase.prepareFileForWrite(myMethod.getContainingFile())) return; - PsiMethod method = myFixWholeHierarchy ? myMethod.findDeepestSuperMethod() : myMethod; - if (method == null) method = myMethod; + PsiMethod method = myMethod; + if (myFixWholeHierarchy) { + final PsiMethod superMethod = myMethod.findDeepestSuperMethod(); + if (superMethod != null) { + final PsiType superReturnType = superMethod.getReturnType(); + if (superReturnType != null && !Comparing.equal(myReturnType, superReturnType)) { + method = SuperMethodWarningUtil.checkSuperMethod(myMethod, RefactoringBundle.message("to.refactor")); + if (method == null) return; + } + } + } + if (!CodeInsightUtilBase.prepareFileForWrite(method.getContainingFile())) return; ChangeSignatureProcessor processor = new ChangeSignatureProcessor(myMethod.getProject(), method, false, null,