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