1 19 20 package jode.type; 21 import jode.AssertError; 22 import jode.GlobalOptions; 23 import java.util.Hashtable ; 24 25 54 public class RangeType extends Type { 55 69 final ReferenceType bottomType; 70 74 final ReferenceType topType; 75 76 79 public RangeType(ReferenceType bottomType, 80 ReferenceType topType) { 81 super(TC_RANGE); 82 if (bottomType == tNull) 83 throw new jode.AssertError("bottom is NULL"); 84 this.bottomType = bottomType; 85 this.topType = topType; 86 } 87 88 93 public ReferenceType getBottom() { 94 return bottomType; 95 } 96 97 102 public ReferenceType getTop() { 103 return topType; 104 } 105 106 107 114 public Type getHint() { 115 Type bottomHint = bottomType.getHint(); 116 Type topHint = topType.getHint(); 117 118 if (topType == tNull && bottomType.equals(bottomHint)) 119 return bottomHint; 120 121 return topHint; 122 } 123 124 129 public Type getCanonic() { 130 return topType.getCanonic(); 131 } 132 133 138 public Type getSuperType() { 139 return topType.getSuperType(); 140 } 141 142 147 public Type getSubType() { 148 return tRange(bottomType, tNull); 149 } 150 151 156 public Type getCastHelper(Type fromType) { 157 return topType.getCastHelper(fromType); 158 } 159 160 public String getTypeSignature() { 161 if (topType.isClassType() || !bottomType.isValidType()) 162 return topType.getTypeSignature(); 163 else 164 return bottomType.getTypeSignature(); 165 } 166 167 public Class getTypeClass() throws ClassNotFoundException { 168 if (topType.isClassType() || !bottomType.isValidType()) 169 return topType.getTypeClass(); 170 else 171 return bottomType.getTypeClass(); 172 } 173 174 public String toString() 175 { 176 return "<" + bottomType + "-" + topType + ">"; 177 } 178 179 public String getDefaultName() { 180 throw new AssertError("getDefaultName() called on range"); 181 } 182 183 public int hashCode() { 184 int hashcode = topType.hashCode(); 185 return (hashcode << 16 | hashcode >>> 16) ^ bottomType.hashCode(); 186 } 187 188 public boolean equals(Object o) { 189 if (o instanceof RangeType) { 190 RangeType type = (RangeType) o; 191 return topType.equals(type.topType) 192 && bottomType.equals(type.bottomType); 193 } 194 return false; 195 } 196 197 202 public Type intersection(Type type) { 203 if (type == tError) 204 return type; 205 if (type == Type.tUnknown) 206 return this; 207 208 Type top, bottom, result; 209 bottom = bottomType.getSpecializedType(type); 210 top = topType.getGeneralizedType(type); 211 if (top.equals(bottom)) 212 result = top; 213 else if (top instanceof ReferenceType 214 && bottom instanceof ReferenceType) 215 result = ((ReferenceType)top) 216 .createRangeType((ReferenceType)bottom); 217 else 218 result = tError; 219 220 if ((GlobalOptions.debuggingFlags & GlobalOptions.DEBUG_TYPES) != 0) { 221 GlobalOptions.err.println("intersecting "+ this +" and "+ type + 222 " to " + result); 223 } 224 return result; 225 } 226 } 227 228 | Popular Tags |