1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.bcel.classfile;
20
21 import java.io.DataInput;
22 import java.io.IOException;
23
24 import org.apache.bcel.Const;
25
26 /**
27 * This class represents a constant pool reference to a field.
28 */
29 public final class ConstantFieldref extends ConstantCP {
30
31 /**
32 * Initialize from another object.
33 *
34 * @param c Source to copy.
35 */
36 public ConstantFieldref(final ConstantFieldref c) {
37 super(Const.CONSTANT_Fieldref, c.getClassIndex(), c.getNameAndTypeIndex());
38 }
39
40 /**
41 * Initialize instance from input data.
42 *
43 * @param input input stream
44 * @throws IOException if an I/O error occurs.
45 */
46 ConstantFieldref(final DataInput input) throws IOException {
47 super(Const.CONSTANT_Fieldref, input);
48 }
49
50 /**
51 * @param classIndex Reference to the class containing the Field
52 * @param nameAndTypeIndex and the Field signature
53 */
54 public ConstantFieldref(final int classIndex, final int nameAndTypeIndex) {
55 super(Const.CONSTANT_Fieldref, classIndex, nameAndTypeIndex);
56 }
57
58 /**
59 * Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.
60 * I.e., the hierarchy of Fields, fields, attributes, etc. spawns a tree of objects.
61 *
62 * @param v Visitor object
63 */
64 @Override
65 public void accept(final Visitor v) {
66 v.visitConstantFieldref(this);
67 }
68 }