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 17:24:51 UTC

[groovy] branch danielsun/tweak-plus created (now 6062b8f29c)

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


      at 6062b8f29c Tweak plus operation for `Object` instance to align with Java

This branch includes the following new commits:

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

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: 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 6062b8f29c345161bfbb8f70eeb3bb7a98dd51a9
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Apr 30 01:23:58 2022 +0800

    Tweak plus operation for `Object` instance to align with Java
---
 .../groovy/runtime/DefaultGroovyMethods.java       | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index baa6e62639..8c6c8b4061 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -24,6 +24,7 @@ import groovy.lang.DelegatesTo;
 import groovy.lang.DelegatingMetaClass;
 import groovy.lang.EmptyRange;
 import groovy.lang.ExpandoMetaClass;
+import groovy.lang.GString;
 import groovy.lang.GroovyObject;
 import groovy.lang.GroovyRuntimeException;
 import groovy.lang.GroovySystem;
@@ -15668,6 +15669,38 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
         return plus(Integer.valueOf(left), right);
     }
 
+    /**
+     * Concatenate an object literal with a string
+     *
+     * <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.2
+     */
+    public static String plus(Object left, String right) {
+        return toString(left) + right;
+    }
+
+    /**
+     * Concatenate an object literal with a gstring
+     *
+     * <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.2
+     */
+    public static String plus(Object left, GString right) {
+        return toString(left) + right;
+    }
+
     /**
      * Compare a Character and a Number. The ordinal value of the Character
      * is used in the comparison (the ordinal value is the unicode