diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightFixUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightFixUtil.java index a18f3ab5f568..5134eb4c5978 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightFixUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightFixUtil.java @@ -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)); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/insertReturn/beforeVoid.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/insertReturn/beforeVoid.java new file mode 100644 index 000000000000..c7b26488ae50 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/insertReturn/beforeVoid.java @@ -0,0 +1,6 @@ +// "Insert 'return'" "false" +class X { + void test() { + test() + } +} \ No newline at end of file