1 package org.simantics.scl.compiler.errors;
3 import java.io.PrintWriter;
4 import java.io.StringWriter;
6 public class CompilationError implements Comparable<CompilationError> {
8 public static final CompilationError[] EMPTY_ARRAY = new CompilationError[0];
10 public final long location;
11 public final String description;
13 public CompilationError(long location, String description) {
14 if(description == null)
15 throw new NullPointerException();
16 this.location = location;
17 this.description = description;
20 public CompilationError(long location, Exception exception) {
21 this(location, exceptionToString(exception));
24 public CompilationError(String description) {
25 this(Locations.NO_LOCATION, description);
28 public CompilationError(Exception exception) {
29 this(Locations.NO_LOCATION, exception);
32 private static String exceptionToString(Exception e) {
33 StringWriter w = new StringWriter();
34 e.printStackTrace(new PrintWriter(w));
39 public int hashCode() {
42 result = prime * result
43 + ((description == null) ? 0 : description.hashCode());
44 result = prime * result + (int) (location ^ (location >>> 32));
49 public boolean equals(Object obj) {
54 if (getClass() != obj.getClass())
56 CompilationError other = (CompilationError) obj;
57 if (description == null) {
58 if (other.description != null)
60 } else if (!description.equals(other.description))
62 if (location != other.location)
68 public int compareTo(CompilationError o) {
69 if(location < o.location)
71 if(location > o.location)
73 return description.compareTo(o.description);
77 public String toString() {
78 return new StringBuilder().append("CompilationError: \"").append(description).append("\" at location ").append(location).toString();