1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 import org.apache.bcel.Constants;
20
21 /***
22 * Denotes basic type such as int.
23 *
24 * @version $Id: BasicType.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public final class BasicType extends Type {
28
29 /***
30 * Constructor for basic types such as int, long, `void'
31 *
32 * @param type one of T_INT, T_BOOLEAN, ..., T_VOID
33 * @see org.apache.bcel.Constants
34 */
35 BasicType(byte type) {
36 super(type, Constants.SHORT_TYPE_NAMES[type]);
37 if ((type < Constants.T_BOOLEAN) || (type > Constants.T_VOID)) {
38 throw new ClassGenException("Invalid type: " + type);
39 }
40 }
41
42
43 public static final BasicType getType( byte type ) {
44 switch (type) {
45 case Constants.T_VOID:
46 return VOID;
47 case Constants.T_BOOLEAN:
48 return BOOLEAN;
49 case Constants.T_BYTE:
50 return BYTE;
51 case Constants.T_SHORT:
52 return SHORT;
53 case Constants.T_CHAR:
54 return CHAR;
55 case Constants.T_INT:
56 return INT;
57 case Constants.T_LONG:
58 return LONG;
59 case Constants.T_DOUBLE:
60 return DOUBLE;
61 case Constants.T_FLOAT:
62 return FLOAT;
63 default:
64 throw new ClassGenException("Invalid type: " + type);
65 }
66 }
67
68
69 /*** @return a hash code value for the object.
70 */
71 public int hashCode() {
72 return type;
73 }
74
75
76 /*** @return true if both type objects refer to the same type
77 */
78 public boolean equals( Object _type ) {
79 return (_type instanceof BasicType) ? ((BasicType) _type).type == this.type : false;
80 }
81 }