1/* 2 * ProGuard -- shrinking, optimization, obfuscation, and preverification 3 * of Java bytecode. 4 * 5 * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu) 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free 9 * Software Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 * more details. 16 * 17 * You should have received a copy of the GNU General Public License along 18 * with this program; if not, write to the Free Software Foundation, Inc., 19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21package proguard.classfile.attribute.annotation; 22 23import proguard.classfile.*; 24import proguard.classfile.attribute.Attribute; 25import proguard.classfile.attribute.annotation.visitor.AnnotationVisitor; 26 27/** 28 * This Attribute represents a parameter annotations attribute. 29 * 30 * @author Eric Lafortune 31 */ 32public abstract class ParameterAnnotationsAttribute extends Attribute 33{ 34 public int u1parametersCount; 35 public int[] u2parameterAnnotationsCount; 36 public Annotation[][] parameterAnnotations; 37 38 39 /** 40 * Creates an uninitialized ParameterAnnotationsAttribute. 41 */ 42 protected ParameterAnnotationsAttribute() 43 { 44 } 45 46 47 /** 48 * Creates an initialized ParameterAnnotationsAttribute. 49 */ 50 protected ParameterAnnotationsAttribute(int u2attributeNameIndex, 51 int u1parametersCount, 52 int[] u2parameterAnnotationsCount, 53 Annotation[][] parameterAnnotations) 54 { 55 super(u2attributeNameIndex); 56 57 this.u1parametersCount = u1parametersCount; 58 this.u2parameterAnnotationsCount = u2parameterAnnotationsCount; 59 this.parameterAnnotations = parameterAnnotations; 60 } 61 62 63 /** 64 * Applies the given visitor to all annotations. 65 */ 66 public void annotationsAccept(Clazz clazz, Method method, AnnotationVisitor annotationVisitor) 67 { 68 // Loop over all parameters. 69 for (int parameterIndex = 0; parameterIndex < u1parametersCount; parameterIndex++) 70 { 71 int annotationsCount = u2parameterAnnotationsCount[parameterIndex]; 72 Annotation[] annotations = parameterAnnotations[parameterIndex]; 73 74 // Loop over all parameter annotations. 75 for (int index = 0; index < annotationsCount; index++) 76 { 77 // We don't need double dispatching here, since there is only one 78 // type of Annotation. 79 annotationVisitor.visitAnnotation(clazz, method, parameterIndex, annotations[index]); 80 } 81 } 82 } 83} 84