only produce warnings if there are no errors
authorcrawshaw <crawshaw@ibex.org>
Tue, 23 Nov 2004 19:24:41 +0000 (19:24 +0000)
committercrawshaw <crawshaw@ibex.org>
Tue, 23 Nov 2004 19:24:41 +0000 (19:24 +0000)
darcs-hash:20041123192441-2eb37-1506bf549b9b9f5e17be841408cd35b8c71ceac8.gz

src/java/org/ibex/tool/Compiler.java

index bba4466..aaf2828 100644 (file)
@@ -89,6 +89,9 @@ public class Compiler {
     private File builddir = new File(".");
     private String sourcedir = null;
 
+    private boolean hasErrors;
+    private PrintWriter warn;
+
     public Compiler() {
         List defs = Collections.EMPTY_LIST;
 
@@ -122,10 +125,19 @@ public class Compiler {
         ICompilationUnit[] units = new ICompilationUnit[s.size()];
         for (int i=0; i < sources.length; i++) units[i] = sources[i].unit;
 
+        hasErrors = false;
+
+        StringWriter sw = new StringWriter();
+        StringBuffer w = sw.getBuffer();
+        warn = new PrintWriter(sw);
+
         org.eclipse.jdt.internal.compiler.Compiler jdt =
             new org.eclipse.jdt.internal.compiler.Compiler(
                 env, policy, settings, results, problems);
         jdt.compile(units);
+
+        if (!hasErrors) { out.write(w.toString()); out.flush(); }
+        warn = null;
     }
 
     private final FilenameFilter filterSrcs = new FilenameFilter() {
@@ -420,19 +432,22 @@ public class Compiler {
         public void acceptResult(CompilationResult result) {
             if (DEBUG) System.out.println("got result: "+result);
             if (result.hasProblems()) {
-                boolean hasErrors = false;
+                boolean err = false;
                 IProblem[] p = result.getProblems();
+                PrintWriter o;
                 for (int i=0; i < p.length; i++) {
-                    out.print(p[i].getOriginatingFileName());
-                    out.print(':');
-                    out.print(p[i].getSourceLineNumber());
-                    out.print(':');
-                    if (p[i].isError()) { out.print(" error: "); hasErrors = true; }
-                    else out.print(" warning: ");
-                    out.println(p[i].getMessage());
+                    if (p[i].isError()) { o = out; err = true; }
+                    else o = warn;
+
+                    o.print(p[i].getOriginatingFileName());
+                    o.print(':');
+                    o.print(p[i].getSourceLineNumber());
+                    o.print(':');
+                    o.print(p[i].isError() ? " error: " : " warning: ");
+                    o.println(p[i].getMessage());
                 }
                 out.flush();
-                if (hasErrors) return;
+                if (err) { hasErrors = true; return; }
             }
 
             ClassFile[] c = result.getClassFiles();