groovy git commit: Fix the NPE issue of org.codehaus.groovy.tools.gse.DependencyTest.testDep when Parrot enabled by default

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

groovy git commit: Fix the NPE issue of org.codehaus.groovy.tools.gse.DependencyTest.testDep when Parrot enabled by default

Daniel.Sun
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 47d7d1506 -> 30f09b2f5


Fix the NPE issue of org.codehaus.groovy.tools.gse.DependencyTest.testDep when Parrot enabled by default

(cherry picked from commit 24e30be)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 30f09b2f597a6287098ac5c8778893787895d399
Parents: 47d7d15
Author: sunlan <[hidden email]>
Authored: Thu Jul 20 23:00:12 2017 +0800
Committer: sunlan <[hidden email]>
Committed: Thu Jul 20 23:03:41 2017 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/control/SourceUnit.java |  4 ++++
 .../parser/antlr4/Antlr4ParserPlugin.java       | 21 +++++++++++++++-----
 .../apache/groovy/parser/antlr4/AstBuilder.java |  4 +---
 3 files changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/30f09b2f/src/main/org/codehaus/groovy/control/SourceUnit.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/SourceUnit.java b/src/main/org/codehaus/groovy/control/SourceUnit.java
index b2c8a32..2dcb82a 100644
--- a/src/main/org/codehaus/groovy/control/SourceUnit.java
+++ b/src/main/org/codehaus/groovy/control/SourceUnit.java
@@ -354,4 +354,8 @@ public class SourceUnit extends ProcessingUnit {
     }
 
     public ReaderSource getSource() { return source; }
+
+    public void setSource(ReaderSource source) {
+        this.source = source;
+    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/30f09b2f/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java
index a07d9a7..31ad35f 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/Antlr4ParserPlugin.java
@@ -18,13 +18,19 @@
  */
 package org.apache.groovy.parser.antlr4;
 
+import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.ast.ModuleNode;
 import org.codehaus.groovy.control.CompilationFailedException;
 import org.codehaus.groovy.control.ParserPlugin;
 import org.codehaus.groovy.control.SourceUnit;
+import org.codehaus.groovy.control.io.ReaderSource;
+import org.codehaus.groovy.control.io.StringReaderSource;
+import org.codehaus.groovy.runtime.IOGroovyMethods;
 import org.codehaus.groovy.syntax.ParserException;
 import org.codehaus.groovy.syntax.Reduction;
 
+import java.io.IOException;
+
 /**
  * A parser plugin for the new parser
  *
@@ -32,22 +38,27 @@ import org.codehaus.groovy.syntax.Reduction;
  * Created on    2016/08/14
  */
 public class Antlr4ParserPlugin implements ParserPlugin {
-    private ModuleNode moduleNode;
+    private ReaderSource readerSource;
 
     @Override
     public Reduction parseCST(SourceUnit sourceUnit, java.io.Reader reader) throws CompilationFailedException {
+        try {
+            this.readerSource = new StringReaderSource(IOGroovyMethods.getText(reader), sourceUnit.getConfiguration());
+        } catch (IOException e) {
+            throw new GroovyBugError("Failed to create StringReaderSource instance", e);
+        }
+
         return null;
     }
 
     @Override
     public ModuleNode buildAST(SourceUnit sourceUnit, java.lang.ClassLoader classLoader, Reduction cst) throws ParserException {
-        if (null != this.moduleNode) {
-            return this.moduleNode;
+        if (null != this.readerSource) {
+            sourceUnit.setSource(this.readerSource);
         }
 
         AstBuilder builder = new AstBuilder(sourceUnit, classLoader);
-        this.moduleNode = builder.buildAST();
 
-        return this.moduleNode;
+        return builder.buildAST();
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/30f09b2f/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 3709576..5fed43e 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
@@ -4401,9 +4401,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
     private String readSourceCode(SourceUnit sourceUnit) {
         String text = null;
         try {
-            text = IOGroovyMethods.getText(
-                    new BufferedReader(
-                            sourceUnit.getSource().getReader()));
+            text = IOGroovyMethods.getText(sourceUnit.getSource().getReader());
         } catch (IOException e) {
             LOGGER.severe(createExceptionMessage(e));
             throw new RuntimeException("Error occurred when reading source code.", e);

Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun