boolean (@Nullable PsiStatement statement, @Nullable PsiMethod psiMethod) { if (statement == null) { return true; } if (statement instanceof PsiBreakStatement || statement instanceof PsiContinueStatement || statement instanceof PsiYieldStatement || statement instanceof PsiReturnStatement || statement instanceof PsiThrowStatement) { return false; } else if (statement instanceof PsiExpressionListStatement || statement instanceof PsiEmptyStatement || statement instanceof PsiAssertStatement || statement instanceof PsiDeclarationStatement || statement instanceof PsiSwitchLabelStatement || statement instanceof PsiForeachStatementBase) { return true; } else if (statement instanceof final PsiExpressionStatement expressionStatement) { final PsiExpression expression = expressionStatement.getExpression(); if (!(expression instanceof final PsiMethodCallExpression methodCallExpression)) { return true; } final PsiMethod method = methodCallExpression.resolveMethod(); if (method == null) { return true; } if (method.equals(psiMethod)) { return false; } @NonNls final String methodName = method.getName(); if (!methodName.equals("exit")) { return true; } final PsiClass aClass = method.getContainingClass(); if (aClass == null) { return true; } final String className = aClass.getQualifiedName(); return !"java.lang.System".equals(className); } else if (statement instanceof PsiForStatement forStatement) { return forStatementMayCompleteNormally(forStatement); } else if (statement instanceof PsiWhileStatement whileStatement) { return whileStatementMayCompleteNormally(whileStatement); } else if (statement instanceof PsiDoWhileStatement doWhileStatement) { return doWhileStatementMayCompleteNormally(doWhileStatement, psiMethod); } else if (statement instanceof PsiSynchronizedStatement synchronizedStatement) { return codeBlockMayCompleteNormally(synchronizedStatement.getBody(), psiMethod); } else if (statement instanceof PsiBlockStatement block) { return codeBlockMayCompleteNormally(block.getCodeBlock(), psiMethod); } else if (statement instanceof PsiLabeledStatement labeled) { return labeledStatementMayCompleteNormally(labeled, psiMethod); } else if (statement instanceof PsiIfStatement ifStatement) { return ifStatementMayCompleteNormally(ifStatement, psiMethod); } else if (statement instanceof PsiTryStatement tryStatement) { return tryStatementMayCompleteNormally(tryStatement, psiMethod); } else if (statement instanceof PsiSwitchStatement switchStatement) { return switchStatementMayCompleteNormally(switchStatement, psiMethod); } else if (statement instanceof PsiSwitchLabeledRuleStatement rule) { PsiStatement body = rule.getBody(); return body != null && statementMayCompleteNormally(body, psiMethod); } else if (statement instanceof PsiTemplateStatement || statement instanceof PsiClassLevelDeclarationStatement) { return true; } else { assert false : "unknown statement type: " + statement.getClass(); return true; } }