You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/12/15 04:19:45 UTC

[groovy] branch GROOVY_2_5_X updated (da6699b -> 2cedccf)

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

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


    from da6699b  GROOVY-8898: Annotation value cannot take inline constant from enum.
     new 40cf362  remove unused import
     new 2cedccf  GROOVY-8927: String variants for take and drop

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/runtime/StringGroovyMethods.java        | 33 ++++++++++++++++++++--
 .../groovy/GroovyCharSequenceMethodsTest.groovy    | 12 ++++++++
 ...StringGMClosureParamTypeInferenceSTCTest.groovy |  4 ---
 3 files changed, 42 insertions(+), 7 deletions(-)


[groovy] 02/02: GROOVY-8927: String variants for take and drop

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

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

commit 2cedccfd9dab37c371b5eb746012f82a9d865ff3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Dec 14 23:24:04 2018 +1000

    GROOVY-8927: String variants for take and drop
---
 .../groovy/runtime/StringGroovyMethods.java        | 33 ++++++++++++++++++++--
 .../groovy/GroovyCharSequenceMethodsTest.groovy    | 12 ++++++++
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 3f55c58..ddca930 100644
--- a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -514,11 +514,25 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
      * @param num the number of characters to drop from this GString
      * @return a String consisting of all characters except the first <code>num</code> ones,
      *         or else an empty String, if the toString() of this GString has less than <code>num</code> characters.
-     * @see #drop(CharSequence, int)
+     * @see #drop(String, int)
      * @since 2.3.7
      */
     public static String drop(GString self, int num) {
-        return drop(self.toString(), num).toString();
+        return drop(self.toString(), num);
+    }
+
+    /**
+     * A String variant of the equivalent CharSequence method.
+     *
+     * @param self the original String
+     * @param num the number of characters to drop from this String
+     * @return a String consisting of all characters except the first <code>num</code> ones,
+     *         or else an empty String, if the String has less than <code>num</code> characters.
+     * @see #drop(CharSequence, int)
+     * @since 2.5.5
+     */
+    public static String drop(String self, int num) {
+        return (String) drop((CharSequence) self, num);
     }
 
     /**
@@ -3323,7 +3337,20 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 2.3.7
      */
     public static String take(GString self, int num) {
-        return (String) take(self.toString(), num);
+        return take(self.toString(), num);
+    }
+
+    /**
+     * A String variant of the equivalent CharSequence method.
+     *
+     * @param self the original String
+     * @param num  the number of chars to take from this String
+     * @return a String consisting of the first <code>num</code> chars,
+     *         or else the whole String if it has less then <code>num</code> elements.
+     * @since 2.5.5
+     */
+    public static String take(String self, int num) {
+        return (String) take((CharSequence) self, num);
     }
 
     /**
diff --git a/src/test/groovy/GroovyCharSequenceMethodsTest.groovy b/src/test/groovy/GroovyCharSequenceMethodsTest.groovy
index 3554e8d..f4111ca 100644
--- a/src/test/groovy/GroovyCharSequenceMethodsTest.groovy
+++ b/src/test/groovy/GroovyCharSequenceMethodsTest.groovy
@@ -132,6 +132,18 @@ class GroovyCharSequenceMethodsTest extends GroovyTestCase {
         assert cs2.drop(3) == 'bar'
     }
 
+    void testDropTakeTC() {
+        assertScript '''
+            @groovy.transform.TypeChecked
+            def method() {
+                assert 'Foo Bar'.drop(4).toLowerCase() == 'bar'
+                assert 'Foo Bar'.take(3).toLowerCase() == 'foo'
+            }
+
+            method()
+        '''
+    }
+
     void testAsBoolean() {
         assert cs1 && cs2
         assert !csEmpty


[groovy] 01/02: remove unused import

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

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

commit 40cf362d2118b0f17b77e73b1ebb2d7c77769d10
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Dec 14 19:58:37 2018 +1000

    remove unused import
---
 .../transform/stc/StringGMClosureParamTypeInferenceSTCTest.groovy     | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/src/test/groovy/transform/stc/StringGMClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/StringGMClosureParamTypeInferenceSTCTest.groovy
index 365dcf0..0724620 100644
--- a/src/test/groovy/transform/stc/StringGMClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/StringGMClosureParamTypeInferenceSTCTest.groovy
@@ -18,12 +18,8 @@
  */
 package groovy.transform.stc
 
-import groovy.transform.NotYetImplemented
-
 /**
  * Unit tests for static type checking : closure parameter type inference for {@link org.codehaus.groovy.runtime.StringGroovyMethods}.
- *
- * @author Cedric Champeau
  */
 class StringGMClosureParamTypeInferenceSTCTest extends StaticTypeCheckingTestCase {
     void testCollectReplacements() {