示例#1
0
  /**
   * Helper for {@link #orderItems}, which recursively assigns indices to classes.
   *
   * @param type {@code null-ok;} type ref to assign, if any
   * @param idx {@code >= 0;} the next index to assign
   * @param maxDepth maximum recursion depth; if negative, this will throw an exception indicating
   *     class definition circularity
   * @return {@code >= 0;} the next index to assign
   */
  private int orderItems0(Type type, int idx, int maxDepth) {
    ClassDefItem c = classDefs.get(type);

    if ((c == null) || (c.hasIndex())) {
      return idx;
    }

    if (maxDepth < 0) {
      throw new RuntimeException("class circularity with " + type);
    }

    maxDepth--;

    CstType superclassCst = c.getSuperclass();
    if (superclassCst != null) {
      Type superclass = superclassCst.getClassType();
      idx = orderItems0(superclass, idx, maxDepth);
    }

    TypeList interfaces = c.getInterfaces();
    int sz = interfaces.size();
    for (int i = 0; i < sz; i++) {
      idx = orderItems0(interfaces.getType(i), idx, maxDepth);
    }

    c.setIndex(idx);
    orderedDefs.add(c);
    return idx + 1;
  }