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 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.visitor;
022:
023: import proguard.classfile.*;
024: import proguard.classfile.attribute.*;
025: import proguard.classfile.attribute.annotation.*;
026: import proguard.classfile.attribute.annotation.visitor.*;
027: import proguard.classfile.attribute.preverification.*;
028: import proguard.classfile.attribute.preverification.visitor.*;
029: import proguard.classfile.attribute.visitor.*;
030: import proguard.classfile.constant.Constant;
031: import proguard.classfile.constant.visitor.ConstantVisitor;
032: import proguard.classfile.util.SimplifiedVisitor;
033:
034: /**
035: * This <code>ClassVisitor</code> removes all visitor information of the
036: * classes it visits.
037: *
038: * @author Eric Lafortune
039: */
040: public class ClassCleaner extends SimplifiedVisitor implements
041: ClassVisitor, ConstantVisitor, MemberVisitor, AttributeVisitor,
042: ExceptionInfoVisitor, InnerClassesInfoVisitor,
043: StackMapFrameVisitor, VerificationTypeVisitor,
044: AnnotationVisitor, ElementValueVisitor {
045: // Implementations for ClassVisitor.
046:
047: public void visitProgramClass(ProgramClass programClass) {
048: clean(programClass);
049:
050: programClass.constantPoolEntriesAccept(this );
051:
052: programClass.fieldsAccept(this );
053: programClass.methodsAccept(this );
054:
055: programClass.attributesAccept(this );
056: }
057:
058: public void visitLibraryClass(LibraryClass libraryClass) {
059: clean(libraryClass);
060:
061: libraryClass.fieldsAccept(this );
062: libraryClass.methodsAccept(this );
063: }
064:
065: // Implementations for ConstantVisitor.
066:
067: public void visitAnyConstant(Clazz clazz, Constant constant) {
068: clean(constant);
069: }
070:
071: // Implementations for MemberVisitor.
072:
073: public void visitProgramMember(ProgramClass programClass,
074: ProgramMember programMember) {
075: clean(programMember);
076:
077: programMember.attributesAccept(programClass, this );
078: }
079:
080: public void visitLibraryMember(LibraryClass libraryClass,
081: LibraryMember libraryMember) {
082: clean(libraryMember);
083: }
084:
085: // Implementations for AttributeVisitor.
086:
087: public void visitAnyAttribute(Clazz clazz, Attribute attribute) {
088: clean(attribute);
089: }
090:
091: public void visitInnerClassesAttribute(Clazz clazz,
092: InnerClassesAttribute innerClassesAttribute) {
093: clean(innerClassesAttribute);
094:
095: innerClassesAttribute.innerClassEntriesAccept(clazz, this );
096: }
097:
098: public void visitExceptionsAttribute(Clazz clazz, Method method,
099: ExceptionsAttribute exceptionsAttribute) {
100: clean(exceptionsAttribute);
101:
102: exceptionsAttribute.exceptionEntriesAccept(
103: (ProgramClass) clazz, this );
104: }
105:
106: public void visitCodeAttribute(Clazz clazz, Method method,
107: CodeAttribute codeAttribute) {
108: clean(codeAttribute);
109:
110: codeAttribute.exceptionsAccept(clazz, method, this );
111: codeAttribute.attributesAccept(clazz, method, this );
112: }
113:
114: public void visitStackMapAttribute(Clazz clazz, Method method,
115: CodeAttribute codeAttribute,
116: StackMapAttribute stackMapAttribute) {
117: clean(stackMapAttribute);
118:
119: stackMapAttribute.stackMapFramesAccept(clazz, method,
120: codeAttribute, this );
121: }
122:
123: public void visitStackMapTableAttribute(Clazz clazz, Method method,
124: CodeAttribute codeAttribute,
125: StackMapTableAttribute stackMapTableAttribute) {
126: clean(stackMapTableAttribute);
127:
128: stackMapTableAttribute.stackMapFramesAccept(clazz, method,
129: codeAttribute, this );
130: }
131:
132: public void visitAnyAnnotationsAttribute(Clazz clazz,
133: AnnotationsAttribute annotationsAttribute) {
134: clean(annotationsAttribute);
135:
136: annotationsAttribute.annotationsAccept(clazz, this );
137: }
138:
139: public void visitAnyParameterAnnotationsAttribute(Clazz clazz,
140: Method method,
141: ParameterAnnotationsAttribute parameterAnnotationsAttribute) {
142: clean(parameterAnnotationsAttribute);
143:
144: parameterAnnotationsAttribute.annotationsAccept(clazz, method,
145: this );
146: }
147:
148: public void visitAnnotationDefaultAttribute(Clazz clazz,
149: Method method,
150: AnnotationDefaultAttribute annotationDefaultAttribute) {
151: clean(annotationDefaultAttribute);
152:
153: annotationDefaultAttribute.defaultValueAccept(clazz, this );
154: }
155:
156: // Implementations for InnerClassesInfoVisitor.
157:
158: public void visitInnerClassesInfo(Clazz clazz,
159: InnerClassesInfo innerClassesInfo) {
160: clean(innerClassesInfo);
161: }
162:
163: // Implementations for ExceptionInfoVisitor.
164:
165: public void visitExceptionInfo(Clazz clazz, Method method,
166: CodeAttribute codeAttribute, ExceptionInfo exceptionInfo) {
167: clean(exceptionInfo);
168: }
169:
170: // Implementations for StackMapFrameVisitor.
171:
172: public void visitSameZeroFrame(Clazz clazz, Method method,
173: CodeAttribute codeAttribute, int offset,
174: SameZeroFrame sameZeroFrame) {
175: clean(sameZeroFrame);
176: }
177:
178: public void visitSameOneFrame(Clazz clazz, Method method,
179: CodeAttribute codeAttribute, int offset,
180: SameOneFrame sameOneFrame) {
181: clean(sameOneFrame);
182:
183: sameOneFrame.stackItemAccept(clazz, method, codeAttribute,
184: offset, this );
185: }
186:
187: public void visitLessZeroFrame(Clazz clazz, Method method,
188: CodeAttribute codeAttribute, int offset,
189: LessZeroFrame lessZeroFrame) {
190: clean(lessZeroFrame);
191: }
192:
193: public void visitMoreZeroFrame(Clazz clazz, Method method,
194: CodeAttribute codeAttribute, int offset,
195: MoreZeroFrame moreZeroFrame) {
196: clean(moreZeroFrame);
197:
198: moreZeroFrame.additionalVariablesAccept(clazz, method,
199: codeAttribute, offset, this );
200: }
201:
202: public void visitFullFrame(Clazz clazz, Method method,
203: CodeAttribute codeAttribute, int offset, FullFrame fullFrame) {
204: clean(fullFrame);
205:
206: fullFrame.variablesAccept(clazz, method, codeAttribute, offset,
207: this );
208: fullFrame.stackAccept(clazz, method, codeAttribute, offset,
209: this );
210: }
211:
212: // Implementations for VerificationTypeVisitor.
213:
214: public void visitAnyVerificationType(Clazz clazz, Method method,
215: CodeAttribute codeAttribute, int offset,
216: VerificationType verificationType) {
217: clean(verificationType);
218: }
219:
220: // Implementations for AnnotationVisitor.
221:
222: public void visitAnnotation(Clazz clazz, Annotation annotation) {
223: clean(annotation);
224:
225: annotation.elementValuesAccept(clazz, this );
226: }
227:
228: // Implementations for ElementValueVisitor.
229:
230: public void visitAnyElementValue(Clazz clazz,
231: Annotation annotation, ElementValue elementValue) {
232: clean(elementValue);
233: }
234:
235: public void visitAnnotationElementValue(Clazz clazz,
236: Annotation annotation,
237: AnnotationElementValue annotationElementValue) {
238: clean(annotationElementValue);
239:
240: annotationElementValue.annotationAccept(clazz, this );
241: }
242:
243: public void visitArrayElementValue(Clazz clazz,
244: Annotation annotation, ArrayElementValue arrayElementValue) {
245: clean(arrayElementValue);
246: }
247:
248: // Small utility methods.
249:
250: private void clean(VisitorAccepter visitorAccepter) {
251: visitorAccepter.setVisitorInfo(null);
252: }
253: }
|