1 30 package org.objectweb.asm.optimizer; 31 32 import org.objectweb.asm.ClassWriter; 33 34 39 class Constant { 40 41 49 char type; 50 51 54 int intVal; 55 56 59 long longVal; 60 61 64 float floatVal; 65 66 69 double doubleVal; 70 71 75 String strVal1; 76 77 81 String strVal2; 82 83 87 String strVal3; 88 89 92 int hashCode; 93 94 public Constant() { 95 } 96 97 public Constant(final Constant i) { 98 type = i.type; 99 intVal = i.intVal; 100 longVal = i.longVal; 101 floatVal = i.floatVal; 102 doubleVal = i.doubleVal; 103 strVal1 = i.strVal1; 104 strVal2 = i.strVal2; 105 strVal3 = i.strVal3; 106 hashCode = i.hashCode; 107 } 108 109 114 void set(final int intVal) { 115 this.type = 'I'; 116 this.intVal = intVal; 117 this.hashCode = 0x7FFFFFFF & (type + intVal); 118 } 119 120 125 void set(final long longVal) { 126 this.type = 'J'; 127 this.longVal = longVal; 128 this.hashCode = 0x7FFFFFFF & (type + (int) longVal); 129 } 130 131 136 void set(final float floatVal) { 137 this.type = 'F'; 138 this.floatVal = floatVal; 139 this.hashCode = 0x7FFFFFFF & (type + (int) floatVal); 140 } 141 142 147 void set(final double doubleVal) { 148 this.type = 'D'; 149 this.doubleVal = doubleVal; 150 this.hashCode = 0x7FFFFFFF & (type + (int) doubleVal); 151 } 152 153 161 void set( 162 final char type, 163 final String strVal1, 164 final String strVal2, 165 final String strVal3) 166 { 167 this.type = type; 168 this.strVal1 = strVal1; 169 this.strVal2 = strVal2; 170 this.strVal3 = strVal3; 171 switch (type) { 172 case 's': 173 case 'S': 174 case 'C': 175 hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()); 176 return; 177 case 'T': 178 hashCode = 0x7FFFFFFF & (type + strVal1.hashCode() 179 * strVal2.hashCode()); 180 return; 181 default: 185 hashCode = 0x7FFFFFFF & (type + strVal1.hashCode() 186 * strVal2.hashCode() * strVal3.hashCode()); 187 } 188 } 189 190 void write(final ClassWriter cw) { 191 switch (type) { 192 case 'I': 193 cw.newConst(new Integer (intVal)); 194 break; 195 case 'J': 196 cw.newConst(new Long (longVal)); 197 break; 198 case 'F': 199 cw.newConst(new Float (floatVal)); 200 break; 201 case 'D': 202 cw.newConst(new Double (doubleVal)); 203 break; 204 case 'S': 205 cw.newConst(strVal1); 206 break; 207 case 's': 208 cw.newUTF8(strVal1); 209 break; 210 case 'C': 211 cw.newClass(strVal1); 212 break; 213 case 'T': 214 cw.newNameType(strVal1, strVal2); 215 break; 216 case 'G': 217 cw.newField(strVal1, strVal2, strVal3); 218 break; 219 case 'M': 220 cw.newMethod(strVal1, strVal2, strVal3, false); 221 break; 222 case 'N': 223 cw.newMethod(strVal1, strVal2, strVal3, true); 224 break; 225 } 226 } 227 228 public boolean equals(final Object o) { 229 if (!(o instanceof Constant)) { 230 return false; 231 } 232 Constant c = (Constant) o; 233 if (c.type == type) { 234 switch (type) { 235 case 'I': 236 return c.intVal == intVal; 237 case 'J': 238 return c.longVal == longVal; 239 case 'F': 240 return c.floatVal == floatVal; 241 case 'D': 242 return c.doubleVal == doubleVal; 243 case 's': 244 case 'S': 245 case 'C': 246 return c.strVal1.equals(strVal1); 247 case 'T': 248 return c.strVal1.equals(strVal1) 249 && c.strVal2.equals(strVal2); 250 default: 254 return c.strVal1.equals(strVal1) 255 && c.strVal2.equals(strVal2) 256 && c.strVal3.equals(strVal3); 257 } 258 } 259 return false; 260 } 261 262 public int hashCode() { 263 return hashCode; 264 } 265 } 266 | Popular Tags |