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 2022/04/29 18:41:13 UTC

[groovy] branch danielsun/tweak-plus updated (6062b8f29c -> ba2a734efe)

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

sunlan pushed a change to branch danielsun/tweak-plus
in repository https://gitbox.apache.org/repos/asf/groovy.git


 discard 6062b8f29c Tweak plus operation for `Object` instance to align with Java
     new ba2a734efe Tweak plus operation for `Object` instance to align with Java

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   (6062b8f29c)
            \
             N -- N -- N   refs/heads/danielsun/tweak-plus (ba2a734efe)

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:
 .../groovy/runtime/DefaultGroovyMethods.java       | 33 ----------------------
 .../vmplugin/v8/PluginDefaultGroovyMethods.java    | 33 ++++++++++++++++++++++
 .../bugs/{Groovy9063.groovy => Groovy10612.groovy} | 29 +++++++++----------
 3 files changed, 47 insertions(+), 48 deletions(-)
 copy src/test/groovy/bugs/{Groovy9063.groovy => Groovy10612.groovy} (69%)


[groovy] 01/01: Tweak plus operation for `Object` instance to align with Java

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

sunlan pushed a commit to branch danielsun/tweak-plus
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit ba2a734efe6fb9d16e0700786f1fdb87f4162b84
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Apr 30 02:38:08 2022 +0800

    Tweak plus operation for `Object` instance to align with Java
---
 .../vmplugin/v8/PluginDefaultGroovyMethods.java    | 33 +++++++++++++++
 src/test/groovy/bugs/Groovy10612.groovy            | 47 ++++++++++++++++++++++
 2 files changed, 80 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethods.java
index 13023ff322..d03517dfc2 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethods.java
@@ -24,6 +24,7 @@ import groovy.lang.GString;
 import groovy.lang.IntRange;
 import groovy.transform.stc.ClosureParams;
 import groovy.transform.stc.FirstParam;
+import org.codehaus.groovy.runtime.DefaultGroovyMethods;
 import org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport;
 import org.codehaus.groovy.runtime.InvokerHelper;
 import org.codehaus.groovy.runtime.NullObject;
@@ -505,6 +506,38 @@ public class PluginDefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         return self + value;
     }
 
+    /**
+     * Appends a String to the literal of the Object instance.
+     *
+     * <pre class="groovyTestCase">
+     * assert '[a:1] is a map' == [a:1] + ' is a map'
+     * </pre>
+     *
+     * @param left  a Object
+     * @param right a String
+     * @return the concatenated string
+     * @since 4.0.3
+     */
+    public static String plus(Object left, String right) {
+        return DefaultGroovyMethods.toString(left) + right;
+    }
+
+    /**
+     * Appends a GString to the literal of the Object instance.
+     *
+     * <pre class="groovyTestCase">
+     * assert '[a:1] is a map' == [a:1] + " is ${'a'} map"
+     * </pre>
+     *
+     * @param left  a Object
+     * @param right a GString
+     * @return the concatenated string
+     * @since 4.0.3
+     */
+    public static String plus(Object left, GString right) {
+        return DefaultGroovyMethods.toString(left) + right;
+    }
+
     /**
      * Supports the range subscript operator for StringBuilder.
      *
diff --git a/src/test/groovy/bugs/Groovy10612.groovy b/src/test/groovy/bugs/Groovy10612.groovy
new file mode 100644
index 0000000000..65c4b0908a
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10612.groovy
@@ -0,0 +1,47 @@
+/*
+ *  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 bugs
+
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+class Groovy10612 {
+    @Test
+    void testStringConcatenationWithPlus() {
+        assertScript '''
+            assert '[a:1] is a map' == [a:1] + ' is a map'
+            assert '[a:1] is a map' == [a:1] + " is ${'a'} map"
+        '''
+    }
+
+    @Test
+    void testStringConcatenationWithPlus_CS() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            def m() {
+                assert '[a:1] is a map' == [a:1] + ' is a map'
+                assert '[a:1] is a map' == [a:1] + " is ${'a'} map"
+            }
+            m()
+        '''
+    }
+}