1 11 package org.eclipse.jdi.internal; 12 13 14 import com.sun.jdi.ClassNotLoadedException; 15 import com.sun.jdi.LocalVariable; 16 import com.sun.jdi.StackFrame; 17 import com.sun.jdi.Type; 18 import com.sun.jdi.VMMismatchException; 19 20 26 public class LocalVariableImpl extends MirrorImpl implements LocalVariable { 27 28 private MethodImpl fMethod; 29 30 private long fCodeIndex; 31 32 private String fName; 33 34 private String fSignature; 35 36 private String fGenericSignature; 37 38 private Type fType; 39 40 private String fTypeName; 41 52 private int fLength; 53 54 private int fSlot; 55 56 private boolean fIsArgument; 57 58 public LocalVariableImpl(VirtualMachineImpl vmImpl, MethodImpl method, long codeIndex, String name, String signature, String genericSignature, int length, int slot, boolean isArgument) { 59 super("LocalVariable", vmImpl); fMethod = method; 61 fCodeIndex = codeIndex; 62 fName = name; 63 fSignature = signature; 64 fGenericSignature= genericSignature; 65 fLength = length; 66 fSlot = slot; 67 fIsArgument = isArgument; 68 } 69 70 73 public int slot() { 74 return fSlot; 75 } 76 77 80 public int hashCode() { 81 return fMethod.hashCode() + (int)fCodeIndex + fSlot; 82 } 83 84 88 public boolean equals(Object object) { 89 if (object != null && object.getClass().equals(this.getClass())) { 90 LocalVariableImpl loc = (LocalVariableImpl)object; 91 return fMethod.equals(loc.fMethod) && fCodeIndex == loc.fCodeIndex && fSlot == loc.fSlot; 92 } 93 return false; 94 } 95 96 99 public int compareTo(Object object) { 100 if (object == null || !object.getClass().equals(this.getClass())) 101 throw new ClassCastException (JDIMessages.LocalVariableImpl_Can__t_compare_local_variable_to_given_object_1); 102 103 LocalVariableImpl var2 = (LocalVariableImpl)object; 105 if (!method().equals(var2.method())) 106 return method().compareTo(var2.method()); 107 108 if (fCodeIndex < 0 || var2.fCodeIndex < 0) 111 throw new InternalError (JDIMessages.LocalVariableImpl_Code_indexes_are_assumed_to_be_always_positive_2); 112 113 long index2 = var2.fCodeIndex; 114 if (fCodeIndex < index2) 115 return -1; 116 else if (fCodeIndex > index2) 117 return 1; 118 else return 0; 119 } 120 121 124 public boolean isArgument() { 125 return fIsArgument; 126 } 127 128 public boolean isVisible(StackFrame frame) throws IllegalArgumentException , VMMismatchException { 129 checkVM(frame); 130 StackFrameImpl frameImpl = (StackFrameImpl)frame; 131 if (!fMethod.equals(frameImpl.location().method())) 132 throw new IllegalArgumentException (JDIMessages.LocalVariableImpl_The_stack_frame__s_method_does_not_match_this_variable__s_method_3); 133 134 if (fLength == -1) { 135 return true; 137 } 138 long currentIndex = frameImpl.location().codeIndex(); 139 140 if (currentIndex >= 0 && fCodeIndex >= 0 && fCodeIndex + fLength >= 0) 142 return fCodeIndex <= currentIndex && currentIndex < fCodeIndex + fLength; 143 144 throw new InternalError (JDIMessages.LocalVariableImpl_Code_indexes_are_assumed_to_be_always_positive_4); 145 } 146 147 150 public String name() { 151 return fName; 152 } 153 154 157 public String signature() { 158 return fSignature; 159 } 160 161 164 public Type type() throws ClassNotLoadedException { 165 if (fType == null) { 166 fType = TypeImpl.create(virtualMachineImpl(), fSignature, method().declaringType().classLoader()); 167 } 168 return fType; 169 } 170 171 174 public String typeName() { 175 if (fTypeName == null) { 176 fTypeName = TypeImpl.signatureToName(fSignature); 177 } 178 return fTypeName; 179 } 180 181 184 public byte tag() { 185 return TypeImpl.signatureToTag(fSignature); 186 } 187 188 191 public MethodImpl method() { 192 return fMethod; 193 } 194 195 198 public boolean isThis() { 199 return slot() == 0 && !method().isStatic(); 200 } 201 202 205 public String toString() { 206 return fName; 207 } 208 209 public String genericSignature() { 210 return fGenericSignature; 211 } 212 213 } 214 | Popular Tags |