public static boolean isReturnRedundant(@NotNull PsiReturnStatement statement,
                                          boolean ignoreInThenBranch,
                                          boolean checkReturnType,
                                          @Nullable Ref<? super Boolean> isInConstructorRef) {
    if (statement.getReturnValue() != null) {
      return false;
    }
    final PsiElement methodParent = PsiTreeUtil.getParentOfType(statement, PsiMethod.class, PsiLambdaExpression.class);
    PsiCodeBlock codeBlock = null;
    if (methodParent instanceof PsiMethod method) {
      codeBlock = method.getBody();
      if (isInConstructorRef != null) {
        isInConstructorRef.set(method.isConstructor());
      }
      if (checkReturnType && !method.isConstructor() && !PsiTypes.voidType().equals(method.getReturnType())) {
        return false;
      }
    }
    else if (methodParent instanceof PsiLambdaExpression lambdaExpression) {
      if (isInConstructorRef != null) {
        isInConstructorRef.set(false);
      }
      if (checkReturnType && !PsiTypes.voidType().equals(LambdaUtil.getFunctionalInterfaceReturnType(lambdaExpression))) {
        return false;
      }
      final PsiElement lambdaBody = lambdaExpression.getBody();
      if (lambdaBody instanceof PsiCodeBlock) {
        codeBlock = (PsiCodeBlock)lambdaBody;
      }
    }
    else {
      return false;
    }
    if (codeBlock == null) {
      return false;
    }
    if (!ControlFlowUtils.blockCompletesWithStatement(codeBlock, statement) || ControlFlowUtils.isInFinallyBlock(statement, null)) {
      return false;
    }
    if (ignoreInThenBranch && isInThenBranch(statement)) {
      return false;
    }
    return true;
  }
public static boolean isReturnRedundant(@NotNull PsiReturnStatement statement,
                                          boolean ignoreInThenBranch,
                                          boolean checkReturnType,
                                          @Nullable Ref<? super Boolean> isInConstructorRef)