]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/CompilationError.java
Merge "Testing SonarQube with Simantics Platform SDK"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / errors / CompilationError.java
1 package org.simantics.scl.compiler.errors;\r
2 \r
3 import java.io.PrintWriter;\r
4 import java.io.StringWriter;\r
5 \r
6 public class CompilationError implements Comparable<CompilationError> {\r
7     \r
8     public static final CompilationError[] EMPTY_ARRAY = new CompilationError[0];\r
9     \r
10     public final long location;\r
11     public final String description;\r
12     \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
18     }\r
19     \r
20     public CompilationError(long location, Exception exception) {\r
21         this(location, exceptionToString(exception));\r
22     }\r
23     \r
24     public CompilationError(String description) {\r
25         this(Locations.NO_LOCATION, description);\r
26     }\r
27     \r
28     public CompilationError(Exception exception) {\r
29         this(Locations.NO_LOCATION, exception);\r
30     }\r
31     \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
36     }\r
37    \r
38     @Override\r
39     public int hashCode() {\r
40         final int prime = 31;\r
41         int result = 1;\r
42         result = prime * result\r
43                 + ((description == null) ? 0 : description.hashCode());\r
44         result = prime * result + (int) (location ^ (location >>> 32));\r
45         return result;\r
46     }\r
47 \r
48     @Override\r
49     public boolean equals(Object obj) {\r
50         if (this == obj)\r
51             return true;\r
52         if (obj == null)\r
53             return false;\r
54         if (getClass() != obj.getClass())\r
55             return false;\r
56         CompilationError other = (CompilationError) obj;\r
57         if (description == null) {\r
58             if (other.description != null)\r
59                 return false;\r
60         } else if (!description.equals(other.description))\r
61             return false;\r
62         if (location != other.location)\r
63             return false;\r
64         return true;\r
65     }\r
66 \r
67     @Override\r
68     public int compareTo(CompilationError o) {\r
69         if(location < o.location)\r
70             return -1;\r
71         if(location > o.location)\r
72             return 1;\r
73         return description.compareTo(o.description);\r
74     }\r
75     \r
76     @Override\r
77     public String toString() {\r
78         return new StringBuilder().append("CompilationError: \"").append(description).append("\" at location ").append(location).toString();\r
79     }\r
80 }\r