1 11 package org.eclipse.jdi.internal; 12 13 14 import java.io.DataInputStream ; 15 import java.io.DataOutputStream ; 16 import java.io.IOException ; 17 import com.ibm.icu.text.MessageFormat; 18 19 import com.sun.jdi.AbsentInformationException; 20 import com.sun.jdi.Location; 21 import com.sun.jdi.Method; 22 import com.sun.jdi.ReferenceType; 23 24 30 public class LocationImpl extends MirrorImpl implements Location { 31 32 public static final int LINE_NR_NOT_AVAILABLE = -1; 33 34 35 MethodImpl fMethod; 36 37 long fIndex; 38 39 42 public LocationImpl(VirtualMachineImpl vmImpl, MethodImpl method, long index) { 43 super("Location", vmImpl); fMethod = method; 45 fIndex = index; 46 } 47 48 51 public long codeIndex() { 52 return fIndex; 53 } 54 55 58 public ReferenceType declaringType() { 59 return fMethod.declaringType(); 60 } 61 62 65 public int hashCode() { 66 return fMethod.hashCode() + (int)fIndex; 67 } 68 69 73 public boolean equals(Object object) { 74 if (object != null && object.getClass().equals(this.getClass())) { 75 LocationImpl loc = (LocationImpl)object; 76 return fMethod.equals(loc.fMethod) && fIndex == loc.fIndex; 77 } 78 return false; 79 } 80 81 84 public int compareTo(Object object) { 85 if (object == null || !object.getClass().equals(this.getClass())) 86 throw new ClassCastException (JDIMessages.LocationImpl_Can__t_compare_location_to_given_object_1); 87 88 LocationImpl location2 = (LocationImpl)object; 90 if (!method().equals(location2.method())) 91 return method().compareTo(location2.method()); 92 93 if (codeIndex() < 0 || location2.codeIndex() < 0) 96 throw new InternalError (JDIMessages.LocationImpl_Code_indexes_are_assumed_to_be_always_positive_2); 97 98 if (codeIndex() < location2.codeIndex()) 99 return -1; 100 else if (codeIndex() > location2.codeIndex()) 101 return 1; 102 else return 0; 103 } 104 105 108 public int lineNumber() { 109 return lineNumber(virtualMachine().getDefaultStratum()); 110 } 111 112 115 public Method method() { 116 return fMethod; 117 } 118 119 122 public String sourceName() throws AbsentInformationException { 123 return sourceName(virtualMachine().getDefaultStratum()); 124 } 125 126 129 public String toString() { 130 try { 131 return MessageFormat.format(JDIMessages.LocationImpl_sourcename___0___line___1__3, new String []{sourceName(), Integer.toString(lineNumber())}); 132 } catch (Exception e) { 133 return fDescription; 134 } 135 } 136 137 140 public void write(MirrorImpl target, DataOutputStream out) throws IOException { 141 fMethod.writeWithReferenceTypeWithTag(target, out); 142 target.writeLong(fIndex, "index", out); } 144 145 148 public static LocationImpl read(MirrorImpl target, DataInputStream in) throws IOException { 149 VirtualMachineImpl vmImpl = target.virtualMachineImpl(); 150 MethodImpl method = MethodImpl.readWithReferenceTypeWithTag(target, in); 152 long index = target.readLong("index", in); if (method == null) { 154 return null; 155 } 156 return new LocationImpl(vmImpl, method, index); 157 } 158 159 162 public int lineNumber(String stratum) { 163 return fMethod.referenceTypeImpl().lineNumber(fIndex, fMethod, stratum); 164 } 165 166 169 public String sourceName(String stratum) throws AbsentInformationException { 170 return fMethod.referenceTypeImpl().sourceName(fIndex, fMethod, stratum); 171 } 172 173 176 public String sourcePath(String stratum) throws AbsentInformationException { 177 return fMethod.referenceTypeImpl().sourcePath(fIndex, fMethod, stratum); 178 } 179 180 183 public String sourcePath() throws AbsentInformationException { 184 return sourcePath(virtualMachine().getDefaultStratum()); 185 } 186 187 } 188 | Popular Tags |