169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/*
269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Javassist, a Java-bytecode translator toolkit.
369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Copyright (C) 1999-2007 Shigeru Chiba. All Rights Reserved.
469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal *
569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * The contents of this file are subject to the Mozilla Public License Version
669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1.1 (the "License"); you may not use this file except in compliance with
769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the License.  Alternatively, the contents of this file may be used under
869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the terms of the GNU Lesser General Public License Version 2.1 or later.
969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal *
1069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Software distributed under the License is distributed on an "AS IS" basis,
1169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * for the specific language governing rights and limitations under the
1369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * License.
1469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */
1569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpackage javassist;
1769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/**
1969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * An instance of <code>CtPrimitiveType</code> represents a primitive type.
2069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * It is obtained from <code>CtClass</code>.
2169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */
2269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpublic final class CtPrimitiveType extends CtClass {
2369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private char descriptor;
2469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private String wrapperName;
2569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private String getMethodName;
2669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private String mDescriptor;
2769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int returnOp;
2869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int arrayType;
2969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int dataSize;
3069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
3169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    CtPrimitiveType(String name, char desc, String wrapper,
3269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    String methodName, String mDesc, int opcode, int atype,
3369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                    int size) {
3469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        super(name);
3569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        descriptor = desc;
3669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        wrapperName = wrapper;
3769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        getMethodName = methodName;
3869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        mDescriptor = mDesc;
3969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        returnOp = opcode;
4069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        arrayType = atype;
4169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        dataSize = size;
4269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
4369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
4469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
4569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Returns <code>true</code> if this object represents a primitive
4669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Java type: boolean, byte, char, short, int, long, float, double,
4769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * or void.
4869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
4969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public boolean isPrimitive() { return true; }
5069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
5169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
5269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Returns the modifiers for this type.
5369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * For decoding, use <code>javassist.Modifier</code>.
5469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     *
5569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * @see Modifier
5669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
5769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int getModifiers() {
5869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return Modifier.PUBLIC | Modifier.FINAL;
5969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
6069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
6169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
6269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Returns the descriptor representing this type.
6369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * For example, if the type is int, then the descriptor is I.
6469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
6569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public char getDescriptor() { return descriptor; }
6669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
6769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
6869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Returns the name of the wrapper class.
6969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * For example, if the type is int, then the wrapper class is
7069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * <code>java.lang.Integer</code>.
7169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
7269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public String getWrapperName() { return wrapperName; }
7369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
7469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
7569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Returns the name of the method for retrieving the value
7669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * from the wrapper object.
7769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * For example, if the type is int, then the method name is
7869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * <code>intValue</code>.
7969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
8069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public String getGetMethodName() { return getMethodName; }
8169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
8269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
8369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Returns the descriptor of the method for retrieving the value
8469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * from the wrapper object.
8569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * For example, if the type is int, then the method descriptor is
8669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * <code>()I</code>.
8769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
8869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public String getGetMethodDescriptor() { return mDescriptor; }
8969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
9069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
9169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Returns the opcode for returning a value of the type.
9269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * For example, if the type is int, then the returned opcode is
9369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * <code>javassit.bytecode.Opcode.IRETURN</code>.
9469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
9569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int getReturnOp() { return returnOp; }
9669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
9769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
9869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Returns the array-type code representing the type.
9969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * It is used for the newarray instruction.
10069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * For example, if the type is int, then this method returns
10169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * <code>javassit.bytecode.Opcode.T_INT</code>.
10269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
10369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int getArrayType() { return arrayType; }
10469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
10569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    /**
10669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Returns the data size of the primitive type.
10769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * If the type is long or double, this method returns 2.
10869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     * Otherwise, it returns 1.
10969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal     */
11069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int getDataSize() { return dataSize; }
11169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal}
112