X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ferrors%2FCompilationError.java;fp=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ferrors%2FCompilationError.java;h=499fe2bf0fa9506489321738adfd1ba9a2db81b3;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/CompilationError.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/CompilationError.java new file mode 100644 index 000000000..499fe2bf0 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/CompilationError.java @@ -0,0 +1,75 @@ +package org.simantics.scl.compiler.errors; + +import java.io.PrintWriter; +import java.io.StringWriter; + +public class CompilationError implements Comparable { + + public static final CompilationError[] EMPTY_ARRAY = new CompilationError[0]; + + public final long location; + public final String description; + + public CompilationError(long location, String description) { + if(description == null) + throw new NullPointerException(); + this.location = location; + this.description = description; + } + + 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); + } +}