Package dk.brics.xact.analysis

Source Code of dk.brics.xact.analysis.ErrorReport$OriginComparator

package dk.brics.xact.analysis;

import java.io.Serializable;
import java.util.Comparator;

import dk.brics.misc.Origin;

/**
* Describes an error reported by the XML analysis.
*/
public class ErrorReport implements Serializable {
    private static final long serialVersionUID = 1L;
    private Origin origin;
  private ErrorType type;
  private String message;
  private Throwable throwable;
 
  public ErrorReport(Origin origin, ErrorType type, String message) {
    this.origin = origin;
    this.type = type;
    this.message = message;
  }
  public ErrorReport(Throwable throwable) {
      this.throwable = throwable;
      this.type = ErrorType.OTHER;
      this.message = throwable.getMessage();
  }
 
  public Throwable getThrowable() {
        return throwable;
    }
  public void setThrowable(Throwable throwable) {
        this.throwable = throwable;
    }
  public boolean hasOrigin() {
      return origin != null;
  }
  public Origin getOrigin() {
      if (origin == null)
          return new Origin("?", -1, -1);
    return origin;
  }
  public void setOrigin(Origin origin) {
    this.origin = origin;
  }
  public ErrorType getType() {
    return type;
  }
  public void setType(ErrorType type) {
    this.type = type;
  }
  public String getMessage() {
    return message;
  }
  public void setMessage(String message) {
    this.message = message;
  }
 
  @Override
  public String toString() {
    return type.getMessage() + " at " + origin.getFile() + ":" + origin.getLine();
  }
 
  /**
   * Compares error reports by their origin alone.
   */
  public static class OriginComparator implements Comparator<ErrorReport>, Serializable {
      private static final long serialVersionUID = 1L;
      public int compare(ErrorReport o1, ErrorReport o2) {
          if (!o1.hasOrigin() && o2.hasOrigin())
              return 1;
          if (o1.hasOrigin() && !o2.hasOrigin())
              return -1;
          return o1.getOrigin().compareTo(o2.getOrigin());
      }
  }
}
TOP

Related Classes of dk.brics.xact.analysis.ErrorReport$OriginComparator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.