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 2019/11/29 19:41:17 UTC

[groovy] branch GROOVY_3_0_X updated (4ac722d -> 03cbd0c)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 4ac722d  Minor refactoring: implement `AstStringCompiler` in Java
     new c71e5e3  Move `AstStringCompiler` to Java source root
     new 03cbd0c  Add a util `compile` method to `AstStringCompiler`

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../groovy/ast/builder/AstStringCompiler.java      | 14 ++++++++-
 .../ast/builder/AstStringCompilerTest.groovy}      | 36 ++++++++++------------
 2 files changed, 29 insertions(+), 21 deletions(-)
 rename src/main/{groovy => java}/org/codehaus/groovy/ast/builder/AstStringCompiler.java (87%)
 copy src/test/{groovy/MultilineChainExpressionTest.groovy => org/codehaus/groovy/ast/builder/AstStringCompilerTest.groovy} (59%)


[groovy] 02/02: Add a util `compile` method to `AstStringCompiler`

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 03cbd0c57ca2cf05ed26cc82a743e6f81464c8f3
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Nov 30 03:35:47 2019 +0800

    Add a util `compile` method to `AstStringCompiler`
    
    (cherry picked from commit df191fba050fee6a7d13a9554928ba557d389a79)
---
 .../groovy/ast/builder/AstStringCompiler.java      | 14 +++++++-
 .../ast/builder/AstStringCompilerTest.groovy       | 39 ++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/builder/AstStringCompiler.java b/src/main/java/org/codehaus/groovy/ast/builder/AstStringCompiler.java
index c48114e..8b4558a 100644
--- a/src/main/java/org/codehaus/groovy/ast/builder/AstStringCompiler.java
+++ b/src/main/java/org/codehaus/groovy/ast/builder/AstStringCompiler.java
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
 /**
  * This class handles converting Strings to ASTNode lists.
  */
-class AstStringCompiler {
+public class AstStringCompiler {
     /**
      * Performs the String source to {@link java.util.List} of {@link ASTNode}.
      *
@@ -44,6 +44,7 @@ class AstStringCompiler {
      * @param compilePhase
      *      the int based CompilePhase to compile it to.
      * @param statementsOnly
+     * @return {@link java.util.List} of {@link ASTNode}
      */
     public List<ASTNode> compile(String script, CompilePhase compilePhase, boolean statementsOnly) {
         final String scriptClassName = makeScriptClassName();
@@ -71,6 +72,17 @@ class AstStringCompiler {
         return result;
     }
 
+    /**
+     * Performs the String source to {@link java.util.List} of statement {@link ASTNode}.
+     *
+     * @param script a Groovy script in String form
+     * @return {@link java.util.List} of {@link ASTNode}
+     * @since 3.0.0
+     */
+    public List<ASTNode> compile(String script) {
+        return this.compile(script, CompilePhase.CONVERSION, true);
+    }
+
     private static String makeScriptClassName() {
         return "Script" + System.nanoTime();
     }
diff --git a/src/test/org/codehaus/groovy/ast/builder/AstStringCompilerTest.groovy b/src/test/org/codehaus/groovy/ast/builder/AstStringCompilerTest.groovy
new file mode 100644
index 0000000..575768e
--- /dev/null
+++ b/src/test/org/codehaus/groovy/ast/builder/AstStringCompilerTest.groovy
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.ast.builder
+
+import groovy.test.GroovyTestCase
+
+import static org.codehaus.groovy.ast.tools.GeneralUtils.block
+import static org.codehaus.groovy.ast.tools.GeneralUtils.constX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt
+
+class AstStringCompilerTest extends GroovyTestCase {
+    void testCompile() {
+        def actual = new AstStringCompiler().compile(""" "Hello World" """)
+        def expected = [
+                block(
+                        stmt(
+                                constX("Hello World")
+                        )
+                )
+        ]
+        AstAssert.assertSyntaxTree(expected, actual)
+    }
+}


[groovy] 01/02: Move `AstStringCompiler` to Java source root

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit c71e5e32ae70735271966d2765354b9831a90ee0
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Nov 30 02:43:06 2019 +0800

    Move `AstStringCompiler` to Java source root
    
    (cherry picked from commit fbfda5ee97ba36cbee918874da90215bd813b3ac)
---
 .../org/codehaus/groovy/ast/builder/AstStringCompiler.java                | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.java b/src/main/java/org/codehaus/groovy/ast/builder/AstStringCompiler.java
similarity index 100%
rename from src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.java
rename to src/main/java/org/codehaus/groovy/ast/builder/AstStringCompiler.java