boolean isResourceEscaping(@Nullable PsiVariable boundVariable, @NotNull PsiExpression resourceCreationExpression) {
    if (boundVariable instanceof PsiField) return true;
    if (isSystemErrOrOutUse(resourceCreationExpression)) {
      return true;
    }
    if (resourcePotentiallyCreatedFromOther(resourceCreationExpression)) return true;
    final PsiElement parent = ExpressionUtils.getPassThroughParent(resourceCreationExpression);
    if (parent instanceof PsiLambdaExpression lambda) {
      PsiType returnType = LambdaUtil.getFunctionalInterfaceReturnType(lambda);
      if (!PsiTypes.voidType().equals(returnType)) {
        return true;
      }
    }
    if (parent instanceof PsiReturnStatement) {
      return true;
    }
    if (parent instanceof PsiAssignmentExpression assignmentExpression) {
      if (PsiUtil.skipParenthesizedExprDown(assignmentExpression.getRExpression()) != resourceCreationExpression) {
        return true; // non-sensical code
      }
      if (assignedToField(assignmentExpression)) {
        return true;
      }
    }
    else if (parent instanceof PsiExpressionList) {
      PsiElement grandParent = parent.getParent();
      if (grandParent instanceof PsiAnonymousClass) {
        grandParent = grandParent.getParent();
      }
      if (grandParent instanceof PsiCallExpression) {
        return anyMethodMayClose || isResourceCreation((PsiExpression) grandParent);
      }
    }
    if (boundVariable == null) {
      return false;
    }
    final PsiCodeBlock codeBlock = PsiTreeUtil.getParentOfType(boundVariable, PsiCodeBlock.class, true, PsiMember.class);
    if (codeBlock == null) {
      return false;
    }
    final EscapeVisitor visitor = new EscapeVisitor(boundVariable, resourceCreationExpression);
    codeBlock.accept(visitor);
    return visitor.isEscaped();
  }
boolean isResourceEscaping(@Nullable PsiVariable boundVariable, @NotNull PsiExpression resourceCreationExpression)