1 package org.simantics.scl.compiler.errors;
3 import java.util.ArrayList;
4 import java.util.Collections;
6 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
8 public class ErrorLog {
9 ArrayList<CompilationError> errors = new ArrayList<CompilationError>();
11 long exceptionPosition = Locations.NO_LOCATION;
13 public void log(String message) {
14 log(new CompilationError(message));
17 public void log(CompilationError error) {
19 if(error.severity != ErrorSeverity.WARNING)
23 public void log(long locatable, String description) {
24 log(new CompilationError(locatable, description));
27 public void logWarning(long locatable, String description) {
28 log(new CompilationError(locatable, description, ErrorSeverity.WARNING));
31 public void log(Exception e) {
32 long location = Locations.NO_LOCATION;
33 if(e instanceof InternalCompilerError)
34 location = ((InternalCompilerError)e).location;
35 if(location == Locations.NO_LOCATION)
36 location = exceptionPosition;
37 log(new CompilationError(location, e));
40 public void log(long location, Exception e) {
41 log(new CompilationError(location, e));
44 public boolean hasNoErrors() {
45 return errorCount == 0;
48 public boolean hasErrors() {
49 return errorCount > 0;
52 public boolean hasErrorsOrWarnings() {
53 return !errors.isEmpty();
56 public CompilationError[] getErrors() {
57 Collections.sort(errors);
58 return errors.toArray(new CompilationError[errors.size()]);
61 public void setExceptionPosition(long exceptionPosition) {
62 if(this.exceptionPosition == Locations.NO_LOCATION)
63 this.exceptionPosition = exceptionPosition;
66 public String getErrorsAsString() {
67 Collections.sort(errors);
68 StringBuilder b = new StringBuilder();
69 for(CompilationError error : errors)
70 b.append(error.description).append('\n');
75 public String toString() {
76 return getErrorsAsString();
79 public int getErrorCount() {