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 * @since 6.0 028 */ 029public abstract class ParameterAnnotations extends Attribute { 030 031 /** Table of parameter annotations */ 032 private ParameterAnnotationEntry[] parameter_annotation_table; 033 034 /** 035 * @param parameter_annotation_type the subclass type of the parameter annotation 036 * @param name_index Index pointing to the name <em>Code</em> 037 * @param length Content length in bytes 038 * @param input Input stream 039 * @param constant_pool Array of constants 040 */ 041 ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length, 042 final DataInput input, final ConstantPool constant_pool) throws IOException { 043 this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[]) null, 044 constant_pool); 045 final int num_parameters = input.readUnsignedByte(); 046 parameter_annotation_table = new ParameterAnnotationEntry[num_parameters]; 047 for (int i = 0; i < num_parameters; i++) { 048 parameter_annotation_table[i] = new ParameterAnnotationEntry(input, constant_pool); 049 } 050 } 051 052 053 /** 054 * @param parameter_annotation_type the subclass type of the parameter annotation 055 * @param name_index Index pointing to the name <em>Code</em> 056 * @param length Content length in bytes 057 * @param parameter_annotation_table the actual parameter annotations 058 * @param constant_pool Array of constants 059 */ 060 public ParameterAnnotations(final byte parameter_annotation_type, final int name_index, final int length, 061 final ParameterAnnotationEntry[] parameter_annotation_table, final ConstantPool constant_pool) { 062 super(parameter_annotation_type, name_index, length, constant_pool); 063 this.parameter_annotation_table = parameter_annotation_table; 064 } 065 066 067 /** 068 * Called by objects that are traversing the nodes of the tree implicitely 069 * defined by the contents of a Java class. I.e., the hierarchy of methods, 070 * fields, attributes, etc. spawns a tree of objects. 071 * 072 * @param v Visitor object 073 */ 074 @Override 075 public void accept( final Visitor v ) { 076 v.visitParameterAnnotation(this); 077 } 078 079 080 /** 081 * @param parameter_annotation_table the entries to set in this parameter annotation 082 */ 083 public final void setParameterAnnotationTable(final ParameterAnnotationEntry[] parameter_annotation_table ) { 084 this.parameter_annotation_table = parameter_annotation_table; 085 } 086 087 088 /** 089 * @return the parameter annotation entry table 090 */ 091 public final ParameterAnnotationEntry[] getParameterAnnotationTable() { 092 return parameter_annotation_table; 093 } 094 095 096 /** 097 * returns the array of parameter annotation entries in this parameter annotation 098 */ 099 public ParameterAnnotationEntry[] getParameterAnnotationEntries() { 100 return parameter_annotation_table; 101 } 102 103 @Override 104 public void dump(final DataOutputStream dos) throws IOException 105 { 106 super.dump(dos); 107 dos.writeByte(parameter_annotation_table.length); 108 109 for (final ParameterAnnotationEntry element : parameter_annotation_table) { 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}