Repository: groovy Updated Branches: refs/heads/master 6c2eb7799 -> 797622a76
Minor refactoring Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/797622a7 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/797622a7 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/797622a7 Branch: refs/heads/master Commit: 797622a768f32da33be43444e33099a41ff88227 Parents: 6c2eb77 Author: sunlan <[email protected]> Authored: Mon Aug 21 08:13:48 2017 +0800 Committer: sunlan <[email protected]> Committed: Mon Aug 21 08:13:48 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/797622a7/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 449bef1..fa98369 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; @@ -155,7 +154,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 = @@ -168,6 +167,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; @@ -4395,18 +4406,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
