Source code: jreversepro/reflect/JConstantPoolEntry.java
1 /*
2 * @(#)JConstantPoolEntry.java
3 *
4 * JReversePro - Java Decompiler / Disassembler.
5 * Copyright (C) 2000 2001 Karthik Kumar.
6 * EMail: akkumar@users.sourceforge.net
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it , under the terms of the GNU General License as published
10 * by the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General License for more details.
17 * You should have received a copy of the GNU General License
18 * along with this program.If not, write to
19 * The Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23 package jreversepro.reflect;
24
25
26 /**
27 * JConstantPoolEntry is an Entry of the CONSTANT POOL data structure
28 * the class file.
29 * @author Karthik Kumar.
30 **/
31 public class JConstantPoolEntry {
32
33 /**
34 * ptr1 is the first pointer from this ConstantPoolEntry.
35 * An example could be TAG_CLASS. TagClass would have an entry
36 * pointing to a TAG_UTF8 that contains the class name.
37 * In that case the ptr1 of TAG_CLASS entry would give
38 * lead to TAG_UTF8.
39 **/
40 int ptr1;
41
42 /**
43 * ptr2 is the second pointer from this ConstantPoolEntry.
44 * An example could be TAG_FIELDTYPE. TagFieldType will have
45 * two entries - the first one to TAG_CLASS and the second one
46 * to TAG_NAMETYPE.In this case ptr2 would have the number of
47 * TAG_NAMETYPE index.
48 **/
49 int ptr2;
50
51 /**
52 * This is applicable to TAG_UTF8 TAG_INTEGER
53 * TAG_FLOAT TAG_DOUBLE TAG_LONG that contains the
54 * actual value of the tag.
55 **/
56 String value;
57
58 /**
59 * Tag Byte tells us about what tag it is.
60 * It can be one of the following.
61 * TAG_UTF8 corresponds to CONSTANT_UTF8
62 * TAG_INTEGER corresponds to CONSTANT_INTEGER
63 * TAG_FLOAT corresponds to CONSTANT_FLOAT
64 * TAG_LONG corresponds to CONSTANT_LONG
65 * TAG_DOUBLE corresponds to CONSTANT_DOUBLE
66 * TAG_CLASS corresponds to CONSTANT_CLASS
67 * TAG_STRING corresponds to CONSTANT_STRING
68 * TAG_FIELDREF corresponds to CONSTANT_FIELDREF
69 * TAG_METHODREF corresponds to CONSTANT_METHODREF
70 * TAG_INTERFACEREF corresponds to CONSTANT_INTERFACEREF
71 * TAG_NAMETYPE corresponds to CONSTANT_NAMETYPE
72 **/
73 int tagByte;
74
75 /**
76 * Constructor
77 * @param tagByte Tag Byte
78 * @param value Value
79 * @param ptr1 Pointer 1
80 * @param ptr2 Pointer 2
81 **/
82 public JConstantPoolEntry(int tagByte, String value,
83 int ptr1, int ptr2) {
84 this.tagByte = tagByte;
85 this.value = value;
86 this.ptr1 = ptr1;
87 this.ptr2 = ptr2;
88 }
89
90 /**
91 * @return Returns Pointer 1.
92 **/
93 public int getPtr1() {
94 return ptr1;
95 }
96
97 /**
98 * @return Returns Pointer 2.
99 **/
100 public int getPtr2() {
101 return ptr2;
102 }
103
104 /**
105 * @return Returns value of this ConstantPoolEntry.
106 **/
107 public String getValue() {
108 return value;
109 }
110
111 /**
112 * @return Returns Tag Byte
113 **/
114 public int getTagByte() {
115 return tagByte;
116 }
117
118 /**
119 * @return Returns stringified form of this class.
120 **/
121 public String toString() {
122 StringBuffer sb = new StringBuffer();
123 sb.append(JConstantPool.getTagName(tagByte));
124 sb.append(",");
125 if (ptr1 == -1) {
126 sb.append(" - ");
127 } else {
128 sb.append(ptr1);
129 }
130 sb.append(",");
131 if (ptr2 == -1) {
132 sb.append(" - ");
133 } else {
134 sb.append(ptr2);
135 }
136 sb.append(",");
137 if (tagByte == JConstantPool.TAG_UTF8) {
138 sb.append(value);
139 } else {
140 sb.append(" - ");
141 }
142 return sb.toString();
143 }
144 }