Home | History | Annotate | Download | only in visitor
      1 /*
      2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
      3  *             of Java bytecode.
      4  *
      5  * Copyright (c) 2002-2009 Eric Lafortune (eric (at) graphics.cornell.edu)
      6  *
      7  * This program 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 program 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 General Public License for
     15  * more details.
     16  *
     17  * You should have received a copy of the GNU General Public License along
     18  * with this program; if not, write to the Free Software Foundation, Inc.,
     19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
     20  */
     21 package proguard.classfile.visitor;
     22 
     23 import proguard.classfile.*;
     24 import proguard.classfile.attribute.*;
     25 import proguard.classfile.attribute.annotation.*;
     26 import proguard.classfile.attribute.annotation.visitor.*;
     27 import proguard.classfile.attribute.preverification.*;
     28 import proguard.classfile.attribute.preverification.visitor.*;
     29 import proguard.classfile.attribute.visitor.*;
     30 import proguard.classfile.constant.Constant;
     31 import proguard.classfile.constant.visitor.ConstantVisitor;
     32 import proguard.classfile.util.SimplifiedVisitor;
     33 
     34 /**
     35  * This <code>ClassVisitor</code> removes all visitor information of the
     36  * classes it visits.
     37  *
     38  * @author Eric Lafortune
     39  */
     40 public class ClassCleaner
     41 extends      SimplifiedVisitor
     42 implements   ClassVisitor,
     43              ConstantVisitor,
     44              MemberVisitor,
     45              AttributeVisitor,
     46              ExceptionInfoVisitor,
     47              InnerClassesInfoVisitor,
     48              StackMapFrameVisitor,
     49              VerificationTypeVisitor,
     50              AnnotationVisitor,
     51              ElementValueVisitor
     52 {
     53     // Implementations for ClassVisitor.
     54 
     55     public void visitProgramClass(ProgramClass programClass)
     56     {
     57         clean(programClass);
     58 
     59         programClass.constantPoolEntriesAccept(this);
     60 
     61         programClass.fieldsAccept(this);
     62         programClass.methodsAccept(this);
     63 
     64         programClass.attributesAccept(this);
     65     }
     66 
     67 
     68     public void visitLibraryClass(LibraryClass libraryClass)
     69     {
     70         clean(libraryClass);
     71 
     72         libraryClass.fieldsAccept(this);
     73         libraryClass.methodsAccept(this);
     74     }
     75 
     76 
     77     // Implementations for ConstantVisitor.
     78 
     79     public void visitAnyConstant(Clazz clazz, Constant constant)
     80     {
     81         clean(constant);
     82     }
     83 
     84 
     85     // Implementations for MemberVisitor.
     86 
     87     public void visitProgramMember(ProgramClass programClass, ProgramMember programMember)
     88     {
     89         clean(programMember);
     90 
     91         programMember.attributesAccept(programClass, this);
     92     }
     93 
     94 
     95     public void visitLibraryMember(LibraryClass libraryClass, LibraryMember libraryMember)
     96     {
     97         clean(libraryMember);
     98     }
     99 
    100 
    101     // Implementations for AttributeVisitor.
    102 
    103     public void visitAnyAttribute(Clazz clazz, Attribute attribute)
    104     {
    105         clean(attribute);
    106     }
    107 
    108 
    109     public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
    110     {
    111         clean(innerClassesAttribute);
    112 
    113         innerClassesAttribute.innerClassEntriesAccept(clazz, this);
    114     }
    115 
    116 
    117     public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute)
    118     {
    119         clean(exceptionsAttribute);
    120 
    121         exceptionsAttribute.exceptionEntriesAccept((ProgramClass)clazz, this);
    122     }
    123 
    124 
    125     public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    126     {
    127         clean(codeAttribute);
    128 
    129         codeAttribute.exceptionsAccept(clazz, method, this);
    130         codeAttribute.attributesAccept(clazz, method, this);
    131     }
    132 
    133 
    134     public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute)
    135     {
    136         clean(stackMapAttribute);
    137 
    138         stackMapAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this);
    139     }
    140 
    141 
    142     public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute)
    143     {
    144         clean(stackMapTableAttribute);
    145 
    146         stackMapTableAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this);
    147     }
    148 
    149 
    150     public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute)
    151     {
    152         clean(annotationsAttribute);
    153 
    154         annotationsAttribute.annotationsAccept(clazz, this);
    155     }
    156 
    157 
    158     public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute)
    159     {
    160         clean(parameterAnnotationsAttribute);
    161 
    162         parameterAnnotationsAttribute.annotationsAccept(clazz, method, this);
    163     }
    164 
    165 
    166     public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute)
    167     {
    168         clean(annotationDefaultAttribute);
    169 
    170         annotationDefaultAttribute.defaultValueAccept(clazz, this);
    171     }
    172 
    173 
    174     // Implementations for InnerClassesInfoVisitor.
    175 
    176     public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo)
    177     {
    178         clean(innerClassesInfo);
    179     }
    180 
    181 
    182     // Implementations for ExceptionInfoVisitor.
    183 
    184     public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo)
    185     {
    186         clean(exceptionInfo);
    187     }
    188 
    189 
    190     // Implementations for StackMapFrameVisitor.
    191 
    192     public void visitSameZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameZeroFrame sameZeroFrame)
    193     {
    194         clean(sameZeroFrame);
    195     }
    196 
    197 
    198     public void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame)
    199     {
    200         clean(sameOneFrame);
    201 
    202         sameOneFrame.stackItemAccept(clazz, method, codeAttribute, offset, this);
    203     }
    204 
    205 
    206     public void visitLessZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LessZeroFrame lessZeroFrame)
    207     {
    208         clean(lessZeroFrame);
    209     }
    210 
    211 
    212     public void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame)
    213     {
    214         clean(moreZeroFrame);
    215 
    216         moreZeroFrame.additionalVariablesAccept(clazz, method, codeAttribute, offset, this);
    217     }
    218 
    219 
    220     public void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame)
    221     {
    222         clean(fullFrame);
    223 
    224         fullFrame.variablesAccept(clazz, method, codeAttribute, offset, this);
    225         fullFrame.stackAccept(clazz, method, codeAttribute, offset, this);
    226     }
    227 
    228 
    229     // Implementations for VerificationTypeVisitor.
    230 
    231     public void visitAnyVerificationType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationType verificationType)
    232     {
    233         clean(verificationType);
    234     }
    235 
    236 
    237     // Implementations for AnnotationVisitor.
    238 
    239     public void visitAnnotation(Clazz clazz, Annotation annotation)
    240     {
    241         clean(annotation);
    242 
    243         annotation.elementValuesAccept(clazz, this);
    244     }
    245 
    246 
    247     // Implementations for ElementValueVisitor.
    248 
    249     public void visitAnyElementValue(Clazz clazz, Annotation annotation, ElementValue elementValue)
    250     {
    251         clean(elementValue);
    252     }
    253 
    254 
    255     public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
    256     {
    257         clean(annotationElementValue);
    258 
    259         annotationElementValue.annotationAccept(clazz, this);
    260     }
    261 
    262 
    263     public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue)
    264     {
    265         clean(arrayElementValue);
    266     }
    267 
    268 
    269     // Small utility methods.
    270 
    271     private void clean(VisitorAccepter visitorAccepter)
    272     {
    273         visitorAccepter.setVisitorInfo(null);
    274     }
    275 }
    276