示例#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;
  }
示例#2
0
  /** {@inheritDoc} */
  public int compareTo(Annotation other) {
    int result = type.compareTo(other.type);

    if (result != 0) {
      return result;
    }

    result = visibility.compareTo(other.visibility);

    if (result != 0) {
      return result;
    }

    Iterator<NameValuePair> thisIter = elements.values().iterator();
    Iterator<NameValuePair> otherIter = other.elements.values().iterator();

    while (thisIter.hasNext() && otherIter.hasNext()) {
      NameValuePair thisOne = thisIter.next();
      NameValuePair otherOne = otherIter.next();

      result = thisOne.compareTo(otherOne);
      if (result != 0) {
        return result;
      }
    }

    if (thisIter.hasNext()) {
      return 1;
    } else if (otherIter.hasNext()) {
      return -1;
    }

    return 0;
  }
示例#3
0
  /** {@inheritDoc} */
  @Override
  public boolean equals(Object other) {
    if (!(other instanceof Annotation)) {
      return false;
    }

    Annotation otherAnnotation = (Annotation) other;

    if (!(type.equals(otherAnnotation.type) && (visibility == otherAnnotation.visibility))) {
      return false;
    }

    return elements.equals(otherAnnotation.elements);
  }
示例#4
0
  /** {@inheritDoc} */
  public String toHuman() {
    StringBuilder sb = new StringBuilder();

    sb.append(visibility.toHuman());
    sb.append("-annotation ");
    sb.append(type.toHuman());
    sb.append(" {");

    boolean first = true;
    for (NameValuePair pair : elements.values()) {
      if (first) {
        first = false;
      } else {
        sb.append(", ");
      }
      sb.append(pair.getName().toHuman());
      sb.append(": ");
      sb.append(pair.getValue().toHuman());
    }

    sb.append("}");
    return sb.toString();
  }
示例#5
0
 /** {@inheritDoc} */
 public int hashCode() {
   int hash = type.hashCode();
   hash = (hash * 31) + elements.hashCode();
   hash = (hash * 31) + visibility.hashCode();
   return hash;
 }