]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/Failure.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / errors / Failure.java
1 package org.simantics.scl.compiler.errors;
2
3 import java.io.PrintStream;
4
5 @SuppressWarnings("rawtypes")
6 public class Failure implements Failable {
7     public final CompilationError[] errors;
8
9     public Failure(CompilationError[] errors) {
10         this.errors = errors;
11     }
12     
13     public Failure(String description) {
14         this.errors = new CompilationError[] { new CompilationError(description) };
15     }
16     
17     public Failure(Exception e) {
18         this.errors = new CompilationError[] { new CompilationError(e) };
19     }
20
21     public void printTo(PrintStream out) {
22         for(CompilationError error : errors)
23             out.println(error.description);
24     }
25
26     public String toString(String source) {
27         return CompilationErrorFormatter.toString(source, errors);
28     }
29     
30     @Override
31     public String toString() {
32         return CompilationErrorFormatter.toString(errors);
33     }
34     
35     @Override
36     public Object getResult() {
37         throw new IllegalStateException("Module compilation failed.");
38     }
39
40     @Override
41     public boolean didSucceed() {
42         return false;
43     }
44
45     @Override
46     public String getDescription() {
47         StringBuilder b = new StringBuilder();
48         b.append("Module compilation failed:");
49         for(CompilationError error : errors)
50             b.append("\n    ").append(error.description);
51         return b.toString();
52     }
53 }