private static boolean isIgnored(PsiExpression expression, boolean checkDeep) {
    final PsiElement parent = getHandlingParent(expression);
    if (parent instanceof PsiVariable) {
      if (!(parent instanceof PsiLocalVariable)) {
        return false;
      }
      else {
        return checkDeep && !isUsedElsewhere((PsiLocalVariable)parent);
      }
    }
    else if (parent instanceof PsiExpressionStatement expressionStatement) {
      // void method (like printStackTrace()) provides no result, thus can't be ignored
      final PsiExpression expression1 = expressionStatement.getExpression();
      return !PsiTypes.voidType().equals(expression1.getType());
    }
    else if (parent instanceof PsiExpressionList) {
      return parent.getParent() instanceof PsiExpressionListStatement;
    }
    else if (parent instanceof PsiLambdaExpression) {
      return PsiTypes.voidType().equals(LambdaUtil.getFunctionalInterfaceReturnType((PsiLambdaExpression)parent));
    }
    else if (parent instanceof PsiReturnStatement || parent instanceof PsiThrowStatement || parent instanceof PsiLoopStatement
             || parent instanceof PsiIfStatement || parent instanceof PsiAssertStatement) {
      return false;
    }
    else if (parent instanceof PsiAssignmentExpression assignmentExpression) {
      final PsiExpression rhs = assignmentExpression.getRExpression();
      if (!PsiTreeUtil.isAncestor(rhs, expression, false)) {
        return false;
      }
      final PsiExpression lhs = PsiUtil.skipParenthesizedExprDown(assignmentExpression.getLExpression());
      if (!(lhs instanceof PsiReferenceExpression referenceExpression)) {
        return false;
      }
      final PsiElement target = referenceExpression.resolve();
      if (!(target instanceof PsiLocalVariable)) {
        return false;
      }
      return checkDeep && !isUsedElsewhere((PsiLocalVariable)target);
    }
    return true;
  }
private static boolean isIgnored(PsiExpression expression, boolean checkDeep)