1 11 package org.eclipse.jdt.internal.debug.core.logicalstructures; 12 13 import org.eclipse.debug.core.DebugException; 14 import org.eclipse.debug.core.model.IVariable; 15 import org.eclipse.jdt.debug.core.IJavaArrayType; 16 import org.eclipse.jdt.debug.core.IJavaObject; 17 import org.eclipse.jdt.debug.core.IJavaType; 18 import org.eclipse.jdt.debug.core.IJavaValue; 19 import org.eclipse.jdt.internal.debug.core.HeapWalkingManager; 20 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 21 import org.eclipse.jdt.internal.debug.core.model.JDIArrayValue; 22 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; 23 import org.eclipse.jdt.internal.debug.core.model.JDIPlaceholderValue; 24 import org.eclipse.jdt.internal.debug.core.model.JDIReferenceType; 25 26 import com.ibm.icu.text.MessageFormat; 27 28 35 public class JDIAllInstancesValue extends JDIArrayValue { 36 37 private IJavaObject[] fInstances; 38 private JDIReferenceType fRoot; 39 private IJavaArrayType fType; 40 private boolean fIsMoreThanPreference; 41 42 49 public JDIAllInstancesValue(JDIDebugTarget target, JDIReferenceType root) { 50 super(target, null); 51 fRoot = root; 52 try { 53 IJavaType[] javaTypes = target.getJavaTypes("java.lang.Object[]"); if (javaTypes.length > 0) { 55 fType = (IJavaArrayType) javaTypes[0]; 56 } 57 } catch (DebugException e) {} 58 } 59 60 63 protected IJavaObject[] getInstances(){ 64 if (fInstances != null){ 65 return fInstances; 66 } else { 67 IJavaObject[] instances = new IJavaObject[0]; 68 fIsMoreThanPreference = false; 69 if (fRoot != null){ 70 int max = HeapWalkingManager.getDefault().getAllInstancesMaxCount(); 71 try{ 72 if (max == 0){ 73 instances = fRoot.getInstances(max); 74 } else { 75 instances = fRoot.getInstances(max+1); 76 if (instances.length > max){ 77 instances[max] = new JDIPlaceholderValue((JDIDebugTarget)fRoot.getDebugTarget(),MessageFormat.format(LogicalStructuresMessages.JDIAllInstancesValue_2,new String []{Integer.toString(max)})); 78 fIsMoreThanPreference = true; 79 } 80 } 81 } catch (DebugException e) { 82 JDIDebugPlugin.log(e); 83 } 84 } 85 fInstances = instances; 86 return instances; 87 } 88 } 89 90 93 public synchronized int getLength() throws DebugException { 94 return getInstances().length; 95 } 96 97 100 public int getSize() throws DebugException { 101 return getInstances().length; 102 } 103 104 107 public IJavaValue getValue(int index) throws DebugException { 108 if(index > getInstances().length-1 || index < 0) { 109 internalError(LogicalStructuresMessages.JDIAllInstancesValue_0); 110 } 111 return getInstances()[index]; 112 } 113 114 117 public IJavaValue[] getValues() throws DebugException { 118 return getInstances(); 119 } 120 121 124 public IVariable getVariable(int offset) throws DebugException { 125 if(offset > getInstances().length-1 || offset < 0) { 126 internalError(LogicalStructuresMessages.JDIAllInstancesValue_1); 127 } 128 if(isMoreThanPreference() && offset == getInstances().length-1){ 129 return new JDIPlaceholderVariable(LogicalStructuresMessages.JDIAllInstancesValue_4, getInstances()[offset]); 130 } else { 131 return new JDIPlaceholderVariable(MessageFormat.format(LogicalStructuresMessages.JDIAllInstancesValue_5,new String []{Integer.toString(offset)}), getInstances()[offset]); 132 } 133 } 134 135 138 public IVariable[] getVariables(int offset, int length) throws DebugException { 139 if (length == 0){ 140 return new IVariable[0]; 141 } 142 if(offset > getInstances().length-1 || offset < 0) { 143 internalError(LogicalStructuresMessages.JDIAllInstancesValue_1); 144 } 145 IVariable[] vars = new JDIPlaceholderVariable[length]; 146 for (int i = 0; i < length; i++) { 147 vars[i] = getVariable(i + offset); 148 } 149 return vars; 150 } 151 152 155 public IVariable[] getVariables() throws DebugException { 156 return getVariables(0, getInstances().length); 157 } 158 159 162 public IJavaObject[] getReferringObjects(long max) throws DebugException { 163 return new IJavaObject[0]; 164 } 165 166 169 public boolean isAllocated() throws DebugException { 170 return getJavaDebugTarget().isAvailable(); 171 } 172 173 176 public int getInitialOffset() { 177 return 0; 178 } 179 180 183 public boolean hasVariables() throws DebugException { 184 return getInstances().length > 0; 185 } 186 187 190 public IJavaType getJavaType() throws DebugException { 191 return fType; 192 } 193 194 197 public String getSignature() throws DebugException { 198 return fType.getSignature(); 199 } 200 201 204 public String getReferenceTypeName() throws DebugException { 205 return fType.getName(); 206 } 207 208 211 public String getValueString() throws DebugException { 212 if (isMoreThanPreference()){ 213 return MessageFormat.format(LogicalStructuresMessages.JDIAllInstancesValue_7,new String []{Integer.toString(getInstances().length-1)}); 214 } else if (getInstances().length == 1) { 215 return MessageFormat.format(LogicalStructuresMessages.JDIAllInstancesValue_8,new String []{Integer.toString(getInstances().length)}); 216 } else { 217 return MessageFormat.format(LogicalStructuresMessages.JDIAllInstancesValue_9,new String []{Integer.toString(getInstances().length)}); 218 } 219 } 220 221 227 public String getDetailString(){ 228 StringBuffer buf = new StringBuffer (); 229 Object [] elements = getInstances(); 230 if (elements.length == 0){ 231 buf.append(LogicalStructuresMessages.JDIAllInstancesValue_10); 232 } 233 else{ 234 String length = null; 235 if (isMoreThanPreference()){ 236 length = MessageFormat.format(LogicalStructuresMessages.JDIAllInstancesValue_11,new String []{Integer.toString(elements.length-1)}); 237 } else { 238 length = Integer.toString(elements.length); 239 } 240 if (elements.length == 1){ 241 buf.append(MessageFormat.format(LogicalStructuresMessages.JDIAllInstancesValue_12,new String []{length})); 242 } else { 243 buf.append(MessageFormat.format(LogicalStructuresMessages.JDIAllInstancesValue_13,new String []{length})); 244 } 245 for (int i = 0; i < elements.length; i++) { 246 buf.append(elements[i] + "\n"); } 248 } 249 return buf.toString(); 250 } 251 252 255 protected boolean isMoreThanPreference() { 256 getInstances(); return fIsMoreThanPreference; 258 } 259 260 } 261 | Popular Tags |