private void visitCauses(Throwable t, TreeVisitor<? super Throwable> visitor) {
    if (t instanceof MultiCauseException) {
      MultiCauseException multiCauseException = (MultiCauseException) t;
      List<? extends Throwable> causes = multiCauseException.getCauses();
      if (!causes.isEmpty()) {
        visitor.startChildren();
        for (Throwable cause : causes) {
          visitor.node(cause);
          if (cause.getClass().getAnnotation(Contextual.class) != null) {
            visitCauses(cause, visitor);
          }
        }
        visitor.endChildren();
      }
      return;
    }

    if (t.getCause() != null) {
      visitor.startChildren();
      Throwable next = findNearestContextualCause(t);
      if (next != null) {
        // Show any contextual cause recursively
        visitor.node(next);
        visitCauses(next, visitor);
      } else {
        // Show the direct cause of the last contextual cause.
        visitor.node(t.getCause());
      }
      visitor.endChildren();
    }
  }
 /** Visits the reportable causes for this failure. */
 public void visitReportableCauses(TreeVisitor<? super Throwable> visitor) {
   visitor.node(this);
   visitCauses(target, visitor);
 }
Ejemplo n.º 3
0
 public void explain(TreeVisitor<? super String> visitor) {
   visitor.node(message);
 }