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/22 18:21:26 UTC

[groovy] branch GROOVY-9855 updated (ad8180a -> 659efd3)

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.


 discard ad8180a  GROOVY-9855: inline string concat sonner
     new 659efd3  GROOVY-9855: inline string concat sonner

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (ad8180a)
            \
             N -- N -- N   refs/heads/GROOVY-9855 (659efd3)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[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 659efd3d6adc55634abb4872db93af74df1d3c77
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..e5483ce 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 (be.getOperation().getType() == PLUS && 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 {