Source code: com/techtrader/modules/tools/bytecode/lowlevel/NameAndTypeEntry.java
1 package com.techtrader.modules.tools.bytecode.lowlevel;
2
3
4 import java.io.DataInput;
5 import java.io.DataOutput;
6 import java.io.IOException;
7 import java.io.PrintWriter;
8
9 import com.techtrader.modules.tools.bytecode.visitor.BCVisitor;
10
11
12 /**
13 * Constant pool entry containing indexes referencing a name and a type.
14 *
15 * @author Abe White
16 */
17 public class NameAndTypeEntry
18 implements Entry, LowLevelConstants
19 {
20 private int _nameIndex = 0;
21 private int _descriptorIndex = 0;
22
23
24 public int getType ()
25 {
26 return ENTRY_NAME_AND_TYPE;
27 }
28
29
30 /**
31 * Get the index into the constant pool of a UTF8Entry containing
32 * the name of this entity.
33 */
34 public int getNameIndex ()
35 {
36 return _nameIndex;
37 }
38
39
40 /**
41 * Set the index into the constant pool of a UTF8Entry containing
42 * the name of this entity.
43 */
44 public void setNameIndex (int nameIndex)
45 {
46 _nameIndex = nameIndex;
47 }
48
49
50 /**
51 * Get the index into the constant pool of a UTF8Entry containing
52 * the descriptor for this entity.
53 */
54 public int getDescriptorIndex ()
55 {
56 return _descriptorIndex;
57 }
58
59
60 /**
61 * Set the index into the constant pool of a UTF8Entry containing
62 * the descriptor for this entity.
63 */
64 public void setDescriptorIndex (int descriptorIndex)
65 {
66 _descriptorIndex = descriptorIndex;
67 }
68
69
70 public void readData (DataInput in)
71 throws IOException
72 {
73 setNameIndex (in.readUnsignedShort ());
74 setDescriptorIndex (in.readUnsignedShort ());
75 }
76
77
78 public void writeData (DataOutput out)
79 throws IOException
80 {
81 out.writeShort (getNameIndex ());
82 out.writeShort (getDescriptorIndex ());
83 }
84
85
86 public String getKey ()
87 {
88 return getType () + "|" + getNameIndex ()
89 + "|" + getDescriptorIndex ();
90 }
91
92
93 public void acceptVisit (BCVisitor visit)
94 {
95 visit.enterNameAndTypeEntry (this);
96 visit.exitNameAndTypeEntry (this);
97 }
98 }