KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > classfile > attribute > annotation > ElementValue


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This library 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 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.visitor.MemberVisitor;
25 import proguard.classfile.attribute.annotation.visitor.ElementValueVisitor;
26
27 import java.io.*;
28
29 /**
30  * This abstract class represents an element value that is attached to an
31  * annotation or an annotation default. Specific types of element values are
32  * subclassed from it.
33  *
34  * @author Eric Lafortune
35  */

36 public abstract class ElementValue implements VisitorAccepter
37 {
38     /**
39      * An extra field for the optional element name. It is used in element value
40      * pairs of annotations. Otherwise, it is 0.
41      */

42     public int u2elementNameIndex;
43
44     /**
45      * An extra field pointing to the referenced <code>Clazz</code>
46      * object, if applicable. This field is typically filled out by the
47      * <code>{@link proguard.classfile.util.ClassReferenceInitializer}</code>.
48      */

49     public Clazz referencedClass;
50
51     /**
52      * An extra field pointing to the referenced <code>Method</code>
53      * object, if applicable. This field is typically filled out by the
54      * <code>{@link proguard.classfile.util.ClassReferenceInitializer}</code>.
55      */

56     public Method referencedMethod;
57
58     /**
59      * An extra field in which visitors can store information.
60      */

61     public Object JavaDoc visitorInfo;
62
63
64     /**
65      * Returns the element name.
66      */

67     public String JavaDoc getMethodName(Clazz clazz)
68     {
69         return clazz.getString(u2elementNameIndex);
70     }
71
72
73     // Abstract methods to be implemented by extensions.
74

75     /**
76      * Returns the tag of this element value.
77      */

78     public abstract int getTag();
79
80
81     /**
82      * Accepts the given visitor.
83      */

84     public abstract void accept(Clazz clazz, Annotation annotation, ElementValueVisitor elementValueVisitor);
85
86
87
88     /**
89      * Applies the given visitor to the referenced method.
90      */

91     public void referencedMethodAccept(MemberVisitor memberVisitor)
92     {
93         if (referencedMethod != null)
94         {
95             referencedMethod.accept(referencedClass, memberVisitor);
96         }
97     }
98
99
100     // Implementations for VisitorAccepter.
101

102     public Object JavaDoc getVisitorInfo()
103     {
104         return visitorInfo;
105     }
106
107     public void setVisitorInfo(Object JavaDoc visitorInfo)
108     {
109         this.visitorInfo = visitorInfo;
110     }
111 }
112
Popular Tags