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