KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > bcel > generic > BasicType


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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 JavaDoc _type ) {
79         return (_type instanceof BasicType) ? ((BasicType) _type).type == this.type : false;
80     }
81 }
82
Popular Tags