mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix return type with super method
This commit is contained in:
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
+14
-2
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user