1 19 20 package org.netbeans.modules.debugger.jpda.models; 21 22 import com.sun.jdi.*; 23 import org.netbeans.api.debugger.jpda.InvalidExpressionException; 24 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl; 25 26 27 30 class ArrayFieldVariable extends AbstractVariable implements 31 org.netbeans.api.debugger.jpda.Field { 32 33 final ArrayReference array; 34 int index; 35 int maxIndexLog; 36 private String declaredType; 37 38 ArrayFieldVariable ( 39 JPDADebuggerImpl debugger, 40 Value value, 41 String declaredType, 42 ArrayReference array, 43 int index, 44 int maxIndex, 45 String parentID 46 ) { 47 super ( 48 debugger, 49 value, 50 parentID + '.' + index + 51 (value instanceof ObjectReference ? "^" : "") 52 ); 53 this.index = index; 54 this.maxIndexLog = log10(maxIndex); 55 this.declaredType = declaredType; 56 this.array = array; 57 } 58 59 60 62 63 68 public String getName () { 69 int num0 = maxIndexLog - log10(index); 70 if (num0 > 0) { 71 return "[" + zeros(num0) + index + "]"; 72 } else { 73 return "[" + index + "]"; 74 } 75 } 76 77 static int log10(int n) { 78 int l = 1; 79 while ((n = n / 10) > 0) l++; 80 return l; 81 } 82 83 private static final String ZEROS = " "; 86 static String zeros(int n) { 87 if (n < ZEROS.length()) { 88 return ZEROS.substring(0, n); 89 } else { 90 String z = ZEROS; 91 while (z.length() < n) z += " "; return z; 93 } 94 } 95 96 101 public String getClassName () { 102 return getType (); 103 } 104 105 110 public boolean isStatic () { 111 return false; 112 } 113 114 119 public String getDeclaredType () { 120 return declaredType; 121 } 122 123 129 protected void setValue (Value value) throws InvalidExpressionException { 130 try { 131 array.setValue(index, value); 132 } catch (InvalidTypeException ex) { 133 throw new InvalidExpressionException (ex); 134 } catch (ClassNotLoadedException ex) { 135 throw new InvalidExpressionException (ex); 136 } 137 } 138 139 public ArrayFieldVariable clone() { 140 ArrayFieldVariable clon = new ArrayFieldVariable( 141 getDebugger(), 142 getJDIValue(), 143 declaredType, 144 array, 145 index, 146 0, 147 getID().substring(0, getID().length() - ('.' + index + (getJDIValue() instanceof ObjectReference ? "^" : "")).length())); 148 clon.maxIndexLog = this.maxIndexLog; 149 return clon; 150 } 151 152 154 public String toString () { 155 return "FieldVariable " + getName (); 156 } 157 } 158 159 | Popular Tags |