Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X a761dfad4 -> 3484401b3


Minor refactoring

(cherry picked from commit 797622a)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 3484401b33bd033ee7a350f07cc1a3400a876f59
Parents: a761dfa
Author: sunlan <[email protected]>
Authored: Mon Aug 21 08:13:48 2017 +0800
Committer: sunlan <[email protected]>
Committed: Mon Aug 21 08:15:32 2017 +0800

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/3484401b/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 92d06f5..df369b3 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
@@ -112,7 +112,6 @@ import 
org.codehaus.groovy.control.CompilationFailedException;
 import org.codehaus.groovy.control.CompilePhase;
 import org.codehaus.groovy.control.SourceUnit;
 import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
-import org.codehaus.groovy.runtime.IOGroovyMethods;
 import org.codehaus.groovy.runtime.StringGroovyMethods;
 import org.codehaus.groovy.syntax.Numbers;
 import org.codehaus.groovy.syntax.SyntaxException;
@@ -153,7 +152,7 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
         this.moduleNode = new ModuleNode(sourceUnit);
         this.classLoader = classLoader; // unused for the time being
 
-        CharStream charStream = 
CharStreams.fromString(this.readSourceCode(sourceUnit));
+        CharStream charStream = createCharStream(sourceUnit);
 
         this.lexer = new GroovyLangLexer(charStream);
         this.parser =
@@ -166,6 +165,18 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
         this.groovydocManager = new GroovydocManager(this);
     }
 
+    private CharStream createCharStream(SourceUnit sourceUnit) {
+        CharStream charStream = null;
+
+        try {
+            charStream = 
CharStreams.fromReader(sourceUnit.getSource().getReader(), 
sourceUnit.getName());
+        } catch (IOException e) {
+            throw new RuntimeException("Error occurred when reading source 
code.", e);
+        }
+
+        return charStream;
+    }
+
     public GroovyParserRuleContext buildCST() throws 
CompilationFailedException {
         GroovyParserRuleContext result;
 
@@ -4476,18 +4487,6 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
         sourceUnit.getErrorCollector().addException(e, this.sourceUnit);
     }
 
-    private String readSourceCode(SourceUnit sourceUnit) {
-        String text = null;
-        try {
-            text = IOGroovyMethods.getText(sourceUnit.getSource().getReader());
-        } catch (IOException e) {
-            LOGGER.severe(createExceptionMessage(e));
-            throw new RuntimeException("Error occurred when reading source 
code.", e);
-        }
-
-        return text;
-    }
-
     private ANTLRErrorListener createANTLRErrorListener() {
         return new ANTLRErrorListener() {
             @Override

Reply via email to