1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.text.Editable;
4 import android.text.SpannableStringBuilder;
5 import com.xtremelabs.robolectric.internal.Implementation;
6 import com.xtremelabs.robolectric.internal.Implements;
7 import com.xtremelabs.robolectric.internal.RealObject;
8 
9 /**
10  * Shadow of {@code SpannableStringBuilder} implemented using a regular {@code StringBuilder}
11  */
12 @SuppressWarnings({"UnusedDeclaration"})
13 @Implements(SpannableStringBuilder.class)
14 public class ShadowSpannableStringBuilder implements CharSequence {
15     @RealObject private SpannableStringBuilder realSpannableStringBuilder;
16 
17     private StringBuilder builder = new StringBuilder();
18 
__constructor__(CharSequence text)19     public void __constructor__(CharSequence text) {
20         builder.append(text);
21     }
22 
23     @Implementation
append(char text)24     public SpannableStringBuilder append(char text) {
25         builder.append(text);
26         return realSpannableStringBuilder;
27     }
28 
29     @Implementation
replace(int st, int en, CharSequence text)30     public Editable replace(int st, int en, CharSequence text) {
31         builder.replace(st, en, text.toString());
32         return realSpannableStringBuilder;
33     }
34 
35     @Implementation
insert(int where, CharSequence text)36     public Editable insert(int where, CharSequence text) {
37         builder.insert(where, text.toString());
38         return realSpannableStringBuilder;
39     }
40 
41     @Implementation
append(CharSequence text)42     public SpannableStringBuilder append(CharSequence text) {
43         builder.append(text.toString());
44         return realSpannableStringBuilder;
45     }
46 
47     @Implementation
length()48     @Override public int length() {
49         return builder.length();
50     }
51 
52     @Implementation
charAt(int index)53     @Override public char charAt(int index) {
54         return builder.charAt(index);
55     }
56 
57     @Implementation
subSequence(int start, int end)58     @Override public CharSequence subSequence(int start, int end) {
59         return builder.subSequence(start, end);
60     }
61 
62     @Implementation
toString()63     public String toString() {
64         return builder.toString();
65     }
66 
67     @Implementation
delete( int start, int end )68     public SpannableStringBuilder delete( int start, int end ) {
69     	builder.delete( start, end );
70         return realSpannableStringBuilder;
71     }
72 }
73