Skip to content

Commit 31df88c

Browse files
authored
Merge pull request #29 from diffblue/danpoe/feature/string-method-models
Add models for setLength() and setCharAt() of StringBuilder
2 parents b545958 + f29b223 commit 31df88c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/main/java/java/lang/StringBuilder.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,4 +679,29 @@ public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
679679
toString().getChars(srcBegin, srcEnd, dst, dstBegin);
680680
}
681681

682+
/**
683+
* @throws IndexOutOfBoundsException {@inheritDoc}
684+
* @see #length()
685+
*
686+
* @diffblue.fullSupport
687+
*/
688+
@Override
689+
public void setLength(int newLength) {
690+
if (newLength < 0)
691+
throw new StringIndexOutOfBoundsException(newLength);
692+
CProverString.setLength(this, newLength);
693+
}
694+
695+
/**
696+
* @throws IndexOutOfBoundsException {@inheritDoc}
697+
* @see #length()
698+
*
699+
* @diffblue.fullSupport
700+
*/
701+
@Override
702+
public void setCharAt(int index, char ch) {
703+
if ((index < 0) || (index >= this.length()))
704+
throw new StringIndexOutOfBoundsException(index);
705+
CProverString.setCharAt(this, index, ch);
706+
}
682707
}

src/main/java/org/cprover/CProverString.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ public static StringBuilder insert(
181181
public static void setLength(StringBuffer instance, int newLength) {
182182
}
183183

184+
/**
185+
* Sets the length of the character sequence.
186+
*
187+
* @param instance the StringBuilder instance
188+
* @param newLength the new length
189+
*/
190+
public static void setLength(StringBuilder instance, int newLength) {
191+
}
192+
184193
/**
185194
* Returns the {@code char} value in this sequence at the specified index.
186195
*
@@ -202,6 +211,16 @@ public static char charAt(StringBuffer instance, int index) {
202211
public static void setCharAt(StringBuffer instance, int index, char c) {
203212
}
204213

214+
/**
215+
* The character at the specified index is set to {@code ch}.
216+
*
217+
* @param instance the StringBuilder instance
218+
* @param index the index of the character to modify.
219+
* @param c the new character.
220+
*/
221+
public static void setCharAt(StringBuilder instance, int index, char c) {
222+
}
223+
205224
/**
206225
* Removes the characters in a substring of this sequence.
207226
*

0 commit comments

Comments
 (0)