15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 package com.sun.org.apache.bcel.internal.classfile;
23
24 import java.io.DataInput;
25 import java.io.DataOutputStream;
26 import java.io.IOException;
27
28 import com.sun.org.apache.bcel.internal.Const;
29
30 /**
31 * This class is derived from the abstract {@link Constant}
32 * and represents a reference to the name and signature
33 * of a field or method.
34 *
35 * @version $Id$
36 * @see Constant
37 */
38 public final class ConstantNameAndType extends Constant {
39
40 private int name_index; // Name of field/method
41 private int signature_index; // and its signature.
42
43
44 /**
45 * Initialize from another object.
46 */
47 public ConstantNameAndType(final ConstantNameAndType c) {
48 this(c.getNameIndex(), c.getSignatureIndex());
49 }
50
51
52 /**
53 * Initialize instance from file data.
54 *
55 * @param file Input stream
74 /**
75 * Called by objects that are traversing the nodes of the tree implicitely
76 * defined by the contents of a Java class. I.e., the hierarchy of methods,
77 * fields, attributes, etc. spawns a tree of objects.
78 *
79 * @param v Visitor object
80 */
81 @Override
82 public void accept( final Visitor v ) {
83 v.visitConstantNameAndType(this);
84 }
85
86
87 /**
88 * Dump name and signature index to file stream in binary format.
89 *
90 * @param file Output file stream
91 * @throws IOException
92 */
93 @Override
94 public final void dump( final DataOutputStream file ) throws IOException {
95 file.writeByte(super.getTag());
96 file.writeShort(name_index);
97 file.writeShort(signature_index);
98 }
99
100
101 /**
102 * @return Name index in constant pool of field/method name.
103 */
104 public final int getNameIndex() {
105 return name_index;
106 }
107
108
109 /** @return name
110 */
111 public final String getName( final ConstantPool cp ) {
112 return cp.constantToString(getNameIndex(), Const.CONSTANT_Utf8);
113 }
114
115
116 /**
117 * @return Index in constant pool of field/method signature.
118 */
119 public final int getSignatureIndex() {
120 return signature_index;
121 }
122
123
124 /** @return signature
125 */
126 public final String getSignature( final ConstantPool cp ) {
127 return cp.constantToString(getSignatureIndex(), Const.CONSTANT_Utf8);
128 }
129
130
131 /**
132 * @param name_index the name index of this constant
133 */
134 public final void setNameIndex( final int name_index ) {
135 this.name_index = name_index;
136 }
137
138
139 /**
140 * @param signature_index the signature index in the constant pool of this type
141 */
142 public final void setSignatureIndex( final int signature_index ) {
143 this.signature_index = signature_index;
144 }
145
146
147 /**
148 * @return String representation
149 */
150 @Override
151 public final String toString() {
152 return super.toString() + "(name_index = " + name_index + ", signature_index = "
153 + signature_index + ")";
154 }
155 }
|
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 package com.sun.org.apache.bcel.internal.classfile;
23
24 import java.io.DataInput;
25 import java.io.DataOutputStream;
26 import java.io.IOException;
27
28 import com.sun.org.apache.bcel.internal.Const;
29
30 /**
31 * This class is derived from the abstract {@link Constant}
32 * and represents a reference to the name and signature
33 * of a field or method.
34 *
35 * @see Constant
36 */
37 public final class ConstantNameAndType extends Constant {
38
39 private int name_index; // Name of field/method
40 private int signature_index; // and its signature.
41
42
43 /**
44 * Initialize from another object.
45 */
46 public ConstantNameAndType(final ConstantNameAndType c) {
47 this(c.getNameIndex(), c.getSignatureIndex());
48 }
49
50
51 /**
52 * Initialize instance from file data.
53 *
54 * @param file Input stream
73 /**
74 * Called by objects that are traversing the nodes of the tree implicitely
75 * defined by the contents of a Java class. I.e., the hierarchy of methods,
76 * fields, attributes, etc. spawns a tree of objects.
77 *
78 * @param v Visitor object
79 */
80 @Override
81 public void accept( final Visitor v ) {
82 v.visitConstantNameAndType(this);
83 }
84
85
86 /**
87 * Dump name and signature index to file stream in binary format.
88 *
89 * @param file Output file stream
90 * @throws IOException
91 */
92 @Override
93 public void dump( final DataOutputStream file ) throws IOException {
94 file.writeByte(super.getTag());
95 file.writeShort(name_index);
96 file.writeShort(signature_index);
97 }
98
99
100 /**
101 * @return Name index in constant pool of field/method name.
102 */
103 public int getNameIndex() {
104 return name_index;
105 }
106
107
108 /** @return name
109 */
110 public String getName( final ConstantPool cp ) {
111 return cp.constantToString(getNameIndex(), Const.CONSTANT_Utf8);
112 }
113
114
115 /**
116 * @return Index in constant pool of field/method signature.
117 */
118 public int getSignatureIndex() {
119 return signature_index;
120 }
121
122
123 /** @return signature
124 */
125 public String getSignature( final ConstantPool cp ) {
126 return cp.constantToString(getSignatureIndex(), Const.CONSTANT_Utf8);
127 }
128
129
130 /**
131 * @param name_index the name index of this constant
132 */
133 public void setNameIndex( final int name_index ) {
134 this.name_index = name_index;
135 }
136
137
138 /**
139 * @param signature_index the signature index in the constant pool of this type
140 */
141 public void setSignatureIndex( final int signature_index ) {
142 this.signature_index = signature_index;
143 }
144
145
146 /**
147 * @return String representation
148 */
149 @Override
150 public String toString() {
151 return super.toString() + "(name_index = " + name_index + ", signature_index = "
152 + signature_index + ")";
153 }
154 }
|