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