private static boolean statementDefinitelyRecurses(@Nullable GrStatement statement,
                                                     GrMethod method) {
    if (statement == null) {
      return false;
    }
    if (statement instanceof GrBreakStatement ||
        statement instanceof GrContinueStatement ||
        statement instanceof GrThrowStatement ||
        statement instanceof GrAssertStatement) {
      return false;
    } else if (statement instanceof GrExpression expression) {
      return expressionDefinitelyRecurses(expression, method);
    } else if (statement instanceof GrVariableDeclaration declaration) {
      final GrVariable[] declaredElements = declaration.getVariables();
      for (GrVariable variable : declaredElements) {
        final GrExpression initializer = variable.getInitializerGroovy();
        if (expressionDefinitelyRecurses(initializer, method)) {
          return true;
        }
      }
      return false;
    } else if (statement instanceof GrReturnStatement returnStatement) {
      final GrExpression returnValue = returnStatement.getReturnValue();
      if (returnValue != null) {
        if (expressionDefinitelyRecurses(returnValue, method)) {
          return true;
        }
      }
      return false;
    } else if (statement instanceof GrForStatement) {
      return forStatementDefinitelyRecurses((GrForStatement)
          statement, method);
    } else if (statement instanceof GrWhileStatement) {
      return whileStatementDefinitelyRecurses(
          (GrWhileStatement) statement, method);
    } else if (statement instanceof GrSynchronizedStatement) {
      final GrCodeBlock body = ((GrSynchronizedStatement) statement)
          .getBody();
      return codeBlockDefinitelyRecurses(body, method);
    } else if (statement instanceof GrBlockStatement) {
      final GrCodeBlock codeBlock = ((GrBlockStatement) statement).getBlock();
      return codeBlockDefinitelyRecurses(codeBlock, method);
    } else if (statement instanceof GrIfStatement) {
      return ifStatementDefinitelyRecurses(
          (GrIfStatement) statement, method);
    } else if (statement instanceof GrTryCatchStatement) {
      return tryStatementDefinitelyRecurses(
          (GrTryCatchStatement) statement, method);
    } else if (statement instanceof GrSwitchStatement) {
      return switchStatementDefinitelyRecurses(
          (GrSwitchStatement) statement, method);
    } else {
      // unknown statement type
      return false;
    }
  }
private static boolean statementDefinitelyRecurses(@Nullable GrStatement statement,
                                                     GrMethod method)