    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 *  Unless required by applicable law or agreed to in writing, software
    012 *  distributed under the License is distributed on an "AS IS" BASIS,
    013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 *  See the License for the specific language governing permissions and
    015 *  limitations under the License.
    016 *
    017 */
    018package org.apache.bcel.classfile;
    019
    020import java.io.DataInput;
    021import java.io.DataOutputStream;
    022import java.io.IOException;
    023
    024/**
    025 * base class for parameter annotations
    026 *
    027 * @version $Id: ParameterAnnotations
    028 * @since 6.0
    029 */
    030public abstract class ParameterAnnotations extends Attribute {
    031
    032    /** Table of parameter annotations */
    033    private ParameterAnnotationEntry[] parameter_annotation_table;
    034
    035    /**
    036     * @param parameter_annotation_type the subclass type of the parameter annotation
    037     * @param name_index Index pointing to the name <em>Code</em>
    038     * @param length Content length in bytes
    039     * @param input Input stream
    040     * @param constant_pool Array of constants
    041     */
    042    ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length,
    043            final DataInput input, final ConstantPool constant_pool) throws IOException {
    044        this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[]) null,
    045                constant_pool);
    046        final int num_parameters = input.readUnsignedByte();
    047        parameter_annotation_table = new ParameterAnnotationEntry[num_parameters];
    048        for (int i = 0; i < num_parameters; i++) {
    049            parameter_annotation_table[i] = new ParameterAnnotationEntry(input, constant_pool);
    050        }
    051    }
    052
    053
    054    /**
    055     * @param parameter_annotation_type the subclass type of the parameter annotation
    056     * @param name_index Index pointing to the name <em>Code</em>
    057     * @param length Content length in bytes
    058     * @param parameter_annotation_table the actual parameter annotations
    059     * @param constant_pool Array of constants
    060     */
    061    public ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length,
    062            final ParameterAnnotationEntry[] parameter_annotation_table, final ConstantPool constant_pool) {
    063        super(parameter_annotation_type, name_index, length, constant_pool);
    064        this.parameter_annotation_table = parameter_annotation_table;
    065    }
    066
    067
    068    /**
    069     * Called by objects that are traversing the nodes of the tree implicitely
    070     * defined by the contents of a Java class. I.e., the hierarchy of methods,
    071     * fields, attributes, etc. spawns a tree of objects.
    072     *
    073     * @param v Visitor object
    074     */
    075    @Override
    076    public void accept( final Visitor v ) {
    077        v.visitParameterAnnotation(this);
    078    }
    079
    080
    081    /**
    082     * @param parameter_annotation_table the entries to set in this parameter annotation
    083     */
    084    public final void setParameterAnnotationTable(final ParameterAnnotationEntry[] parameter_annotation_table ) {
    085        this.parameter_annotation_table = parameter_annotation_table;
    086    }
    087
    088
    089    /**
    090     * @return the parameter annotation entry table
    091     */
    092    public final ParameterAnnotationEntry[] getParameterAnnotationTable() {
    093        return parameter_annotation_table;
    094    }
    095
    096
    097    /**
    098     * returns the array of parameter annotation entries in this parameter annotation
    099     */
    100    public ParameterAnnotationEntry[] getParameterAnnotationEntries() {
    101        return parameter_annotation_table;
    102    }
    103
    104    @Override
    105    public void dump(final DataOutputStream dos) throws IOException
    106    {
    107        super.dump(dos);
    108        dos.writeByte(parameter_annotation_table.length);
    109
    110        for (final ParameterAnnotationEntry element : parameter_annotation_table) {
    111            element.dump(dos);
    112        }
    113
    114    }
    115
    116    /**
    117     * @return deep copy of this attribute
    118     */
    119    @Override
    120    public Attribute copy( final ConstantPool constant_pool ) {
    121        return (Attribute) clone();
    122    }
    123}