This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 52e07dd6c3 GROOVY-11656: Create SGM#getLength methods for
StringBuilder/StringBuffer
52e07dd6c3 is described below
commit 52e07dd6c3a90a3b0f6ab8f26e98b6adb262bc99
Author: Paul King <[email protected]>
AuthorDate: Wed May 7 11:25:50 2025 +1000
GROOVY-11656: Create SGM#getLength methods for StringBuilder/StringBuffer
---
.../groovy/runtime/StringGroovyMethods.java | 42 ++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
index bc91ee2647..0500bed10a 100644
--- a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -2795,6 +2795,48 @@ public class StringGroovyMethods extends
DefaultGroovyMethodsSupport {
return self.length();
}
+ /**
+ * Provides a {@code getLength} alias for {@code length} for {@link
StringBuilder},
+ * supporting assignment arithmetic operator expressions involving
+ * the otherwise write-only length property.
+ *
+ * <pre class="groovyTestCase">
+ * def sb = new StringBuilder()
+ * sb << 'foobar'
+ * sb.length -= 3
+ * assert sb.toString() == 'foo'
+ * </pre>
+ *
+ * @param self a StringBuilder
+ * @return the length of the StringBuilder
+ *
+ * @since 5.0.0
+ */
+ public static int getLength(final StringBuilder self) {
+ return self.length();
+ }
+
+ /**
+ * Provides a {@code getLength} alias for {@code length} for {@link
StringBuffer},
+ * supporting assignment arithmetic operator expressions involving
+ * the otherwise write-only length property.
+ *
+ * <pre class="groovyTestCase">
+ * def sb = new StringBuffer()
+ * sb << 'foobar'
+ * sb.length -= 3
+ * assert sb.toString() == 'foo'
+ * </pre>
+ *
+ * @param self a StringBuffer
+ * @return the length of the StringBuffer
+ *
+ * @since 5.0.0
+ */
+ public static int getLength(final StringBuffer self) {
+ return self.length();
+ }
+
/**
* Provides the standard Groovy {@code size()} method for {@code Matcher}.
*