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 22 package com.sun.org.apache.bcel.internal.classfile; 23 24 import java.io.DataInput; 25 import java.io.DataOutputStream; 26 import java.io.IOException; 27 import java.util.ArrayList; 28 import java.util.Collections; 29 import java.util.List; 30 31 /** 32 * represents one parameter annotation in the parameter annotation table 33 * 34 * @version $Id: ParameterAnnotationEntry 35 * @since 6.0 36 */ 37 public class ParameterAnnotationEntry implements Node { 38 39 private final AnnotationEntry[] annotation_table; 40 41 42 /** 43 * Construct object from input stream. 44 * 45 * @param input Input stream 46 * @throws IOException 47 */ 48 ParameterAnnotationEntry(final DataInput input, final ConstantPool constant_pool) throws IOException { 49 final int annotation_table_length = input.readUnsignedShort(); 50 annotation_table = new AnnotationEntry[annotation_table_length]; 51 for (int i = 0; i < annotation_table_length; i++) { 52 // TODO isRuntimeVisible 53 annotation_table[i] = AnnotationEntry.read(input, constant_pool, false); 54 } 55 } 56 57 58 /** 59 * Called by objects that are traversing the nodes of the tree implicitely 60 * defined by the contents of a Java class. I.e., the hierarchy of methods, 61 * fields, attributes, etc. spawns a tree of objects. 62 * 63 * @param v Visitor object 64 */ 65 @Override 66 public void accept( final Visitor v ) { 67 v.visitParameterAnnotationEntry(this); 68 } 69 70 /** 71 * returns the array of annotation entries in this annotation 72 */ 73 public AnnotationEntry[] getAnnotationEntries() { 74 return annotation_table; 75 } 76 77 public void dump(final DataOutputStream dos) throws IOException { 78 dos.writeShort(annotation_table.length); 79 for (final AnnotationEntry entry : annotation_table) { 80 entry.dump(dos); 81 } 82 } 83 84 public static ParameterAnnotationEntry[] createParameterAnnotationEntries(final Attribute[] attrs) { 85 // Find attributes that contain parameter annotation data 86 final List<ParameterAnnotationEntry> accumulatedAnnotations = new ArrayList<>(attrs.length); 87 for (final Attribute attribute : attrs) { 88 if (attribute instanceof ParameterAnnotations) { 89 final ParameterAnnotations runtimeAnnotations = (ParameterAnnotations)attribute; 90 Collections.addAll(accumulatedAnnotations, runtimeAnnotations.getParameterAnnotationEntries()); 91 } 92 } 93 return accumulatedAnnotations.toArray(new ParameterAnnotationEntry[accumulatedAnnotations.size()]); 94 } 95 }