001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This library is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This library is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License
018: * along with this library; if not, write to the Free Software Foundation,
019: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.classfile.attribute.annotation;
022:
023: import proguard.classfile.*;
024: import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor;
025: import proguard.classfile.visitor.ClassVisitor;
026:
027: /**
028: * Representation of an annotation.
029: *
030: * @author Eric Lafortune
031: */
032: public class Annotation implements VisitorAccepter {
033: public int u2typeIndex;
034: public int u2elementValuesCount;
035: public ElementValue[] elementValues;
036:
037: /**
038: * An extra field pointing to the Clazz objects referenced in the
039: * type string. This field is typically filled out by the <code>{@link
040: * proguard.classfile.util.ClassReferenceInitializer
041: * ClassReferenceInitializer}</code>.
042: * References to primitive types are ignored.
043: */
044: public Clazz[] referencedClasses;
045:
046: /**
047: * An extra field in which visitors can store information.
048: */
049: public Object visitorInfo;
050:
051: /**
052: * Returns the type.
053: */
054: public String getType(Clazz clazz) {
055: return clazz.getString(u2typeIndex);
056: }
057:
058: /**
059: * Applies the given visitor to the first referenced class. This is the
060: * main annotation class.
061: */
062: public void referencedClassAccept(ClassVisitor classVisitor) {
063: if (referencedClasses != null) {
064: Clazz referencedClass = referencedClasses[0];
065: if (referencedClass != null) {
066: referencedClass.accept(classVisitor);
067: }
068: }
069: }
070:
071: /**
072: * Applies the given visitor to all referenced classes.
073: */
074: public void referencedClassesAccept(ClassVisitor classVisitor) {
075: if (referencedClasses != null) {
076: for (int index = 0; index < referencedClasses.length; index++) {
077: Clazz referencedClass = referencedClasses[index];
078: if (referencedClass != null) {
079: referencedClass.accept(classVisitor);
080: }
081: }
082: }
083: }
084:
085: /**
086: * Applies the given visitor to all element value pairs.
087: */
088: public void elementValuesAccept(Clazz clazz,
089: ElementValueVisitor elementValueVisitor) {
090: for (int index = 0; index < u2elementValuesCount; index++) {
091: elementValues[index].accept(clazz, this ,
092: elementValueVisitor);
093: }
094: }
095:
096: // Implementations for VisitorAccepter.
097:
098: public Object getVisitorInfo() {
099: return visitorInfo;
100: }
101:
102: public void setVisitorInfo(Object visitorInfo) {
103: this.visitorInfo = visitorInfo;
104: }
105: }
|