ImplicitElseData (@NotNull PsiIfStatement ifStatement, PsiStatement @NotNull [] thenStatements, String jumpKeyword, boolean basicJumpStatement) { if (!PsiKeyword.RETURN.equals(jumpKeyword) && !PsiKeyword.CONTINUE.equals(jumpKeyword)) return null; int statementsLength = thenStatements.length; if (statementsLength == 0) return null; PsiIfStatement currentIf = ifStatement; List<PsiStatement> statements = new ArrayList<>(); int count = 0; boolean conditionHasSideEffects = false; while (true) { if (currentIf.getElseBranch() != null) return null; if (currentIf != ifStatement && ControlFlowUtils.unwrapBlock(currentIf.getThenBranch()).length != 1) break; if(currentIf.getCondition() != null && SideEffectChecker.mayHaveSideEffects(currentIf.getCondition())) { conditionHasSideEffects = true; } PsiStatement sibling = currentIf; do { sibling = PsiTreeUtil.getNextSiblingOfType(sibling, PsiStatement.class); if (sibling == null) break; if (!isMeaningful(sibling)) continue; count++; statements.add(sibling); } while (count <= statementsLength); if (!statements.isEmpty()) break; PsiIfStatement enclosingIf = getEnclosingIfStmt(currentIf); if (enclosingIf == null) break; currentIf = enclosingIf; } if (conditionHasSideEffects && ifStatement != currentIf) return null; // ensure it is last statements in method PsiElement parent = currentIf.getParent(); if (!(parent instanceof PsiCodeBlock)) return null; if (PsiKeyword.RETURN.equals(jumpKeyword)) { if (!(parent.getParent() instanceof PsiMethod)) return null; if (!statements.isEmpty()) { if (PsiTreeUtil.getNextSiblingOfType(statements.get(statements.size() - 1), PsiStatement.class) != null) return null; } } if (PsiKeyword.CONTINUE.equals(jumpKeyword) && !(parent.getParent() instanceof PsiBlockStatement) && !(parent.getParent().getParent() instanceof PsiLoopStatement)) return null; if (basicJumpStatement) { // skip possible jump statement if (count == statementsLength || count == statementsLength - 1) return new ImplicitElseData(statements, currentIf); } else if (count == statementsLength) { return new ImplicitElseData(statements, currentIf); } return null; }