--- /dev/null
+package org.simantics.scl.compiler.errors;\r
+\r
+import java.io.PrintWriter;\r
+import java.io.StringWriter;\r
+\r
+public class CompilationError implements Comparable<CompilationError> {\r
+ \r
+ public static final CompilationError[] EMPTY_ARRAY = new CompilationError[0];\r
+ \r
+ public final long location;\r
+ public final String description;\r
+ \r
+ public CompilationError(long location, String description) {\r
+ if(description == null)\r
+ throw new NullPointerException();\r
+ this.location = location;\r
+ this.description = description;\r
+ }\r
+ \r
+ public CompilationError(long location, Exception exception) {\r
+ this(location, exceptionToString(exception));\r
+ }\r
+ \r
+ public CompilationError(String description) {\r
+ this(Locations.NO_LOCATION, description);\r
+ }\r
+ \r
+ public CompilationError(Exception exception) {\r
+ this(Locations.NO_LOCATION, exception);\r
+ }\r
+ \r
+ private static String exceptionToString(Exception e) {\r
+ StringWriter w = new StringWriter();\r
+ e.printStackTrace(new PrintWriter(w));\r
+ return w.toString();\r
+ }\r
+ \r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result\r
+ + ((description == null) ? 0 : description.hashCode());\r
+ result = prime * result + (int) (location ^ (location >>> 32));\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj)\r
+ return true;\r
+ if (obj == null)\r
+ return false;\r
+ if (getClass() != obj.getClass())\r
+ return false;\r
+ CompilationError other = (CompilationError) obj;\r
+ if (description == null) {\r
+ if (other.description != null)\r
+ return false;\r
+ } else if (!description.equals(other.description))\r
+ return false;\r
+ if (location != other.location)\r
+ return false;\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public int compareTo(CompilationError o) {\r
+ if(location < o.location)\r
+ return -1;\r
+ if(location > o.location)\r
+ return 1;\r
+ return description.compareTo(o.description);\r
+ }\r
+}\r