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;
12 public final ErrorSeverity severity;
14 public CompilationError(long location, String description, ErrorSeverity severity) {
15 if(description == null)
16 throw new NullPointerException();
17 this.location = location;
18 this.description = description;
19 this.severity = severity;
22 public CompilationError(long location, String description) {
23 this(location, description, ErrorSeverity.ERROR);
26 public CompilationError(long location, Exception exception) {
27 this(location, exceptionToString(exception));
30 public CompilationError(String description) {
31 this(Locations.NO_LOCATION, description);
34 public CompilationError(Exception exception) {
35 this(Locations.NO_LOCATION, exception);
38 private static String exceptionToString(Exception e) {
39 StringWriter w = new StringWriter();
40 e.printStackTrace(new PrintWriter(w));
45 public int hashCode() {
48 result = prime * result
49 + ((description == null) ? 0 : description.hashCode());
50 result = prime * result + (int) (location ^ (location >>> 32));
55 public boolean equals(Object obj) {
60 if (getClass() != obj.getClass())
62 CompilationError other = (CompilationError) obj;
63 if (description == null) {
64 if (other.description != null)
66 } else if (!description.equals(other.description))
68 if (location != other.location)
74 public int compareTo(CompilationError o) {
75 if(location < o.location)
77 if(location > o.location)
79 return description.compareTo(o.description);
83 public String toString() {
84 return new StringBuilder().append("CompilationError: \"").append(description).append("\" at location ").append(location).toString();