• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  *             of Java bytecode.
4  *
5  * Copyright (c) 2002-2014 Eric Lafortune (eric@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.util.SimplifiedVisitor;
25 import proguard.classfile.visitor.*;
26 
27 /**
28  * This ClassVisitor inlines siblings in the program classes that it visits,
29  * whenever possible.
30  *
31  * @see ClassMerger
32  * @author Eric Lafortune
33  */
34 public class HorizontalClassMerger
35 extends      SimplifiedVisitor
36 implements   ClassVisitor
37 {
38     private final boolean      allowAccessModification;
39     private final boolean      mergeInterfacesAggressively;
40     private final ClassVisitor extraClassVisitor;
41 
42 
43     /**
44      * Creates a new HorizontalClassMerger.
45      * @param allowAccessModification     specifies whether the access modifiers
46      *                                    of classes can be changed in order to
47      *                                    merge them.
48      * @param mergeInterfacesAggressively specifies whether interfaces may
49      *                                    be merged aggressively.
50      */
HorizontalClassMerger(boolean allowAccessModification, boolean mergeInterfacesAggressively)51     public HorizontalClassMerger(boolean allowAccessModification,
52                                  boolean mergeInterfacesAggressively)
53     {
54         this(allowAccessModification, mergeInterfacesAggressively, null);
55     }
56 
57 
58     /**
59      * Creates a new VerticalClassMerger.
60      * @param allowAccessModification     specifies whether the access modifiers
61      *                                    of classes can be changed in order to
62      *                                    merge them.
63      * @param mergeInterfacesAggressively specifies whether interfaces may
64      *                                    be merged aggressively.
65      * @param extraClassVisitor           an optional extra visitor for all
66      *                                    merged classes.
67      */
HorizontalClassMerger(boolean allowAccessModification, boolean mergeInterfacesAggressively, ClassVisitor extraClassVisitor)68     public HorizontalClassMerger(boolean      allowAccessModification,
69                                  boolean      mergeInterfacesAggressively,
70                                  ClassVisitor extraClassVisitor)
71     {
72         this.allowAccessModification     = allowAccessModification;
73         this.mergeInterfacesAggressively = mergeInterfacesAggressively;
74         this.extraClassVisitor           = extraClassVisitor;
75     }
76 
77 
78     // Implementations for ClassVisitor.
79 
visitProgramClass(ProgramClass programClass)80     public void visitProgramClass(ProgramClass programClass)
81     {
82         programClass.superClassConstantAccept(new ReferencedClassVisitor(
83                                               new SubclassTraveler(
84                                               new ProgramClassFilter(
85                                               new ClassMerger(programClass,
86                                                               allowAccessModification,
87                                                               mergeInterfacesAggressively,
88                                                               extraClassVisitor)))));
89     }
90 }