src/share/classes/com/sun/tools/javac/code/TargetType.java

changeset 1442
fcf89720ae71
parent 1357
c75be5bc5283
child 1521
71f35e4b93a5
equal deleted inserted replaced
1441:c78acf6c2f3e 1442:fcf89720ae71
164 UNKNOWN(-1); 164 UNKNOWN(-1);
165 165
166 static final int MAXIMUM_TARGET_TYPE_VALUE = 0x22; 166 static final int MAXIMUM_TARGET_TYPE_VALUE = 0x22;
167 167
168 private final int targetTypeValue; 168 private final int targetTypeValue;
169 private Set<TargetAttribute> flags; 169 private final Set<TargetAttribute> flags;
170 170
171 TargetType(int targetTypeValue, TargetAttribute... attributes) { 171 TargetType(int targetTypeValue, TargetAttribute... attributes) {
172 if (targetTypeValue < Byte.MIN_VALUE 172 if (targetTypeValue < Byte.MIN_VALUE
173 || targetTypeValue > Byte.MAX_VALUE) 173 || targetTypeValue > Byte.MAX_VALUE)
174 throw new AssertionError("attribute type value needs to be a byte: " + targetTypeValue); 174 throw new AssertionError("attribute type value needs to be a byte: " + targetTypeValue);
231 231
232 public int targetTypeValue() { 232 public int targetTypeValue() {
233 return this.targetTypeValue; 233 return this.targetTypeValue;
234 } 234 }
235 235
236 private static TargetType[] targets = null; 236 private static final TargetType[] targets;
237 237
238 private static TargetType[] buildTargets() { 238 static {
239 TargetType[] targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1]; 239 targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1];
240 TargetType[] alltargets = values(); 240 TargetType[] alltargets = values();
241 for (TargetType target : alltargets) { 241 for (TargetType target : alltargets) {
242 if (target.targetTypeValue >= 0) 242 if (target.targetTypeValue >= 0)
243 targets[target.targetTypeValue] = target; 243 targets[target.targetTypeValue] = target;
244 } 244 }
245 for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i) { 245 for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i) {
246 if (targets[i] == null) 246 if (targets[i] == null)
247 targets[i] = UNKNOWN; 247 targets[i] = UNKNOWN;
248 } 248 }
249 return targets;
250 } 249 }
251 250
252 public static boolean isValidTargetTypeValue(int tag) { 251 public static boolean isValidTargetTypeValue(int tag) {
253 if (targets == null)
254 targets = buildTargets();
255
256 if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue)) 252 if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue))
257 return true; 253 return true;
258 254
259 return (tag >= 0 && tag < targets.length); 255 return (tag >= 0 && tag < targets.length);
260 } 256 }
261 257
262 public static TargetType fromTargetTypeValue(int tag) { 258 public static TargetType fromTargetTypeValue(int tag) {
263 if (targets == null)
264 targets = buildTargets();
265
266 if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue)) 259 if (((byte)tag) == ((byte)UNKNOWN.targetTypeValue))
267 return UNKNOWN; 260 return UNKNOWN;
268 261
269 if (tag < 0 || tag >= targets.length) 262 if (tag < 0 || tag >= targets.length)
270 throw new IllegalArgumentException("Unknown TargetType: " + tag); 263 throw new IllegalArgumentException("Unknown TargetType: " + tag);

mercurial