Minor refactoring

(cherry picked from commit b67f1e4)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/65a21bac
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/65a21bac
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/65a21bac

Branch: refs/heads/GROOVY_2_6_X
Commit: 65a21bac44d65b1be13760eb4a277aa6b96560b6
Parents: 581faad
Author: sunlan <sun...@apache.org>
Authored: Mon Aug 7 12:55:39 2017 +0800
Committer: sunlan <sun...@apache.org>
Committed: Mon Aug 7 13:24:43 2017 +0800

----------------------------------------------------------------------
 .../apache/groovy/parser/antlr4/AstBuilder.java | 30 +++++++++++---------
 1 file changed, 16 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/65a21bac/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
diff --git 
a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
 
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index ba314b9..c7b8dd1 100644
--- 
a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ 
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -188,7 +188,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
                 AtnManager.RRWL.readLock().unlock();
             }
         } catch (Throwable t) {
-            throw createParsingFailedException(t);
+            throw convertException(t);
         }
 
         return result;
@@ -207,23 +207,25 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
         return parser.compilationUnit();
     }
 
+    public CompilationFailedException convertException(Throwable t) {
+        CompilationFailedException cfe;
+
+        if (t instanceof CompilationFailedException) {
+            cfe = (CompilationFailedException) t;
+        } else if (t instanceof ParseCancellationException) {
+            cfe = createParsingFailedException(t.getCause());
+        } else {
+            cfe = createParsingFailedException(t);
+        }
+
+        return cfe;
+    }
+
     public ModuleNode buildAST() {
         try {
             return (ModuleNode) this.visit(this.buildCST());
         } catch (Throwable t) {
-            CompilationFailedException cfe;
-
-            if (t instanceof CompilationFailedException) {
-                cfe = (CompilationFailedException) t;
-            } else if (t instanceof ParseCancellationException) {
-                cfe = createParsingFailedException(t.getCause());
-            } else {
-                cfe = createParsingFailedException(t);
-            }
-
-//            LOGGER.log(Level.SEVERE, "Failed to build AST", cfe);
-
-            throw cfe;
+            throw convertException(t);
         }
     }
 

Reply via email to