You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/07/20 15:00:26 UTC

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

Repository: groovy
Updated Branches:
  refs/heads/master 13613d906 -> 24e30be40


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


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

Branch: refs/heads/master
Commit: 24e30be406225cf7c4fb2a45af9ae13470e241d3
Parents: 13613d9
Author: sunlan <su...@apache.org>
Authored: Thu Jul 20 23:00:12 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Thu Jul 20 23:00:12 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/24e30be4/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/24e30be4/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/24e30be4/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 4d4d253..2454fc4 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
@@ -4326,9 +4326,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);