Skip to content

Commit 52e07dd

Browse files
committed
GROOVY-11656: Create SGM#getLength methods for StringBuilder/StringBuffer
1 parent 0c82aee commit 52e07dd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,6 +2795,48 @@ public static int size(final CharSequence self) {
27952795
return self.length();
27962796
}
27972797

2798+
/**
2799+
* Provides a {@code getLength} alias for {@code length} for {@link StringBuilder},
2800+
* supporting assignment arithmetic operator expressions involving
2801+
* the otherwise write-only length property.
2802+
*
2803+
* <pre class="groovyTestCase">
2804+
* def sb = new StringBuilder()
2805+
* sb << 'foobar'
2806+
* sb.length -= 3
2807+
* assert sb.toString() == 'foo'
2808+
* </pre>
2809+
*
2810+
* @param self a StringBuilder
2811+
* @return the length of the StringBuilder
2812+
*
2813+
* @since 5.0.0
2814+
*/
2815+
public static int getLength(final StringBuilder self) {
2816+
return self.length();
2817+
}
2818+
2819+
/**
2820+
* Provides a {@code getLength} alias for {@code length} for {@link StringBuffer},
2821+
* supporting assignment arithmetic operator expressions involving
2822+
* the otherwise write-only length property.
2823+
*
2824+
* <pre class="groovyTestCase">
2825+
* def sb = new StringBuffer()
2826+
* sb << 'foobar'
2827+
* sb.length -= 3
2828+
* assert sb.toString() == 'foo'
2829+
* </pre>
2830+
*
2831+
* @param self a StringBuffer
2832+
* @return the length of the StringBuffer
2833+
*
2834+
* @since 5.0.0
2835+
*/
2836+
public static int getLength(final StringBuffer self) {
2837+
return self.length();
2838+
}
2839+
27982840
/**
27992841
* Provides the standard Groovy {@code size()} method for {@code Matcher}.
28002842
*

0 commit comments

Comments
 (0)