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