View Javadoc

1   /*
2    * @(#) ConstantMethodref.java Jan 9, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.dsol.interpreter.classfile;
11  
12  import java.io.DataInput;
13  import java.io.IOException;
14  
15  /***
16   * A ConstantMethodref <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 ConstantMethodref extends Constant
29  {
30  	/*** the class index */
31  	private int classIndex;
32  
33  	/*** the name / type index */
34  	private int nameAndTypeIndex;
35  
36  	/***
37  	 * constructs a new ConstantMethodref
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 ConstantMethodref(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 ConstantMethodref
52  	 * 
53  	 * @param constantPool the constantPool it is part of
54  	 * @param classIndex the classIndex
55  	 * @param nameAndTypeIndex the NameAndTypeIndex
56  	 */
57  	public ConstantMethodref(final Constant[] constantPool,
58  			final int classIndex, final int nameAndTypeIndex)
59  	{
60  		super(constantPool);
61  		this.classIndex = classIndex;
62  		this.nameAndTypeIndex = nameAndTypeIndex;
63  	}
64  
65  	/***
66  	 * @see nl.tudelft.simulation.dsol.interpreter.classfile.Constant#getTag()
67  	 */
68  	public int getTag()
69  	{
70  		return 10;
71  	}
72  
73  	/***
74  	 * returns the classindex
75  	 * 
76  	 * @return classIndex
77  	 */
78  	public int getClassIndex()
79  	{
80  		return this.classIndex;
81  	}
82  
83  	/***
84  	 * returns the nameAndTypeIndex
85  	 * 
86  	 * @return nameAndTypeIndex
87  	 */
88  	public int getNameAndTypeIndex()
89  	{
90  		return this.nameAndTypeIndex;
91  	}
92  
93  	/***
94  	 * returns the constantClass of this constant
95  	 * 
96  	 * @return ConstantClass the constantClass
97  	 */
98  	public ConstantClass getConstantClass()
99  	{
100 		return ((ConstantClass) super.constantPool[this.classIndex]);
101 	}
102 
103 	/***
104 	 * returns the nameAndType constant
105 	 * 
106 	 * @return ConstantNameAndType
107 	 */
108 	public ConstantNameAndType getConstantNameAndType()
109 	{
110 		return ((ConstantNameAndType) super.constantPool[this.nameAndTypeIndex]);
111 	}
112 
113 	/***
114 	 * @see java.lang.Object#toString()
115 	 */
116 	public String toString()
117 	{
118 		return "ConstantMethodref[classIndex=" + this.classIndex
119 				+ " nameAndTypeIndex=" + this.nameAndTypeIndex + "]";
120 	}
121 }