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 import nl.tudelft.simulation.language.reflection.FieldSignature;
16
17 /***
18 * A ConstantClass <br>
19 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
20 * University of Technology </a>, the Netherlands. <br>
21 * See for project information <a
22 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
23 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
24 * License (GPL) </a>, no warranty <br>
25 *
26 * @version 1.0 Jan 9, 2004 <br>
27 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
28 * Jacobs </a>
29 */
30 public class ConstantClass extends Constant
31 {
32 /*** gets the name index */
33 private int nameIndex;
34
35 /***
36 * constructs a new ConstantClass
37 *
38 * @param dataInput the inputstream to read from
39 * @param constantPool the constantPool it is part of
40 * @throws IOException on failure
41 */
42 public ConstantClass(final Constant[] constantPool,
43 final DataInput dataInput) throws IOException
44 {
45 this(constantPool, dataInput.readUnsignedShort());
46 }
47
48 /***
49 * constructs a new ClassConstant
50 *
51 * @param nameIndex the nameIndex
52 * @param constantPool the constantPool it is part of
53 */
54 public ConstantClass(final Constant[] constantPool, final int nameIndex)
55 {
56 super(constantPool);
57 this.nameIndex = nameIndex;
58 }
59
60 /***
61 * @see nl.tudelft.simulation.dsol.interpreter.classfile.Constant#getTag()
62 */
63 public int getTag()
64 {
65 return 7;
66 }
67
68 /***
69 * returns the name index
70 *
71 * @return nameIndex
72 */
73 public int getNameIndex()
74 {
75 return this.nameIndex;
76 }
77
78 /***
79 * returns the className of this constant
80 *
81 * @return String the className
82 */
83 public FieldSignature getValue()
84 {
85 return new FieldSignature(
86 ((ConstantUTF8) super.constantPool[this.nameIndex]).getValue());
87 }
88
89 /***
90 * @see java.lang.Object#toString()
91 */
92 public String toString()
93 {
94 return "ConstantClass[index=" + this.nameIndex + "]";
95 }
96 }