01: /*
02: * ProGuard -- shrinking, optimization, obfuscation, and preverification
03: * of Java bytecode.
04: *
05: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
06: *
07: * This library is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the Free
09: * Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This library 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 Lesser General Public License
15: * for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public License
18: * along with this library; if not, write to the Free Software Foundation,
19: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: package proguard.classfile.attribute.annotation;
22:
23: import proguard.classfile.*;
24: import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor;
25: import proguard.classfile.visitor.MemberVisitor;
26:
27: /**
28: * This abstract class represents an element value that is attached to an
29: * annotation or an annotation default. Specific types of element values are
30: * subclassed from it.
31: *
32: * @author Eric Lafortune
33: */
34: public abstract class ElementValue implements VisitorAccepter {
35: /**
36: * An extra field for the optional element name. It is used in element value
37: * pairs of annotations. Otherwise, it is 0.
38: */
39: public int u2elementNameIndex;
40:
41: /**
42: * An extra field pointing to the referenced <code>Clazz</code>
43: * object, if applicable. This field is typically filled out by the
44: * <code>{@link proguard.classfile.util.ClassReferenceInitializer}</code>.
45: */
46: public Clazz referencedClass;
47:
48: /**
49: * An extra field pointing to the referenced <code>Method</code>
50: * object, if applicable. This field is typically filled out by the
51: * <code>{@link proguard.classfile.util.ClassReferenceInitializer}</code>.
52: */
53: public Method referencedMethod;
54:
55: /**
56: * An extra field in which visitors can store information.
57: */
58: public Object visitorInfo;
59:
60: /**
61: * Returns the element name.
62: */
63: public String getMethodName(Clazz clazz) {
64: return clazz.getString(u2elementNameIndex);
65: }
66:
67: // Abstract methods to be implemented by extensions.
68:
69: /**
70: * Returns the tag of this element value.
71: */
72: public abstract int getTag();
73:
74: /**
75: * Accepts the given visitor.
76: */
77: public abstract void accept(Clazz clazz, Annotation annotation,
78: ElementValueVisitor elementValueVisitor);
79:
80: /**
81: * Applies the given visitor to the referenced method.
82: */
83: public void referencedMethodAccept(MemberVisitor memberVisitor) {
84: if (referencedMethod != null) {
85: referencedMethod.accept(referencedClass, memberVisitor);
86: }
87: }
88:
89: // Implementations for VisitorAccepter.
90:
91: public Object getVisitorInfo() {
92: return visitorInfo;
93: }
94:
95: public void setVisitorInfo(Object visitorInfo) {
96: this.visitorInfo = visitorInfo;
97: }
98: }
|