You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2009/01/21 02:31:42 UTC

svn commit: r736188 - in /ode/sandbox/simpel/src: main/java/org/apache/ode/simpel/ main/java/org/apache/ode/simpel/omodel/ main/java/org/apache/ode/simpel/util/ test/java/org/apache/ode/simpel/

Author: mriou
Date: Tue Jan 20 17:31:42 2009
New Revision: 736188

URL: http://svn.apache.org/viewvc?rev=736188&view=rev
Log:
Proper compilation exception listing all recoverable errors.

Modified:
    ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/CompilationException.java
    ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java
    ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java
    ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
    ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java
    ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java

Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/CompilationException.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/CompilationException.java?rev=736188&r1=736187&r2=736188&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/CompilationException.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/CompilationException.java Tue Jan 20 17:31:42 2009
@@ -1,9 +1,17 @@
 package org.apache.ode.simpel;
 
+import java.util.List;
+
 /**
- * @author Matthieu Riou <mr...@apache.org>
+ * Main exception for all possible errors happening during compilation. For recoverable errors, it's thrown
+ * with a list of underlying errors that can be analyzed independently. For unrecoverable errors, it's treated
+ * as a classic exception.
  */
 public class CompilationException extends RuntimeException {
+
+    public List<Error> errors;
+    public String compilationMessages;
+
     public CompilationException(String message) {
         super(message);
     }
@@ -15,4 +23,33 @@
     public CompilationException(Throwable cause) {
         super(cause);
     }
+
+    public CompilationException(List<Error> errors) {
+        super();
+        StringBuffer msg = new StringBuffer("Errors during process compilation:\n");
+        for (Error error : errors)
+            msg.append(error.line).append(":").append(error.column).append(" ").append(error.message).append("\n");
+        this.compilationMessages = msg.toString();
+        this.errors = errors;
+    }
+
+    @Override
+    public String getMessage() {
+        return compilationMessages == null ? super.getMessage() : compilationMessages;
+    }
+
+    public static class Error {
+        public int line;
+        public int column;
+        public String message;
+        public Exception recognitionException;
+
+        public Error(int line, int column, String message, Exception e) {
+            this.line = line;
+            this.column = column;
+            this.message = message;
+            this.recognitionException = e;
+        }
+    }
+
 }

Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java?rev=736188&r1=736187&r2=736188&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/ErrorListener.java Tue Jan 20 17:31:42 2009
@@ -2,10 +2,14 @@
 
 import org.antlr.runtime.RecognitionException;
 
+import java.util.List;
+
 /**
  * @author Matthieu Riou <mr...@apache.org>
  */
 public interface ErrorListener {
 
-    public void reportRecognitionError(int line, int column, String message, RecognitionException e);
+    List<CompilationException.Error> getErrors();
+
+    void reportRecognitionError(int line, int column, String message, RecognitionException e);
 }

Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java?rev=736188&r1=736187&r2=736188&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/SimPELCompiler.java Tue Jan 20 17:31:42 2009
@@ -106,10 +106,9 @@
         LinkedListTree t = (LinkedListTree)result.getTree();
         StringBuffer b = new StringBuffer();
         toText(t, b);
-        System.out.println(b.toString());
 
         if (t != null) {
-            //  Handle functions separately
+            // Handle functions separately
             handleFunctions(t);
 
             // Pass the tree to the walker for compilation
@@ -127,6 +126,9 @@
             } catch (RecognitionException e) {
                 throw new CompilationException(e);
             }
+            if (errListener.getErrors() != null && errListener.getErrors().size() > 0)
+                throw new CompilationException(errListener.getErrors());
+
             return walker.getBuilder().getProcess();
         }
         return null;

Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java?rev=736188&r1=736187&r2=736188&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/omodel/OBuilder.java Tue Jan 20 17:31:42 2009
@@ -21,9 +21,6 @@
 
 /**
  * TODO e4x templates
- * TODO allow javascript blocks instead of just hooking on equal, otherwise you can't do stuff like
- *          operations.appendChild(<operand>2</operand>);
- *          operations.appendChild(<operand>3</operand>);
  * TODO resources aren't available if they're not used
  */
 public class OBuilder extends BaseCompiler {

Modified: ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java?rev=736188&r1=736187&r2=736188&view=diff
==============================================================================
--- ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java (original)
+++ ode/sandbox/simpel/src/main/java/org/apache/ode/simpel/util/DefaultErrorListener.java Tue Jan 20 17:31:42 2009
@@ -2,6 +2,7 @@
 
 import org.antlr.runtime.RecognitionException;
 import org.apache.ode.simpel.ErrorListener;
+import org.apache.ode.simpel.CompilationException;
 
 import java.util.LinkedList;
 import java.util.List;
@@ -11,28 +12,15 @@
  */
 public class DefaultErrorListener implements ErrorListener {
 
-    private LinkedList<Error> _errors = new LinkedList<Error>();
+    private LinkedList<CompilationException.Error> _errors = new LinkedList<CompilationException.Error>();
 
-    public List<Error> getErrors() {
+    public List<CompilationException.Error> getErrors() {
         return _errors;
     }
 
     public void reportRecognitionError(int line, int column, String message, RecognitionException e) {
-        _errors.add(new Error(line, column, message, e));
+        _errors.add(new CompilationException.Error(line, column, message, e));
         System.err.println(line + ":" + column + " " +  message);
     }
 
-    public class Error {
-        public int line;
-        public int column;
-        public String message;
-        public RecognitionException e;
-
-        public Error(int line, int column, String message, RecognitionException e) {
-            this.line = line;
-            this.column = column;
-            this.message = message;
-            this.e = e;
-        }
-    }
 }

Modified: ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java
URL: http://svn.apache.org/viewvc/ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java?rev=736188&r1=736187&r2=736188&view=diff
==============================================================================
--- ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java (original)
+++ ode/sandbox/simpel/src/test/java/org/apache/ode/simpel/SimPELCompilerTest.java Tue Jan 20 17:31:42 2009
@@ -7,6 +7,7 @@
 
 import java.io.BufferedReader;
 import java.io.FileReader;
+import java.util.List;
 
 /**
  * @author Matthieu Riou <mr...@apache.org>
@@ -137,6 +138,10 @@
     private static class TestErrorListener implements ErrorListener {
         public StringBuffer messages = new StringBuffer();
 
+        public List<CompilationException.Error> getErrors() {
+            return null;
+        }
+
         public void reportRecognitionError(int line, int column, String message, RecognitionException e) {
             messages.append(" - line ").append(line).append(": ").append(message).append("\n");
         }