Home | History | Annotate | Download | only in peephole
      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.optimize.peephole;
     22 
     23 import proguard.classfile.ProgramClass;
     24 import proguard.classfile.constant.visitor.ConstantVisitor;
     25 import proguard.classfile.util.SimplifiedVisitor;
     26 import proguard.classfile.visitor.ClassVisitor;
     27 
     28 /**
     29  * This ClassVisitor inlines the direct subclasses into the program classes
     30  * that it visits, whenever possible.
     31  *
     32  * @see ClassMerger
     33  * @author Eric Lafortune
     34  */
     35 public class VerticalClassMerger
     36 extends      SimplifiedVisitor
     37 implements   ClassVisitor
     38 {
     39     private final boolean      allowAccessModification;
     40     private final boolean      mergeInterfacesAggressively;
     41     private final ClassVisitor extraClassVisitor;
     42 
     43 
     44     /**
     45      * Creates a new VerticalClassMerger.
     46      * @param allowAccessModification     specifies whether the access modifiers
     47      *                                    of classes can be changed in order to
     48      *                                    merge them.
     49      * @param mergeInterfacesAggressively specifies whether interfaces may
     50      *                                    be merged aggressively.
     51      */
     52     public VerticalClassMerger(boolean allowAccessModification,
     53                                boolean mergeInterfacesAggressively)
     54     {
     55         this(allowAccessModification, mergeInterfacesAggressively, null);
     56     }
     57 
     58 
     59     /**
     60      * Creates a new VerticalClassMerger.
     61      * @param allowAccessModification     specifies whether the access modifiers
     62      *                                    of classes can be changed in order to
     63      *                                    merge them.
     64      * @param mergeInterfacesAggressively specifies whether interfaces may
     65      *                                    be merged aggressively.
     66      * @param extraClassVisitor           an optional extra visitor for all
     67      *                                    merged classes.
     68      */
     69     public VerticalClassMerger(boolean      allowAccessModification,
     70                                boolean      mergeInterfacesAggressively,
     71                                ClassVisitor extraClassVisitor)
     72     {
     73         this.allowAccessModification     = allowAccessModification;
     74         this.mergeInterfacesAggressively = mergeInterfacesAggressively;
     75         this.extraClassVisitor           = extraClassVisitor;
     76     }
     77 
     78 
     79     // Implementations for ClassVisitor.
     80 
     81     public void visitProgramClass(ProgramClass programClass)
     82     {
     83         programClass.subclassesAccept(new ClassMerger(programClass,
     84                                                       allowAccessModification,
     85                                                       mergeInterfacesAggressively,
     86                                                       extraClassVisitor));
     87     }
     88 }