001: /*
002: * Javassist, a Java-bytecode translator toolkit.
003: * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
004: *
005: * The contents of this file are subject to the Mozilla Public License Version
006: * 1.1 (the "License"); you may not use this file except in compliance with
007: * the License. Alternatively, the contents of this file may be used under
008: * the terms of the GNU Lesser General Public License Version 2.1 or later.
009: *
010: * Software distributed under the License is distributed on an "AS IS" basis,
011: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
012: * for the specific language governing rights and limitations under the
013: * License.
014: */
015:
016: package javassist;
017:
018: /**
019: * An instance of <code>CtPrimitiveType</code> represents a primitive type.
020: * It is obtained from <code>CtClass</code>.
021: */
022: public final class CtPrimitiveType extends CtClass {
023: private char descriptor;
024: private String wrapperName;
025: private String getMethodName;
026: private String mDescriptor;
027: private int returnOp;
028: private int arrayType;
029: private int dataSize;
030:
031: CtPrimitiveType(String name, char desc, String wrapper,
032: String methodName, String mDesc, int opcode, int atype,
033: int size) {
034: super (name);
035: descriptor = desc;
036: wrapperName = wrapper;
037: getMethodName = methodName;
038: mDescriptor = mDesc;
039: returnOp = opcode;
040: arrayType = atype;
041: dataSize = size;
042: }
043:
044: /**
045: * Returns <code>true</code> if this object represents a primitive
046: * Java type: boolean, byte, char, short, int, long, float, double,
047: * or void.
048: */
049: public boolean isPrimitive() {
050: return true;
051: }
052:
053: /**
054: * Returns the descriptor representing this type.
055: * For example, if the type is int, then the descriptor is I.
056: */
057: public char getDescriptor() {
058: return descriptor;
059: }
060:
061: /**
062: * Returns the name of the wrapper class.
063: * For example, if the type is int, then the wrapper class is
064: * <code>java.lang.Integer</code>.
065: */
066: public String getWrapperName() {
067: return wrapperName;
068: }
069:
070: /**
071: * Returns the name of the method for retrieving the value
072: * from the wrapper object.
073: * For example, if the type is int, then the method name is
074: * <code>intValue</code>.
075: */
076: public String getGetMethodName() {
077: return getMethodName;
078: }
079:
080: /**
081: * Returns the descriptor of the method for retrieving the value
082: * from the wrapper object.
083: * For example, if the type is int, then the method descriptor is
084: * <code>()I</code>.
085: */
086: public String getGetMethodDescriptor() {
087: return mDescriptor;
088: }
089:
090: /**
091: * Returns the opcode for returning a value of the type.
092: * For example, if the type is int, then the returned opcode is
093: * <code>javassit.bytecode.Opcode.IRETURN</code>.
094: */
095: public int getReturnOp() {
096: return returnOp;
097: }
098:
099: /**
100: * Returns the array-type code representing the type.
101: * It is used for the newarray instruction.
102: * For example, if the type is int, then this method returns
103: * <code>javassit.bytecode.Opcode.T_INT</code>.
104: */
105: public int getArrayType() {
106: return arrayType;
107: }
108:
109: /**
110: * Returns the data size of the primitive type.
111: * If the type is long or double, this method returns 2.
112: * Otherwise, it returns 1.
113: */
114: public int getDataSize() {
115: return dataSize;
116: }
117: }
|