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 } | 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 package com.sun.org.apache.bcel.internal.generic; 22 23 import com.sun.org.apache.bcel.internal.Const; 24 25 /** 26 * Denotes basic type such as int. 27 * 28 * @version $Id: BasicType.java 1747278 2016-06-07 17:28:43Z britter $ 29 */ 30 public final class BasicType extends Type { 31 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 Const 37 */ 38 BasicType(final byte type) { 39 super(type, Const.getShortTypeName(type)); 40 if ((type < Const.T_BOOLEAN) || (type > Const.T_VOID)) { 41 throw new ClassGenException("Invalid type: " + type); 42 } 43 } 44 45 // @since 6.0 no longer final 46 public static BasicType getType(final byte type) { 47 switch (type) { 48 case Const.T_VOID: 49 return VOID; 50 case Const.T_BOOLEAN: 51 return BOOLEAN; 52 case Const.T_BYTE: 53 return BYTE; 54 case Const.T_SHORT: 55 return SHORT; 56 case Const.T_CHAR: 57 return CHAR; 58 case Const.T_INT: 59 return INT; 60 case Const.T_LONG: 61 return LONG; 62 case Const.T_DOUBLE: 63 return DOUBLE; 64 case Const.T_FLOAT: 65 return FLOAT; 66 default: 67 throw new ClassGenException("Invalid type: " + type); 68 } 69 } 70 71 /** 72 * @return a hash code value for the object. 73 */ 74 @Override 75 public int hashCode() { 76 return super.getType(); 77 } 78 79 /** 80 * @return true if both type objects refer to the same type 81 */ 82 @Override 83 public boolean equals(final Object _type) { 84 return (_type instanceof BasicType) ? ((BasicType) _type).getType() == this.getType() : false; 85 } 86 } |