]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Failure.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / errors / Failure.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Failure.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Failure.java
new file mode 100644 (file)
index 0000000..5a6cf72
--- /dev/null
@@ -0,0 +1,53 @@
+package org.simantics.scl.compiler.errors;
+
+import java.io.PrintStream;
+
+@SuppressWarnings("rawtypes")
+public class Failure implements Failable {
+    public final CompilationError[] errors;
+
+    public Failure(CompilationError[] errors) {
+        this.errors = errors;
+    }
+    
+    public Failure(String description) {
+        this.errors = new CompilationError[] { new CompilationError(description) };
+    }
+    
+    public Failure(Exception e) {
+        this.errors = new CompilationError[] { new CompilationError(e) };
+    }
+
+    public void printTo(PrintStream out) {
+        for(CompilationError error : errors)
+            out.println(error.description);
+    }
+
+    public String toString(String source) {
+        return CompilationErrorFormatter.toString(source, errors);
+    }
+    
+    @Override
+    public String toString() {
+        return CompilationErrorFormatter.toString(errors);
+    }
+    
+    @Override
+    public Object getResult() {
+        throw new IllegalStateException("Module compilation failed.");
+    }
+
+    @Override
+    public boolean didSucceed() {
+        return false;
+    }
+
+    @Override
+    public String getDescription() {
+        StringBuilder b = new StringBuilder();
+        b.append("Module compilation failed:");
+        for(CompilationError error : errors)
+            b.append("\n    ").append(error.description);
+        return b.toString();
+    }
+}