[java-intentions] Do not suggest to insert 'return' in the void method

GitOrigin-RevId: e73ca4a07b093b819858fb165d4b6207e9fcd360
This commit is contained in:
Tagir Valeev
2023-07-14 22:49:34 +00:00
committed by intellij-monorepo-bot
parent 1ac30a6fc9
commit ee20b97285
2 changed files with 11 additions and 13 deletions
@@ -431,22 +431,14 @@ public final class HighlightFixUtil {
PsiType type = expression.getType();
if (type == null) return;
if (!type.equals(PsiTypes.voidType())) {
IntentionAction action = PriorityIntentionActionWrapper.highPriority(QUICK_FIX_FACTORY.createIterateFix(expression));
registrar.add(action);
}
if (PsiTreeUtil.skipWhitespacesAndCommentsForward(statement) == block.getRBrace()) {
PsiElement blockParent = block.getParent();
if (blockParent instanceof PsiMethod) {
PsiType returnType = ((PsiMethod)blockParent).getReturnType();
registrar.add(PriorityIntentionActionWrapper.highPriority(QUICK_FIX_FACTORY.createIterateFix(expression)));
if (PsiTreeUtil.skipWhitespacesAndCommentsForward(statement) == block.getRBrace() && block.getParent() instanceof PsiMethod method) {
PsiType returnType = method.getReturnType();
if (returnType != null && isPossibleReturnValue(expression, type, returnType)) {
IntentionAction action = QUICK_FIX_FACTORY.createInsertReturnFix(expression);
registrar.add(action);
registrar.add(QUICK_FIX_FACTORY.createInsertReturnFix(expression));
}
}
}
if (!type.equals(PsiTypes.voidType())) {
IntentionAction action = QUICK_FIX_FACTORY.createIntroduceVariableAction(expression);
registrar.add(action);
registrar.add(QUICK_FIX_FACTORY.createIntroduceVariableAction(expression));
}
}
@@ -0,0 +1,6 @@
// "Insert 'return'" "false"
class X {
void test() {
test()<caret>
}
}