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 00:44:17 UTC

groovy git commit: Cache the AST generated by Parrot

Repository: groovy
Updated Branches:
  refs/heads/master 4788991f8 -> bcadf9072


Cache the AST generated by Parrot


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

Branch: refs/heads/master
Commit: bcadf90727c2897651525e45bcb0cb063529544a
Parents: 4788991
Author: sunlan <su...@apache.org>
Authored: Thu Jul 20 08:43:56 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Thu Jul 20 08:44:10 2017 +0800

----------------------------------------------------------------------
 .../parser/antlr4/Antlr4ParserPlugin.java       | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/bcadf907/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 4d91d29..0d7136c 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
@@ -25,6 +25,8 @@ import org.codehaus.groovy.control.SourceUnit;
 import org.codehaus.groovy.syntax.ParserException;
 import org.codehaus.groovy.syntax.Reduction;
 
+import java.io.IOException;
+
 /**
  * A parser plugin for the new parser
  *
@@ -32,6 +34,8 @@ import org.codehaus.groovy.syntax.Reduction;
  * Created on    2016/08/14
  */
 public class Antlr4ParserPlugin implements ParserPlugin {
+    private ModuleNode moduleNode;
+
     @Override
     public Reduction parseCST(SourceUnit sourceUnit, java.io.Reader reader) throws CompilationFailedException {
         return null;
@@ -39,7 +43,21 @@ public class Antlr4ParserPlugin implements ParserPlugin {
 
     @Override
     public ModuleNode buildAST(SourceUnit sourceUnit, java.lang.ClassLoader classLoader, Reduction cst) throws ParserException {
+        if (null != this.moduleNode) {
+            return this.moduleNode;
+        }
+
+        try {
+            if (null == sourceUnit.getSource().getReader()) {
+                return moduleNode;
+            }
+        } catch (IOException e) {
+            return moduleNode;
+        }
+
         AstBuilder builder = new AstBuilder(sourceUnit, classLoader);
-        return builder.buildAST();
+        this.moduleNode = builder.buildAST();
+
+        return this.moduleNode;
     }
 }