    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one
    003 * or more contributor license agreements.  See the NOTICE file
    004 * distributed with this work for additional information
    005 * regarding copyright ownership.  The ASF licenses this file
    006 * to you under the Apache License, Version 2.0 (the
    007 * "License"); you may not use this file except in compliance
    008 * with the License.  You may obtain a copy of the License at
    009 *
    010 *   https://www.apache.org/licenses/LICENSE-2.0
    011 *
    012 * Unless required by applicable law or agreed to in writing,
    013 * software distributed under the License is distributed on an
    014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015 * KIND, either express or implied.  See the License for the
    016 * specific language governing permissions and limitations
    017 * under the License.
    018 */
    019package org.apache.bcel.classfile;
    020
    021import java.io.DataInput;
    022import java.io.IOException;
    023
    024import org.apache.bcel.Const;
    025
    026/**
    027 * This class represents a constant pool reference to a field.
    028 */
    029public final class ConstantFieldref extends ConstantCP {
    030
    031    /**
    032     * Initialize from another object.
    033     *
    034     * @param c Source to copy.
    035     */
    036    public ConstantFieldref(final ConstantFieldref c) {
    037        super(Const.CONSTANT_Fieldref, c.getClassIndex(), c.getNameAndTypeIndex());
    038    }
    039
    040    /**
    041     * Initialize instance from input data.
    042     *
    043     * @param input input stream
    044     * @throws IOException if an I/O error occurs.
    045     */
    046    ConstantFieldref(final DataInput input) throws IOException {
    047        super(Const.CONSTANT_Fieldref, input);
    048    }
    049
    050    /**
    051     * @param classIndex Reference to the class containing the Field
    052     * @param nameAndTypeIndex and the Field signature
    053     */
    054    public ConstantFieldref(final int classIndex, final int nameAndTypeIndex) {
    055        super(Const.CONSTANT_Fieldref, classIndex, nameAndTypeIndex);
    056    }
    057
    058    /**
    059     * Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.
    060     * I.e., the hierarchy of Fields, fields, attributes, etc. spawns a tree of objects.
    061     *
    062     * @param v Visitor object
    063     */
    064    @Override
    065    public void accept(final Visitor v) {
    066        v.visitConstantFieldref(this);
    067    }
    068}