1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.bcel.internal.generic;
  23 
  24 import com.sun.org.apache.bcel.internal.Constants;
  25 
  26 /**
  27  * Denotes basic type such as int.
  28  *
  29  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  30  */
  31 public final class BasicType extends Type {
  32   /**
  33    * Constructor for basic types such as int, long, `void'
  34    *
  35    * @param type one of T_INT, T_BOOLEAN, ..., T_VOID
  36    * @see com.sun.org.apache.bcel.internal.Constants
  37    */
  38   BasicType(byte type) {
  39     super(type, Constants.SHORT_TYPE_NAMES[type]);
  40 
  41     if((type < Constants.T_BOOLEAN) || (type > Constants.T_VOID))
  42       throw new ClassGenException("Invalid type: " + type);
  43   }
  44 
  45   public static final BasicType getType(byte type) {
  46     switch(type) {
  47     case Constants.T_VOID:    return VOID;
  48     case Constants.T_BOOLEAN: return BOOLEAN;
  49     case Constants.T_BYTE:    return BYTE;
  50     case Constants.T_SHORT:   return SHORT;
  51     case Constants.T_CHAR:    return CHAR;
  52     case Constants.T_INT:     return INT;
  53     case Constants.T_LONG:    return LONG;
  54     case Constants.T_DOUBLE:  return DOUBLE;
  55     case Constants.T_FLOAT:   return FLOAT;
  56 
  57     default:
  58       throw new ClassGenException("Invalid type: " + type);
  59     }
  60   }
  61 
  62   /** @return true if both type objects refer to the same type
  63    */
  64   @Override
  65   public boolean equals(Object type) {
  66     return (type instanceof BasicType)?
  67       ((BasicType)type).type == this.type : false;
  68   }
  69 
  70   @Override
  71   public int hashCode() {
  72       return type;
  73   }
  74 }