class TypeWithDims {
    final Tree node;
    final ImmutableList<List<AnnotationTree>> dims;

    public TypeWithDims(Tree node, ImmutableList<List<AnnotationTree>> dims) {
      this.node = node;
      this.dims = dims;
    }
  }

  enum SortedDims {
    YES,
    NO
  }

  /** Returns a (possibly re-ordered) {@link TypeWithDims} for the given type. */
  static TypeWithDims extractDims(Tree node, SortedDims sorted) {<FILL_FUNCTION_BODY>

    Deque<List<AnnotationTree>> builder = new ArrayDeque<>();
    node = extractDims(builder, node);
    Iterable<List<AnnotationTree>> dims;
    if (sorted == SortedDims.YES) {
      dims = reorderBySourcePosition(builder);
    } else {
      dims = builder;
    }
    return new TypeWithDims(node, ImmutableList.copyOf(dims));
  
<no_super_class>