001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2003 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This program 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 program 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 General Public License for
015: * more details.
016: *
017: * You should have received a copy of the GNU General Public License along
018: * with this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.classfile.attribute.visitor;
022:
023: import proguard.classfile.*;
024: import proguard.classfile.attribute.*;
025: import proguard.classfile.util.SimplifiedVisitor;
026: import proguard.classfile.visitor.*;
027:
028: /**
029: * This ClassVisitor, MemberVisitor, and AttributeVisitor lets a given
030: * AttributeVisitor visit all Attribute objects of the program classes,
031: * program class members, or code attributes, respectively, that it visits.
032: *
033: * @author Eric Lafortune
034: */
035: public class AllAttributeVisitor extends SimplifiedVisitor implements
036: ClassVisitor, MemberVisitor, AttributeVisitor {
037: private final boolean deep;
038: private final AttributeVisitor attributeVisitor;
039:
040: /**
041: * Creates a new shallow AllAttributeVisitor.
042: * @param attributeVisitor the AttributeVisitor to which visits will be
043: * delegated.
044: */
045: public AllAttributeVisitor(AttributeVisitor attributeVisitor) {
046: this (false, attributeVisitor);
047: }
048:
049: /**
050: * Creates a new optionally deep AllAttributeVisitor.
051: * @param deep specifies whether the attributes contained
052: * further down the class structure should be
053: * visited too.
054: * @param attributeVisitor the AttributeVisitor to which visits will be
055: * delegated.
056: */
057: public AllAttributeVisitor(boolean deep,
058: AttributeVisitor attributeVisitor) {
059: this .deep = deep;
060: this .attributeVisitor = attributeVisitor;
061: }
062:
063: // Implementations for ClassVisitor.
064:
065: public void visitProgramClass(ProgramClass programClass) {
066: programClass.attributesAccept(attributeVisitor);
067:
068: // Visit the attributes further down the class structure, if required.
069: if (deep) {
070: programClass.fieldsAccept(this );
071: programClass.methodsAccept(this );
072: programClass.attributesAccept(this );
073: }
074: }
075:
076: public void visitLibraryClass(LibraryClass libraryClass) {
077: }
078:
079: // Implementations for MemberVisitor.
080:
081: public void visitProgramMember(ProgramClass programClass,
082: ProgramMember programMember) {
083: programMember.attributesAccept(programClass, attributeVisitor);
084:
085: // Visit the attributes further down the member structure, if required.
086: if (deep) {
087: programMember.attributesAccept(programClass, this );
088: }
089: }
090:
091: public void visitLibraryMember(LibraryClass programClass,
092: LibraryMember programMember) {
093: }
094:
095: // Implementations for AttributeVisitor.
096:
097: public void visitAnyAttribute(Clazz clazz, Attribute attribute) {
098: }
099:
100: public void visitCodeAttribute(Clazz clazz, Method method,
101: CodeAttribute codeAttribute) {
102: codeAttribute.attributesAccept(clazz, method, attributeVisitor);
103: }
104: }
|