You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2020/12/21 16:54:46 UTC

[groovy] branch GROOVY-9855 created (now ad8180a)

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

emilles pushed a change to branch GROOVY-9855
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at ad8180a  GROOVY-9855: inline string concat sonner

This branch includes the following new commits:

     new ad8180a  GROOVY-9855: inline string concat sonner

The 1 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.



[groovy] 01/01: GROOVY-9855: inline string concat sonner

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

emilles pushed a commit to branch GROOVY-9855
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit ad8180ae528113a2d6663d26567b24658747d2b3
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Dec 21 10:53:54 2020 -0600

    GROOVY-9855: inline string concat sonner
---
 .../java/org/apache/groovy/ast/tools/ExpressionUtils.java     | 11 +++++++++--
 .../groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy    | 11 +++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
index d85c9f1..fcf33e3 100644
--- a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
@@ -309,8 +309,15 @@ public final class ExpressionUtils {
             }
         } else if (exp instanceof BinaryExpression) {
             BinaryExpression be = (BinaryExpression) exp;
-            be.setLeftExpression(transformInlineConstants(be.getLeftExpression()));
-            be.setRightExpression(transformInlineConstants(be.getRightExpression()));
+            Expression lhs = transformInlineConstants(be.getLeftExpression());
+            Expression rhs = transformInlineConstants(be.getRightExpression());
+            if (lhs instanceof ConstantExpression && rhs instanceof ConstantExpression &&
+                    lhs.getType().equals(ClassHelper.STRING_TYPE) && rhs.getType().equals(ClassHelper.STRING_TYPE)) {
+                // GROOVY-9855: inline string concat
+                return configure(be, new ConstantExpression(lhs.getText() + rhs.getText()));
+            }
+            be.setLeftExpression(lhs);
+            be.setRightExpression(rhs);
             return be;
         } else if (exp instanceof ListExpression) {
             ListExpression origList = (ListExpression) exp;
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index b61a949..272327c 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -898,6 +898,17 @@ import org.codehaus.groovy.ast.stmt.AssertStatement
         '''
     }
 
+    // GROOVY-9855
+    void testShouldInlineStringConcatInTypeAnnotation() {
+        assertScript '''
+            @SuppressWarnings(C.PREFIX + 'checked') // not 'un'.plus('checked')
+            class C {
+                public static final String PREFIX = 'un'
+            }
+            new C()
+        '''
+    }
+
     void testImplicitPropertyOfDelegateShouldNotPreferField() {
         assertScript '''
             Calendar.instance.with {