code: public static Expression retainResult(Expression node) {
      switch (node.getKind()) {
        case ARRAY_CREATION:
          ((ArrayCreation) node).setHasRetainedResult(true);
          return TreeUtil.remove(node);
        case CLASS_INSTANCE_CREATION:
          ((ClassInstanceCreation) node).setHasRetainedResult(true);
          return TreeUtil.remove(node);
        case FUNCTION_INVOCATION: {
          FunctionInvocation invocation = (FunctionInvocation) node;
          if (invocation.getFunctionElement().getRetainedResultName() != null) {
            invocation.setHasRetainedResult(true);
            return TreeUtil.remove(node);
          }
          return null;
        }
        default:
          return null;
      }
    }
docs: If possible give this expression an unbalanced extra retain. If a non-null
  result is returned, then the returned expression has an unbalanced extra
  retain and the passed in expression is removed from the tree and must be
  discarded. If null is returned then the passed in expression is left
  untouched. The caller must ensure the result is eventually consumed.