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