1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2009 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 an annotations attribute.
29 *
30 * @author Eric Lafortune
31 */
32public abstract class AnnotationsAttribute extends Attribute
33{
34    public int          u2annotationsCount;
35    public Annotation[] annotations;
36
37
38    /**
39     * Creates an uninitialized AnnotationsAttribute.
40     */
41    protected AnnotationsAttribute()
42    {
43    }
44
45
46    /**
47     * Creates an initialized AnnotationsAttribute.
48     */
49    protected AnnotationsAttribute(int          u2attributeNameIndex,
50                                   int          u2annotationsCount,
51                                   Annotation[] annotations)
52    {
53        super(u2attributeNameIndex);
54
55        this.u2annotationsCount = u2annotationsCount;
56        this.annotations        = annotations;
57    }
58
59
60    /**
61     * Applies the given visitor to all class annotations.
62     */
63    public void annotationsAccept(Clazz clazz, AnnotationVisitor annotationVisitor)
64    {
65        for (int index = 0; index < u2annotationsCount; index++)
66        {
67            // We don't need double dispatching here, since there is only one
68            // type of Annotation.
69            annotationVisitor.visitAnnotation(clazz, annotations[index]);
70        }
71    }
72
73
74    /**
75     * Applies the given visitor to all field annotations.
76     */
77    public void annotationsAccept(Clazz clazz, Field field, AnnotationVisitor annotationVisitor)
78    {
79        for (int index = 0; index < u2annotationsCount; index++)
80        {
81            // We don't need double dispatching here, since there is only one
82            // type of Annotation.
83            annotationVisitor.visitAnnotation(clazz, field, annotations[index]);
84        }
85    }
86
87
88    /**
89     * Applies the given visitor to all method annotations.
90     */
91    public void annotationsAccept(Clazz clazz, Method method, AnnotationVisitor annotationVisitor)
92    {
93        for (int index = 0; index < u2annotationsCount; index++)
94        {
95            // We don't need double dispatching here, since there is only one
96            // type of Annotation.
97            annotationVisitor.visitAnnotation(clazz, method, annotations[index]);
98        }
99    }
100}
101