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;
022:
023: import proguard.classfile.*;
024: import proguard.classfile.attribute.visitor.AttributeVisitor;
025:
026: /**
027: * This abstract class represents an attribute that is attached to a class,
028: * a class member, or a code attribute. Specific types of attributes are
029: * subclassed from it.
030: *
031: * @author Eric Lafortune
032: * @noinspection AbstractClassWithoutAbstractMethods
033: */
034: public abstract class Attribute implements VisitorAccepter {
035: public int u2attributeNameIndex;
036: //public int u4attributeLength;
037: //public byte info[];
038:
039: /**
040: * An extra field in which visitors can store information.
041: */
042: public Object visitorInfo;
043:
044: /**
045: * Returns the String name of the attribute.
046: */
047: public String getAttributeName(Clazz clazz) {
048: return clazz.getString(u2attributeNameIndex);
049: }
050:
051: // Methods to be implemented by extensions, if applicable.
052:
053: /**
054: * Accepts the given visitor.
055: */
056: public void accept(Clazz clazz, AttributeVisitor attributeVisitor) {
057: throw new UnsupportedOperationException(
058: "Method must be overridden in ["
059: + this .getClass().getName()
060: + "] if ever called");
061: }
062:
063: /**
064: * Accepts the given visitor in the context of the given field.
065: */
066: public void accept(Clazz clazz, Field field,
067: AttributeVisitor attributeVisitor) {
068: // Delegate the default invocation if the field is null anyway.
069: if (field == null) {
070: accept(clazz, attributeVisitor);
071: } else {
072: throw new UnsupportedOperationException(
073: "Method must be overridden in ["
074: + this .getClass().getName()
075: + "] if ever called");
076: }
077: }
078:
079: /**
080: * Accepts the given visitor in the context of the given method.
081: */
082: public void accept(Clazz clazz, Method method,
083: AttributeVisitor attributeVisitor) {
084: // Delegate the default invocation if the method is null anyway.
085: if (method == null) {
086: accept(clazz, (Field) null, attributeVisitor);
087: } else {
088: throw new UnsupportedOperationException(
089: "Method must be overridden in ["
090: + this .getClass().getName()
091: + "] if ever called");
092: }
093: }
094:
095: /**
096: * Accepts the given visitor in the context of the given code attribute.
097: */
098: public void accept(Clazz clazz, Method method,
099: CodeAttribute codeAttribute,
100: AttributeVisitor attributeVisitor) {
101: // Delegate the default invocation if the code attribute is null anyway.
102: if (codeAttribute == null) {
103: accept(clazz, method, attributeVisitor);
104: } else {
105: throw new UnsupportedOperationException(
106: "Method must be overridden in ["
107: + this .getClass().getName()
108: + "] if ever called");
109: }
110: }
111:
112: // Implementations for VisitorAccepter.
113:
114: public Object getVisitorInfo() {
115: return visitorInfo;
116: }
117:
118: public void setVisitorInfo(Object visitorInfo) {
119: this.visitorInfo = visitorInfo;
120: }
121: }
|