package kalang.compiler;

import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

/**
 *
 * @author Kason Yang
 */
public class StandardDiagnosisHandler implements DiagnosisHandler{
    
    public static StandardDiagnosisHandler INSTANCE = new StandardDiagnosisHandler();

    private final PrintStream errOut;
    
    private final PrintStream stdOut;

    public StandardDiagnosisHandler() {
        this(System.out,System.err);
    }

    public StandardDiagnosisHandler(PrintStream stdOut,PrintStream errOut) {
        this.stdOut = stdOut;
        this.errOut = errOut;
    }

    @Override
    public void handleDiagnosis(Diagnosis diagnosis) {
        boolean isError = diagnosis.getKind().isError();
        if(isError){
            CompileContext ctx = diagnosis.getContext();
            ctx.stopCompile(ctx.getCompilingPhase());
        }
        PrintStream o = isError ? stdOut : errOut;
        o.println(diagnosis);
    }

}

@@ -21,154 +21,51 @@
 ler;
-%0A%0Aimport java.io.OutputStream;%0Aimport java.io.PrintStream;%0Aimport java.io.PrintWriter;%0Aimport java.io.StringWriter;%0Aimport java.io.Writer;%0A
+%0D%0A%0D%0Aimport java.io.PrintStream;%0D%0A%0D
 %0A/**
+%0D
 %0A *
+%0D
 %0A * 
@@ -86,12 +86,14 @@
 Yang
+%0D
 %0A */
+%0D
 %0Apub
@@ -154,22 +154,21 @@
 sHandler
-%7B%0A    
+ %7B%0D%0A%0D
 %0A    pub
@@ -245,17 +245,19 @@
 ndler();
-%0A
+%0D%0A%0D
 %0A    pri
@@ -286,21 +286,19 @@
  errOut;
-%0A    
+%0D%0A%0D
 %0A    pri
@@ -327,17 +327,60 @@
  stdOut;
-%0A
+%0D%0A%0D%0A    private boolean hasError = false;%0D%0A%0D
 %0A    pub
@@ -411,16 +411,17 @@
 dler() %7B
+%0D
 %0A       
@@ -437,16 +437,17 @@
 tem.out,
+ 
 System.e
@@ -450,23 +450,26 @@
 em.err);
+%0D
 %0A    %7D
-%0A
+%0D%0A%0D
 %0A    pub
@@ -516,16 +516,17 @@
  stdOut,
+ 
 PrintStr
@@ -538,16 +538,17 @@
 rrOut) %7B
+%0D
 %0A       
@@ -565,24 +565,25 @@
 ut = stdOut;
+%0D
 %0A        thi
@@ -600,23 +600,26 @@
  errOut;
+%0D
 %0A    %7D
-%0A
+%0D%0A%0D
 %0A    @Ov
@@ -624,16 +624,17 @@
 Override
+%0D
 %0A    pub
@@ -680,16 +680,17 @@
 nosis) %7B
+%0D
 %0A       
@@ -738,16 +738,17 @@
 Error();
+%0D
 %0A       
@@ -750,16 +750,17 @@
       if
+ 
 (isError
@@ -760,17 +760,54 @@
 isError)
-%7B
+ %7B%0D%0A            this.hasError = true;%0D
 %0A       
@@ -855,16 +855,17 @@
 ntext();
+%0D
 %0A       
@@ -910,16 +910,17 @@
 hase());
+%0D
 %0A       
@@ -921,16 +921,17 @@
        %7D
+%0D
 %0A       
@@ -973,16 +973,17 @@
  errOut;
+%0D
 %0A       
@@ -1008,14 +1008,86 @@
 is);
+%0D
 %0A    %7D
-%0A%0A%7D
+%0D%0A%0D%0A    public boolean hasError() %7B%0D%0A        return hasError;%0D%0A    %7D%0D%0A%0D%0A%7D%0D
 %0A

add method: hasError