View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   *
17   */
18  package org.apache.bcel.generic;
19  
20  import org.apache.bcel.Const;
21  
22  /**
23   * Denotes basic type such as int.
24   *
25   */
26  public final class BasicType extends Type {
27  
28      /**
29       * Constructor for basic types such as int, long, `void'
30       *
31       * @param type one of T_INT, T_BOOLEAN, ..., T_VOID
32       * @see Const
33       */
34      BasicType(final byte type) {
35          super(type, Const.getShortTypeName(type));
36          if ((type < Const.T_BOOLEAN) || (type > Const.T_VOID)) {
37              throw new ClassGenException("Invalid type: " + type);
38          }
39      }
40  
41  
42      // @since 6.0 no longer final
43      public static BasicType getType( final byte type ) {
44          switch (type) {
45              case Const.T_VOID:
46                  return VOID;
47              case Const.T_BOOLEAN:
48                  return BOOLEAN;
49              case Const.T_BYTE:
50                  return BYTE;
51              case Const.T_SHORT:
52                  return SHORT;
53              case Const.T_CHAR:
54                  return CHAR;
55              case Const.T_INT:
56                  return INT;
57              case Const.T_LONG:
58                  return LONG;
59              case Const.T_DOUBLE:
60                  return DOUBLE;
61              case Const.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      @Override
72      public int hashCode() {
73          return super.getType();
74      }
75  
76  
77      /** @return true if both type objects refer to the same type
78       */
79      @Override
80      public boolean equals( final Object _type ) {
81          return (_type instanceof BasicType="../../../../org/apache/bcel/generic/BasicType.html#BasicType">BasicType) ? ((BasicType) _type).getType() == this.getType() : false;
82      }
83  }