/Users/lyon/j4p/src/javassist/CtPrimitiveType.java
|
1 /*
2 * Javassist, a Java-bytecode translator toolkit.
3 * Copyright (C) 1999-2003 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() {
50 return true;
51 }
52
53 /**
54 * Returns the descriptor representing this type.
55 * For example, if the type is int, then the descriptor is I.
56 */
57 public char getDescriptor() {
58 return descriptor;
59 }
60
61 /**
62 * Returns the name of the wrapper class.
63 * For example, if the type is int, then the wrapper class is
64 * <code>java.lang.Integer</code>.
65 */
66 public String getWrapperName() {
67 return wrapperName;
68 }
69
70 /**
71 * Returns the name of the method for retrieving the value
72 * from the wrapper object.
73 * For example, if the type is int, then the method name is
74 * <code>intValue</code>.
75 */
76 public String getGetMethodName() {
77 return getMethodName;
78 }
79
80 /**
81 * Returns the descriptor of the method for retrieving the value
82 * from the wrapper object.
83 * For example, if the type is int, then the method descriptor is
84 * <code>()I</code>.
85 */
86 public String getGetMethodDescriptor() {
87 return mDescriptor;
88 }
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() {
96 return returnOp;
97 }
98
99 /**
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 }
118