Replace SyntacticErrorListener with CustomErrorListener, step 2

Stage 2 of the replacement of SyntacticErrorListener with its inner
class CustomErrorListener.  In order to retain history, we do this
in two commits: one commit to change the name of the
SyntacticErrorListener class to CustomErrorListener while changing
the inner CustomErrorListener class to a dummy name; a second commit
to move the inner class methods out to the outer class.

Closes #61, Closes #73.


Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/fafbd535
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/fafbd535
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/fafbd535

Branch: refs/heads/master
Commit: fafbd535d2a88e2afdbbb03c56770ac72ffeb428
Parents: 45d56a5
Author: Mike Dusenberry <[email protected]>
Authored: Fri Feb 19 12:17:13 2016 -0800
Committer: Deron Eriksson <[email protected]>
Committed: Fri Feb 19 12:17:13 2016 -0800

----------------------------------------------------------------------
 .../parser/common/CommonSyntacticValidator.java |   6 +-
 .../parser/common/CustomErrorListener.java      | 137 +++++++++----------
 .../sysml/parser/dml/DMLParserWrapper.java      |   6 +-
 .../sysml/parser/dml/DmlSyntacticValidator.java |   4 +-
 .../sysml/parser/pydml/PyDMLParserWrapper.java  |   4 +-
 .../parser/pydml/PydmlSyntacticValidator.java   |   4 +-
 6 files changed, 78 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fafbd535/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java 
b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
index 4e5d01f..68a586e 100644
--- a/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
@@ -51,7 +51,7 @@ import org.apache.sysml.parser.PrintStatement;
 import org.apache.sysml.parser.RelationalExpression;
 import org.apache.sysml.parser.Statement;
 import org.apache.sysml.parser.StringIdentifier;
-import 
org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
+import org.apache.sysml.parser.common.CustomErrorListener;
 import org.apache.sysml.parser.dml.DmlParser.BuiltinFunctionExpressionContext;
 import org.apache.sysml.parser.dml.DmlSyntacticValidator;
 import org.apache.sysml.parser.pydml.PydmlSyntacticValidator;
@@ -64,12 +64,12 @@ import com.google.common.primitives.Longs;
  */
 public abstract class CommonSyntacticValidator {
 
-       protected final CustomErrorListenerInner errorListener;
+       protected final CustomErrorListener errorListener;
        protected final String currentFile;
        protected String _workingDir = ".";   //current working directory
        protected HashMap<String,String> argVals = null;
 
-       public CommonSyntacticValidator(CustomErrorListenerInner errorListener, 
HashMap<String,String> argVals) {
+       public CommonSyntacticValidator(CustomErrorListener errorListener, 
HashMap<String,String> argVals) {
                this.errorListener = errorListener;
                currentFile = errorListener.getCurrentFileName();
                this.argVals = argVals;

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fafbd535/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java 
b/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
index 74c82c0..ec640c5 100644
--- a/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
+++ b/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
@@ -26,86 +26,83 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.sysml.api.DMLScript;
 
-public class CustomErrorListener {
-       
+public class CustomErrorListener extends BaseErrorListener {
+
        private static final Log LOG = 
LogFactory.getLog(DMLScript.class.getName());
-       
-       public static class CustomErrorListenerInner extends BaseErrorListener {
-               
-               private boolean atleastOneError = false;
-               private String currentFileName = null;
-               
-               public void setCurrentFileName(String currentFilePath) {
-                       currentFileName = currentFilePath;
-               }
-               
-               public String getCurrentFileName() {
-                       return currentFileName;
-               }
-               
-               public void unsetCurrentFileName() {
-                       currentFileName = null;
-               }
 
-               public void validationError(int line, int charPositionInLine, 
String msg) {
-                       try {
-                               setAtleastOneError(true);
-                               // Print error messages with file name
-                               if(currentFileName == null) {
-                                       LOG.error("line 
"+line+":"+charPositionInLine+" "+msg);
-                               }
-                               else {
-                                       String fileName = currentFileName;
-                                       LOG.error(fileName + " line 
"+line+":"+charPositionInLine+" "+msg);
-                               }
+       private boolean atleastOneError = false;
+       private String currentFileName = null;
+
+       public void setCurrentFileName(String currentFilePath) {
+               currentFileName = currentFilePath;
+       }
+
+       public String getCurrentFileName() {
+               return currentFileName;
+       }
+
+       public void unsetCurrentFileName() {
+               currentFileName = null;
+       }
+
+       public void validationError(int line, int charPositionInLine, String 
msg) {
+               try {
+                       setAtleastOneError(true);
+                       // Print error messages with file name
+                       if(currentFileName == null) {
+                               LOG.error("line "+line+":"+charPositionInLine+" 
"+msg);
                        }
-                       catch(Exception e1) {
-                               LOG.error("ERROR: while customizing error 
message:" + e1);
+                       else {
+                               String fileName = currentFileName;
+                               LOG.error(fileName + " line 
"+line+":"+charPositionInLine+" "+msg);
                        }
                }
-               
-               public void validationWarning(int line, int charPositionInLine, 
String msg) {
-                       try {
-                               //atleastOneError = true; ---> not an error, 
just warning
-                               // Print error messages with file name
-                               if(currentFileName == null)
-                                       LOG.warn("line 
"+line+":"+charPositionInLine+" "+msg);
-                               else {
-                                       String fileName = currentFileName;
-                                       LOG.warn(fileName + " line 
"+line+":"+charPositionInLine+" "+msg);
-                               }
-                       }
-                       catch(Exception e1) {
-                               LOG.warn("ERROR: while customizing error 
message:" + e1);
-                       }
+               catch(Exception e1) {
+                       LOG.error("ERROR: while customizing error message:" + 
e1);
                }
-               
-               @Override
-               public void syntaxError(Recognizer<?, ?> recognizer, Object 
offendingSymbol,
-                               int line, int charPositionInLine,
-                               String msg, RecognitionException e)
-               {       
-                       try {
-                               setAtleastOneError(true);
-                               // Print error messages with file name
-                               if(currentFileName == null)
-                                       LOG.error("line 
"+line+":"+charPositionInLine+" "+msg);
-                               else {
-                                       String fileName = currentFileName;
-                                       LOG.error(fileName + " line 
"+line+":"+charPositionInLine+" "+msg);
-                               }
-                       }
-                       catch(Exception e1) {
-                               LOG.error("ERROR: while customizing error 
message:" + e1);
+       }
+
+       public void validationWarning(int line, int charPositionInLine, String 
msg) {
+               try {
+                       //atleastOneError = true; ---> not an error, just 
warning
+                       // Print error messages with file name
+                       if(currentFileName == null)
+                               LOG.warn("line "+line+":"+charPositionInLine+" 
"+msg);
+                       else {
+                               String fileName = currentFileName;
+                               LOG.warn(fileName + " line 
"+line+":"+charPositionInLine+" "+msg);
                        }
                }
-
-               public boolean isAtleastOneError() {
-                       return atleastOneError;
+               catch(Exception e1) {
+                       LOG.warn("ERROR: while customizing error message:" + 
e1);
                }
+       }
 
-               public void setAtleastOneError(boolean atleastOneError) {
-                       this.atleastOneError = atleastOneError;
+       @Override
+       public void syntaxError(Recognizer<?, ?> recognizer, Object 
offendingSymbol,
+                                                       int line, int 
charPositionInLine,
+                                                       String msg, 
RecognitionException e)
+       {
+               try {
+                       setAtleastOneError(true);
+                       // Print error messages with file name
+                       if(currentFileName == null)
+                               LOG.error("line "+line+":"+charPositionInLine+" 
"+msg);
+                       else {
+                               String fileName = currentFileName;
+                               LOG.error(fileName + " line 
"+line+":"+charPositionInLine+" "+msg);
+                       }
+               }
+               catch(Exception e1) {
+                       LOG.error("ERROR: while customizing error message:" + 
e1);
                }
        }
+
+       public boolean isAtleastOneError() {
+               return atleastOneError;
+       }
+
+       public void setAtleastOneError(boolean atleastOneError) {
+               this.atleastOneError = atleastOneError;
+       }
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fafbd535/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java 
b/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
index 6b9a238..fb5fc65 100644
--- a/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
+++ b/src/main/java/org/apache/sysml/parser/dml/DMLParserWrapper.java
@@ -43,7 +43,7 @@ import org.apache.sysml.parser.FunctionStatementBlock;
 import org.apache.sysml.parser.ImportStatement;
 import org.apache.sysml.parser.LanguageException;
 import org.apache.sysml.parser.ParseException;
-import 
org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
+import org.apache.sysml.parser.common.CustomErrorListener;
 import org.apache.sysml.parser.dml.DmlParser.FunctionStatementContext;
 import org.apache.sysml.parser.dml.DmlParser.ProgramrootContext;
 import org.apache.sysml.parser.dml.DmlParser.StatementContext;
@@ -125,7 +125,7 @@ public class DMLParserWrapper extends AParserWrapper
                }
 
                ProgramrootContext ast = null;
-               CustomErrorListenerInner errorListener = new 
CustomErrorListenerInner();
+               CustomErrorListener errorListener = new CustomErrorListener();
                
                try {
                        DmlLexer lexer = new DmlLexer(in);
@@ -149,11 +149,9 @@ public class DMLParserWrapper extends AParserWrapper
                                        antlr4Parser.reset();
                                        if(fileName != null) {
                                                
errorListener.setCurrentFileName(fileName);
-                                               // 
CustomErrorListener.currentFileName.push(fileName);
                                        }
                                        else {
                                                
errorListener.setCurrentFileName("MAIN_SCRIPT");
-                                               // 
CustomErrorListener.currentFileName.push("MAIN_SCRIPT");
                                        }
                                        // Set our custom error listener
                                        
antlr4Parser.addErrorListener(errorListener);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fafbd535/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java 
b/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
index f3a297f..02c8b75 100644
--- a/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
@@ -55,7 +55,7 @@ import org.apache.sysml.parser.Statement;
 import org.apache.sysml.parser.StatementBlock;
 import org.apache.sysml.parser.WhileStatement;
 import org.apache.sysml.parser.common.CommonSyntacticValidator;
-import 
org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
+import org.apache.sysml.parser.common.CustomErrorListener;
 import org.apache.sysml.parser.common.ExpressionInfo;
 import org.apache.sysml.parser.common.StatementInfo;
 import org.apache.sysml.parser.dml.DmlParser.AddSubExpressionContext;
@@ -110,7 +110,7 @@ import 
org.apache.sysml.parser.dml.DmlParser.WhileStatementContext;
 
 public class DmlSyntacticValidator extends CommonSyntacticValidator implements 
DmlListener {
 
-       public DmlSyntacticValidator(CustomErrorListenerInner errorListener, 
HashMap<String,String> argVals) {
+       public DmlSyntacticValidator(CustomErrorListener errorListener, 
HashMap<String,String> argVals) {
                super(errorListener, argVals);
        }
 

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fafbd535/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java 
b/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java
index ad49b44..7090e5d 100644
--- a/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java
+++ b/src/main/java/org/apache/sysml/parser/pydml/PyDMLParserWrapper.java
@@ -44,7 +44,7 @@ import org.apache.sysml.parser.ImportStatement;
 import org.apache.sysml.parser.LanguageException;
 import org.apache.sysml.parser.ParseException;
 import org.apache.sysml.parser.Statement;
-import 
org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
+import org.apache.sysml.parser.common.CustomErrorListener;
 import org.apache.sysml.parser.dml.DMLParserWrapper;
 import org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext;
 import org.apache.sysml.parser.pydml.PydmlParser.ProgramrootContext;
@@ -112,7 +112,7 @@ public class PyDMLParserWrapper extends AParserWrapper
                }
 
                ProgramrootContext ast = null;
-               CustomErrorListenerInner errorListener = new 
CustomErrorListenerInner();
+               CustomErrorListener errorListener = new CustomErrorListener();
                
                try {
                        PydmlLexer lexer = new PydmlLexer(in);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fafbd535/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java 
b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
index a2a0995..fd12d53 100644
--- a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
@@ -58,7 +58,7 @@ import org.apache.sysml.parser.StatementBlock;
 import org.apache.sysml.parser.StringIdentifier;
 import org.apache.sysml.parser.WhileStatement;
 import org.apache.sysml.parser.common.CommonSyntacticValidator;
-import 
org.apache.sysml.parser.common.CustomErrorListener.CustomErrorListenerInner;
+import org.apache.sysml.parser.common.CustomErrorListener;
 import org.apache.sysml.parser.common.ExpressionInfo;
 import org.apache.sysml.parser.common.StatementInfo;
 import org.apache.sysml.parser.dml.DmlParser.MatrixMulExpressionContext;
@@ -118,7 +118,7 @@ import 
org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext;
  */
 public class PydmlSyntacticValidator extends CommonSyntacticValidator 
implements PydmlListener {
 
-       public PydmlSyntacticValidator(CustomErrorListenerInner errorListener, 
HashMap<String,String> argVals) {
+       public PydmlSyntacticValidator(CustomErrorListener errorListener, 
HashMap<String,String> argVals) {
                super(errorListener, argVals);
        }
 

Reply via email to