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 * @version $Id: ParameterAnnotations 28 * @since 6.0 29 */ 30 public abstract class ParameterAnnotations extends Attribute { 31 32 /** Table of parameter annotations */ 33 private ParameterAnnotationEntry[] parameter_annotation_table; 34 35 /** 36 * @param parameter_annotation_type the subclass type of the parameter annotation 37 * @param name_index Index pointing to the name <em>Code</em> 38 * @param length Content length in bytes 39 * @param input Input stream 40 * @param constant_pool Array of constants 41 */ ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length, final DataInput input, final ConstantPool constant_pool)42 ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length, 43 final DataInput input, final ConstantPool constant_pool) throws IOException { 44 this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[]) null, 45 constant_pool); 46 final int num_parameters = input.readUnsignedByte(); 47 parameter_annotation_table = new ParameterAnnotationEntry[num_parameters]; 48 for (int i = 0; i < num_parameters; i++) { 49 parameter_annotation_table[i] = new ParameterAnnotationEntry(input, constant_pool); 50 } 51 } 52 53 54 /** 55 * @param parameter_annotation_type the subclass type of the parameter annotation 56 * @param name_index Index pointing to the name <em>Code</em> 57 * @param length Content length in bytes 58 * @param parameter_annotation_table the actual parameter annotations 59 * @param constant_pool Array of constants 60 */ ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length, final ParameterAnnotationEntry[] parameter_annotation_table, final ConstantPool constant_pool)61 public ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length, 62 final ParameterAnnotationEntry[] parameter_annotation_table, final ConstantPool constant_pool) { 63 super(parameter_annotation_type, name_index, length, constant_pool); 64 this.parameter_annotation_table = parameter_annotation_table; 65 } 66 67 68 /** 69 * Called by objects that are traversing the nodes of the tree implicitely 70 * defined by the contents of a Java class. I.e., the hierarchy of methods, 71 * fields, attributes, etc. spawns a tree of objects. 72 * 73 * @param v Visitor object 74 */ 75 @Override accept( final Visitor v )76 public void accept( final Visitor v ) { 77 v.visitParameterAnnotation(this); 78 } 79 80 81 /** 82 * @param parameter_annotation_table the entries to set in this parameter annotation 83 */ setParameterAnnotationTable(final ParameterAnnotationEntry[] parameter_annotation_table )84 public final void setParameterAnnotationTable(final ParameterAnnotationEntry[] parameter_annotation_table ) { 85 this.parameter_annotation_table = parameter_annotation_table; 86 } 87 88 89 /** 90 * @return the parameter annotation entry table 91 */ getParameterAnnotationTable()92 public final ParameterAnnotationEntry[] getParameterAnnotationTable() { 93 return parameter_annotation_table; 94 } 95 96 97 /** 98 * returns the array of parameter annotation entries in this parameter annotation 99 */ getParameterAnnotationEntries()100 public ParameterAnnotationEntry[] getParameterAnnotationEntries() { 101 return parameter_annotation_table; 102 } 103 104 @Override dump(final DataOutputStream dos)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 copy( final ConstantPool constant_pool )120 public Attribute copy( final ConstantPool constant_pool ) { 121 return (Attribute) clone(); 122 } 123 } 124