KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > classfile > attribute > Attribute


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;
22
23 import proguard.classfile.*;
24 import proguard.classfile.attribute.annotation.*;
25 import proguard.classfile.attribute.visitor.AttributeVisitor;
26
27 import java.io.*;
28
29 /**
30  * This abstract class represents an attribute that is attached to a class,
31  * a class member, or a code attribute. Specific types of attributes are
32  * subclassed from it.
33  *
34  * @author Eric Lafortune
35  */

36 public abstract class Attribute implements VisitorAccepter
37 {
38     public int u2attributeNameIndex;
39     //public int u4attributeLength;
40
//public byte info[];
41

42     /**
43      * An extra field in which visitors can store information.
44      */

45     public Object JavaDoc visitorInfo;
46
47
48     /**
49      * Returns the String name of the attribute.
50      */

51     public String JavaDoc getAttributeName(Clazz clazz)
52     {
53         return clazz.getString(u2attributeNameIndex);
54     }
55
56
57     // Methods to be implemented by extensions, if applicable.
58

59     /**
60      * Accepts the given visitor.
61      */

62     public void accept(Clazz clazz, AttributeVisitor attributeVisitor)
63     {
64         throw new UnsupportedOperationException JavaDoc("Method must be overridden in ["+this.getClass().getName()+"] if ever called");
65     }
66
67     /**
68      * Accepts the given visitor in the context of the given field.
69      */

70     public void accept(Clazz clazz, Field field, AttributeVisitor attributeVisitor)
71     {
72         // Delegate the default invocation if the field is null anyway.
73
if (field == null)
74         {
75             accept(clazz, attributeVisitor);
76         }
77         else
78         {
79             throw new UnsupportedOperationException JavaDoc("Method must be overridden in ["+this.getClass().getName()+"] if ever called");
80         }
81     }
82
83     /**
84      * Accepts the given visitor in the context of the given method.
85      */

86     public void accept(Clazz clazz, Method method, AttributeVisitor attributeVisitor)
87     {
88         // Delegate the default invocation if the method is null anyway.
89
if (method == null)
90         {
91             accept(clazz, (Field)null, attributeVisitor);
92         }
93         else
94         {
95             throw new UnsupportedOperationException JavaDoc("Method must be overridden in ["+this.getClass().getName()+"] if ever called");
96         }
97     }
98
99     /**
100      * Accepts the given visitor in the context of the given code attribute.
101      */

102     public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, AttributeVisitor attributeVisitor)
103     {
104         // Delegate the default invocation if the code attribute is null anyway.
105
if (codeAttribute == null)
106         {
107             accept(clazz, method, attributeVisitor);
108         }
109         else
110         {
111             throw new UnsupportedOperationException JavaDoc("Method must be overridden in ["+this.getClass().getName()+"] if ever called");
112         }
113     }
114
115
116     // Implementations for VisitorAccepter.
117

118     public Object JavaDoc getVisitorInfo()
119     {
120         return visitorInfo;
121     }
122
123     public void setVisitorInfo(Object JavaDoc visitorInfo)
124     {
125         this.visitorInfo = visitorInfo;
126     }
127 }
128
Popular Tags