Esempio n. 1
0
  /**
   * Utility method which prints the abbreviations of the elements in a passed {@link Set} of
   * exception types.
   *
   * @param s The exceptions to print.
   * @param connector The character to insert between exceptions.
   * @return An abbreviated representation of the exceptions.
   */
  private String toAbbreviatedString(Set s, char connector) {
    final String JAVA_LANG = "java.lang.";
    final int JAVA_LANG_LENGTH = JAVA_LANG.length();
    final String EXCEPTION = "Exception";
    final int EXCEPTION_LENGTH = EXCEPTION.length();

    Collection vmErrorThrowables = ThrowableSet.Manager.v().VM_ERRORS.exceptionsIncluded;
    boolean containsAllVmErrors = s.containsAll(vmErrorThrowables);
    StringBuffer buf = new StringBuffer();

    if (containsAllVmErrors) {
      buf.append(connector);
      buf.append("vmErrors");
    }

    for (Iterator it = sortedThrowableIterator(s); it.hasNext(); ) {
      RefLikeType reflikeType = (RefLikeType) it.next();
      RefType baseType = null;
      if (reflikeType instanceof RefType) {
        baseType = (RefType) reflikeType;
        if (vmErrorThrowables.contains(baseType) && containsAllVmErrors) {
          continue; // Already accounted for vmErrors.
        } else {
          buf.append(connector);
        }
      } else if (reflikeType instanceof AnySubType) {
        buf.append(connector);
        buf.append('(');
        baseType = ((AnySubType) reflikeType).getBase();
      }
      String typeName = baseType.toString();
      if (typeName.startsWith(JAVA_LANG)) {
        typeName = typeName.substring(JAVA_LANG_LENGTH);
      }
      if (typeName.length() > EXCEPTION_LENGTH && typeName.endsWith(EXCEPTION)) {
        typeName = typeName.substring(0, typeName.length() - EXCEPTION_LENGTH);
      }
      buf.append(typeName);
      if (reflikeType instanceof AnySubType) {
        buf.append(')');
      }
    }
    return buf.toString();
  }