KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javassist > CtPrimitiveType


1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 1999-2005 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 JavaDoc wrapperName;
25     private String JavaDoc getMethodName;
26     private String JavaDoc mDescriptor;
27     private int returnOp;
28     private int arrayType;
29     private int dataSize;
30
31     CtPrimitiveType(String JavaDoc name, char desc, String JavaDoc wrapper,
32                     String JavaDoc methodName, String JavaDoc 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 descriptor representing this type.
53      * For example, if the type is int, then the descriptor is I.
54      */

55     public char getDescriptor() { return descriptor; }
56
57     /**
58      * Returns the name of the wrapper class.
59      * For example, if the type is int, then the wrapper class is
60      * <code>java.lang.Integer</code>.
61      */

62     public String JavaDoc getWrapperName() { return wrapperName; }
63
64     /**
65      * Returns the name of the method for retrieving the value
66      * from the wrapper object.
67      * For example, if the type is int, then the method name is
68      * <code>intValue</code>.
69      */

70     public String JavaDoc getGetMethodName() { return getMethodName; }
71
72     /**
73      * Returns the descriptor of the method for retrieving the value
74      * from the wrapper object.
75      * For example, if the type is int, then the method descriptor is
76      * <code>()I</code>.
77      */

78     public String JavaDoc getGetMethodDescriptor() { return mDescriptor; }
79
80     /**
81      * Returns the opcode for returning a value of the type.
82      * For example, if the type is int, then the returned opcode is
83      * <code>javassit.bytecode.Opcode.IRETURN</code>.
84      */

85     public int getReturnOp() { return returnOp; }
86
87     /**
88      * Returns the array-type code representing the type.
89      * It is used for the newarray instruction.
90      * For example, if the type is int, then this method returns
91      * <code>javassit.bytecode.Opcode.T_INT</code>.
92      */

93     public int getArrayType() { return arrayType; }
94
95     /**
96      * Returns the data size of the primitive type.
97      * If the type is long or double, this method returns 2.
98      * Otherwise, it returns 1.
99      */

100     public int getDataSize() { return dataSize; }
101 }
102
Popular Tags