1 11 package org.eclipse.jdt.internal.debug.core.model; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 import org.eclipse.debug.core.DebugException; 19 import org.eclipse.jdi.TimeoutException; 20 import org.eclipse.jdt.debug.core.IJavaType; 21 import org.eclipse.jdt.debug.core.JDIDebugModel; 22 23 import com.sun.jdi.ArrayType; 24 import com.sun.jdi.ClassType; 25 import com.sun.jdi.InterfaceType; 26 import com.sun.jdi.Type; 27 28 31 public class JDIType extends JDIDebugElement implements IJavaType { 32 33 36 private Type fType; 37 38 45 protected JDIType(JDIDebugTarget target, Type type) { 46 super(target); 47 setUnderlyingType(type); 48 } 49 50 58 public void requestFailed(String message, Throwable e, int code) throws DebugException { 59 throwDebugException(message, code, e); 60 } 61 62 66 protected void throwDebugException(String message, int code, Throwable exception) throws DebugException { 67 throw new DebugException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), 68 code, message, exception)); 69 } 70 71 80 public void targetRequestFailed(String message, RuntimeException e) throws DebugException { 81 if (e == null || e.getClass().getName().startsWith("com.sun.jdi") || e instanceof TimeoutException) { requestFailed(message, e, DebugException.TARGET_REQUEST_FAILED); 83 } else { 84 throw e; 85 } 86 } 87 88 92 public static JDIType createType(JDIDebugTarget target, Type type) { 93 if (type instanceof ArrayType) { 94 return new JDIArrayType(target, (ArrayType)type); 95 } 96 if (type instanceof ClassType) { 97 return new JDIClassType(target, (ClassType)type); 98 } 99 if (type instanceof InterfaceType) { 100 return new JDIInterfaceType(target, (InterfaceType)type); 101 } 102 return new JDIType(target, type); 103 } 104 105 108 public String getSignature() throws DebugException { 109 try { 110 return getUnderlyingType().signature(); 111 } catch (RuntimeException e) { 112 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIType_exception_while_retrieving_signature, new String [] {e.toString()}), e); 113 return null; 116 } 117 } 118 119 124 public Type getUnderlyingType() { 125 return fType; 126 } 127 128 133 protected void setUnderlyingType(Type type) { 134 fType = type; 135 } 136 137 140 public String toString() { 141 return getUnderlyingType().toString(); 142 } 143 144 147 public String getName() throws DebugException { 148 try { 149 return getUnderlyingType().name(); 150 } catch (RuntimeException e) { 151 targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIType_exception_while_retrieving_type_name, new String []{e.toString()}), e); 152 } 153 return null; 156 } 157 158 161 public boolean equals(Object object) { 162 return object instanceof JDIType && fType.equals(((JDIType)object).fType); 163 } 164 165 168 public int hashCode() { 169 return fType.hashCode(); 170 } 171 172 } 173 | Popular Tags |