001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 */ 018package org.apache.bcel.generic; 019 020import org.apache.bcel.Const; 021 022/** 023 * Denotes basic type such as int. 024 * 025 */ 026public final class BasicType extends Type { 027 028 /** 029 * Constructor for basic types such as int, long, `void' 030 * 031 * @param type one of T_INT, T_BOOLEAN, ..., T_VOID 032 * @see Const 033 */ 034 BasicType(final byte type) { 035 super(type, Const.getShortTypeName(type)); 036 if ((type < Const.T_BOOLEAN) || (type > Const.T_VOID)) { 037 throw new ClassGenException("Invalid type: " + type); 038 } 039 } 040 041 042 // @since 6.0 no longer final 043 public static BasicType getType( final byte type ) { 044 switch (type) { 045 case Const.T_VOID: 046 return VOID; 047 case Const.T_BOOLEAN: 048 return BOOLEAN; 049 case Const.T_BYTE: 050 return BYTE; 051 case Const.T_SHORT: 052 return SHORT; 053 case Const.T_CHAR: 054 return CHAR; 055 case Const.T_INT: 056 return INT; 057 case Const.T_LONG: 058 return LONG; 059 case Const.T_DOUBLE: 060 return DOUBLE; 061 case Const.T_FLOAT: 062 return FLOAT; 063 default: 064 throw new ClassGenException("Invalid type: " + type); 065 } 066 } 067 068 069 /** @return a hash code value for the object. 070 */ 071 @Override 072 public int hashCode() { 073 return super.getType(); 074 } 075 076 077 /** @return true if both type objects refer to the same type 078 */ 079 @Override 080 public boolean equals( final Object _type ) { 081 return (_type instanceof BasicType) ? ((BasicType) _type).getType() == this.getType() : false; 082 } 083}