KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > constants > ConstantNameAndTypeInfo


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.structures.constants;
9
10 import org.gjt.jclasslib.structures.CPInfo;
11 import org.gjt.jclasslib.structures.InvalidByteCodeException;
12
13 import java.io.*;
14
15 /**
16     Describes a <tt>CONSTANT_NameAndType_info</tt> constant pool data structure.
17
18     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
19     @version $Revision: 1.5 $ $Date: 2003/08/18 07:51:15 $
20 */

21 public class ConstantNameAndTypeInfo extends CPInfo {
22
23     /** Length of the constant pool data structure in bytes. */
24     public static final int SIZE = 4;
25     
26     private int nameIndex;
27     private int descriptorIndex;
28     
29     public byte getTag() {
30         return CONSTANT_NAME_AND_TYPE;
31     }
32
33     public String JavaDoc getTagVerbose() {
34         return CONSTANT_NAME_AND_TYPE_VERBOSE;
35     }
36     
37     public String JavaDoc getVerbose() throws InvalidByteCodeException {
38         return getName() + getDescriptor();
39     }
40
41     /**
42         Get the index of the constant pool entry containing the name of this entry.
43         @return the index
44      */

45     public int getNameIndex() {
46         return nameIndex;
47     }
48
49     /**
50         Set the index of the constant pool entry containing the name of this entry.
51         @param nameIndex the index
52      */

53     public void setNameIndex(int nameIndex) {
54         this.nameIndex = nameIndex;
55     }
56
57     /**
58         Get the index of the constant pool entry containing the descriptor of this entry.
59         @return the index
60      */

61     public int getDescriptorIndex() {
62         return descriptorIndex;
63     }
64
65     /**
66         Set the index of the constant pool entry containing the descriptor of this entry.
67         @param descriptorIndex the index
68      */

69     public void setDescriptorIndex(int descriptorIndex) {
70         this.descriptorIndex = descriptorIndex;
71     }
72
73     /**
74         Get the name.
75         @return the name.
76         @throws InvalidByteCodeException
77      */

78     public String JavaDoc getName() throws InvalidByteCodeException {
79         return classFile.getConstantPoolEntryName(nameIndex);
80     }
81
82     /**
83         Get the descriptor string.
84         @return the string.
85         @throws InvalidByteCodeException
86      */

87     public String JavaDoc getDescriptor() throws InvalidByteCodeException {
88         return classFile.getConstantPoolEntryName(descriptorIndex);
89     }
90
91     public void read(DataInput in)
92         throws InvalidByteCodeException, IOException {
93             
94         nameIndex = in.readUnsignedShort();
95         descriptorIndex = in.readUnsignedShort();
96         
97         if (debug) debug("read ");
98     }
99     
100     public void write(DataOutput out)
101         throws InvalidByteCodeException, IOException {
102
103         out.writeByte(CONSTANT_NAME_AND_TYPE);
104         out.writeShort(nameIndex);
105         out.writeShort(descriptorIndex);
106         if (debug) debug("wrote ");
107     }
108
109     protected void debug(String JavaDoc message) {
110         super.debug(message + getTagVerbose() + " with name_index " + nameIndex +
111               " and descriptor_index " + descriptorIndex);
112     }
113
114     public boolean equals(Object JavaDoc object) {
115         if (!(object instanceof ConstantNameAndTypeInfo)) {
116             return false;
117         }
118         ConstantNameAndTypeInfo constantNameAndTypeInfo = (ConstantNameAndTypeInfo)object;
119         return super.equals(object) &&
120                constantNameAndTypeInfo.nameIndex == nameIndex &&
121                constantNameAndTypeInfo.descriptorIndex == descriptorIndex;
122     }
123
124     public int hashCode() {
125         return super.hashCode() ^ nameIndex ^ descriptorIndex;
126     }
127     
128 }
129
Popular Tags