--- /dev/null
+package org.simantics.scl.compiler.errors;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+
+public class ErrorLog {
+ ArrayList<CompilationError> errors = new ArrayList<CompilationError>();
+ long exceptionPosition;
+
+ public void log(String message) {
+ errors.add(new CompilationError(message));
+ }
+
+ public void log(CompilationError error) {
+ errors.add(error);
+ }
+
+ public void log(long locatable, String description) {
+ log(new CompilationError(locatable, description));
+ }
+
+ public void log(Exception e) {
+ if(e instanceof InternalCompilerError)
+ log(((InternalCompilerError)e).location, e);
+ else
+ log(new CompilationError(e));
+ }
+
+ public void log(long location, Exception e) {
+ log(new CompilationError(location, e));
+ }
+
+ public boolean isEmpty() {
+ return errors.isEmpty();
+ }
+
+ public CompilationError[] getErrors() {
+ Collections.sort(errors);
+ return errors.toArray(new CompilationError[errors.size()]);
+ }
+
+ public void setExceptionPosition(long exceptionPosition) {
+ if(this.exceptionPosition == Locations.NO_LOCATION)
+ this.exceptionPosition = exceptionPosition;
+ }
+
+ public long getExceptionPosition() {
+ return exceptionPosition;
+ }
+
+ public String getErrorsAsString() {
+ StringBuilder b = new StringBuilder();
+ for(CompilationError error : errors)
+ b.append(error.description).append('\n');
+ return b.toString();
+ }
+}