1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.interpreter.classfile;
11
12 import java.io.DataInput;
13 import java.io.IOException;
14
15 /***
16 * A ConstantNameAndType <br>
17 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
18 * University of Technology </a>, the Netherlands. <br>
19 * See for project information <a
20 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
21 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
22 * License (GPL) </a>, no warranty <br>
23 *
24 * @version 1.0 Jan 9, 2004 <br>
25 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
26 * Jacobs </a>
27 */
28 public class ConstantNameAndType extends Constant
29 {
30 /*** the name index */
31 private int nameIndex;
32
33 /*** the descriptor index */
34 private int descriptorIndex;
35
36 /***
37 * constructs a new ConstantNameAndType
38 *
39 * @param constantPool the constantPool it is part of
40 * @param inputStream the inputstream to read from
41 * @throws IOException on failure
42 */
43 public ConstantNameAndType(final Constant[] constantPool,
44 final DataInput inputStream) throws IOException
45 {
46 this(constantPool, inputStream.readUnsignedShort(), inputStream
47 .readUnsignedShort());
48 }
49
50 /***
51 * constructs a new ConstantNameAndType
52 *
53 * @param constantPool the constantPool it is part of
54 * @param nameIndex the nameIndex
55 * @param descriptorIndex descriptorIndex
56 */
57 public ConstantNameAndType(final Constant[] constantPool,
58 final int nameIndex, final int descriptorIndex)
59 {
60 super(constantPool);
61 this.nameIndex = nameIndex;
62 this.descriptorIndex = descriptorIndex;
63 }
64
65 /***
66 * @see nl.tudelft.simulation.dsol.interpreter.classfile.Constant#getTag()
67 */
68 public int getTag()
69 {
70 return 12;
71 }
72
73 /***
74 * returns the nameindex
75 *
76 * @return nameIndex
77 */
78 public int getNameIndex()
79 {
80 return this.nameIndex;
81 }
82
83 /***
84 * returns the descriptorIndex
85 *
86 * @return descriptorIndex
87 */
88 public int getDescriptorIndex()
89 {
90 return this.descriptorIndex;
91 }
92
93 /***
94 * returns the name of this constant
95 *
96 * @return String the name
97 */
98 public String getName()
99 {
100 return ((ConstantUTF8) super.constantPool[this.nameIndex]).getValue();
101 }
102
103 /***
104 * returns the type of this constant
105 *
106 * @return String the type
107 */
108 public String getDescriptor()
109 {
110 return ((ConstantUTF8) super.constantPool[this.descriptorIndex])
111 .getValue();
112 }
113
114 /***
115 * @see java.lang.Object#toString()
116 */
117 public String toString()
118 {
119 return "ConstantNameAndType[name_index=" + this.nameIndex
120 + " descriptor_index=" + this.descriptorIndex + "]";
121 }
122 }