Home | History | Annotate | Download | only in javassist
      1 /*
      2  * Javassist, a Java-bytecode translator toolkit.
      3  * Copyright (C) 1999-2007 Shigeru Chiba. All Rights Reserved.
      4  *
      5  * The contents of this file are subject to the Mozilla Public License Version
      6  * 1.1 (the "License"); you may not use this file except in compliance with
      7  * the License.  Alternatively, the contents of this file may be used under
      8  * the terms of the GNU Lesser General Public License Version 2.1 or later.
      9  *
     10  * Software distributed under the License is distributed on an "AS IS" basis,
     11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
     12  * for the specific language governing rights and limitations under the
     13  * License.
     14  */
     15 
     16 package javassist;
     17 
     18 /**
     19  * An instance of <code>CtPrimitiveType</code> represents a primitive type.
     20  * It is obtained from <code>CtClass</code>.
     21  */
     22 public final class CtPrimitiveType extends CtClass {
     23     private char descriptor;
     24     private String wrapperName;
     25     private String getMethodName;
     26     private String mDescriptor;
     27     private int returnOp;
     28     private int arrayType;
     29     private int dataSize;
     30 
     31     CtPrimitiveType(String name, char desc, String wrapper,
     32                     String methodName, String mDesc, int opcode, int atype,
     33                     int size) {
     34         super(name);
     35         descriptor = desc;
     36         wrapperName = wrapper;
     37         getMethodName = methodName;
     38         mDescriptor = mDesc;
     39         returnOp = opcode;
     40         arrayType = atype;
     41         dataSize = size;
     42     }
     43 
     44     /**
     45      * Returns <code>true</code> if this object represents a primitive
     46      * Java type: boolean, byte, char, short, int, long, float, double,
     47      * or void.
     48      */
     49     public boolean isPrimitive() { return true; }
     50 
     51     /**
     52      * Returns the modifiers for this type.
     53      * For decoding, use <code>javassist.Modifier</code>.
     54      *
     55      * @see Modifier
     56      */
     57     public int getModifiers() {
     58         return Modifier.PUBLIC | Modifier.FINAL;
     59     }
     60 
     61     /**
     62      * Returns the descriptor representing this type.
     63      * For example, if the type is int, then the descriptor is I.
     64      */
     65     public char getDescriptor() { return descriptor; }
     66 
     67     /**
     68      * Returns the name of the wrapper class.
     69      * For example, if the type is int, then the wrapper class is
     70      * <code>java.lang.Integer</code>.
     71      */
     72     public String getWrapperName() { return wrapperName; }
     73 
     74     /**
     75      * Returns the name of the method for retrieving the value
     76      * from the wrapper object.
     77      * For example, if the type is int, then the method name is
     78      * <code>intValue</code>.
     79      */
     80     public String getGetMethodName() { return getMethodName; }
     81 
     82     /**
     83      * Returns the descriptor of the method for retrieving the value
     84      * from the wrapper object.
     85      * For example, if the type is int, then the method descriptor is
     86      * <code>()I</code>.
     87      */
     88     public String getGetMethodDescriptor() { return mDescriptor; }
     89 
     90     /**
     91      * Returns the opcode for returning a value of the type.
     92      * For example, if the type is int, then the returned opcode is
     93      * <code>javassit.bytecode.Opcode.IRETURN</code>.
     94      */
     95     public int getReturnOp() { return returnOp; }
     96 
     97     /**
     98      * Returns the array-type code representing the type.
     99      * It is used for the newarray instruction.
    100      * For example, if the type is int, then this method returns
    101      * <code>javassit.bytecode.Opcode.T_INT</code>.
    102      */
    103     public int getArrayType() { return arrayType; }
    104 
    105     /**
    106      * Returns the data size of the primitive type.
    107      * If the type is long or double, this method returns 2.
    108      * Otherwise, it returns 1.
    109      */
    110     public int getDataSize() { return dataSize; }
    111 }
    112