1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
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
22package com.sun.org.apache.bcel.internal.classfile;
23
24import java.io.DataInput;
25import java.io.DataOutputStream;
26import java.io.IOException;
27
28/**
29 * base class for parameter annotations
30 *
31 * @version $Id: ParameterAnnotations
32 * @since 6.0
33 */
34public abstract class ParameterAnnotations extends Attribute {
35
36    /** Table of parameter annotations */
37    private ParameterAnnotationEntry[] parameter_annotation_table;
38
39    /**
40     * @param parameter_annotation_type the subclass type of the parameter annotation
41     * @param name_index Index pointing to the name <em>Code</em>
42     * @param length Content length in bytes
43     * @param input Input stream
44     * @param constant_pool Array of constants
45     */
46    ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length,
47            final DataInput input, final ConstantPool constant_pool) throws IOException {
48        this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[]) null,
49                constant_pool);
50        final int num_parameters = input.readUnsignedByte();
51        parameter_annotation_table = new ParameterAnnotationEntry[num_parameters];
52        for (int i = 0; i < num_parameters; i++) {
53            parameter_annotation_table[i] = new ParameterAnnotationEntry(input, constant_pool);
54        }
55    }
56
57
58    /**
59     * @param parameter_annotation_type the subclass type of the parameter annotation
60     * @param name_index Index pointing to the name <em>Code</em>
61     * @param length Content length in bytes
62     * @param parameter_annotation_table the actual parameter annotations
63     * @param constant_pool Array of constants
64     */
65    public ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length,
66            final ParameterAnnotationEntry[] parameter_annotation_table, final ConstantPool constant_pool) {
67        super(parameter_annotation_type, name_index, length, constant_pool);
68        this.parameter_annotation_table = parameter_annotation_table;
69    }
70
71
72    /**
73     * Called by objects that are traversing the nodes of the tree implicitely
74     * defined by the contents of a Java class. I.e., the hierarchy of methods,
75     * fields, attributes, etc. spawns a tree of objects.
76     *
77     * @param v Visitor object
78     */
79    @Override
80    public void accept( final Visitor v ) {
81        v.visitParameterAnnotation(this);
82    }
83
84
85    /**
86     * @param parameter_annotation_table the entries to set in this parameter annotation
87     */
88    public final void setParameterAnnotationTable(final ParameterAnnotationEntry[] parameter_annotation_table ) {
89        this.parameter_annotation_table = parameter_annotation_table;
90    }
91
92
93    /**
94     * @return the parameter annotation entry table
95     */
96    public final ParameterAnnotationEntry[] getParameterAnnotationTable() {
97        return parameter_annotation_table;
98    }
99
100
101    /**
102     * returns the array of parameter annotation entries in this parameter annotation
103     */
104    public ParameterAnnotationEntry[] getParameterAnnotationEntries() {
105        return parameter_annotation_table;
106    }
107
108    @Override
109    public void dump(final DataOutputStream dos) throws IOException
110    {
111        super.dump(dos);
112        dos.writeByte(parameter_annotation_table.length);
113
114        for (final ParameterAnnotationEntry element : parameter_annotation_table) {
115            element.dump(dos);
116        }
117
118    }
119
120    /**
121     * @return deep copy of this attribute
122     */
123    @Override
124    public Attribute copy( final ConstantPool constant_pool ) {
125        return (Attribute) clone();
126    }
127}
128