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.info; 22 23 import proguard.classfile.Clazz; 24 25 /** 26 * This class stores some optimization information that can be attached to 27 * a class. 28 * 29 * @author Eric Lafortune 30 */ 31 public class ClassOptimizationInfo 32 { 33 private boolean isInstantiated = false; 34 private boolean isInstanceofed = false; 35 private boolean isDotClassed = false; 36 private boolean isCaught = false; 37 private boolean isSimpleEnum = false; 38 private boolean containsStaticInitializer = false; 39 private boolean containsPackageVisibleMembers = false; 40 private boolean invokesPackageVisibleMembers = false; 41 private Clazz targetClass; 42 43 setInstantiated()44 public void setInstantiated() 45 { 46 isInstantiated = true; 47 } 48 49 isInstantiated()50 public boolean isInstantiated() 51 { 52 return isInstantiated; 53 } 54 55 setInstanceofed()56 public void setInstanceofed() 57 { 58 isInstanceofed = true; 59 } 60 61 isInstanceofed()62 public boolean isInstanceofed() 63 { 64 return isInstanceofed; 65 } 66 67 setDotClassed()68 public void setDotClassed() 69 { 70 isDotClassed = true; 71 } 72 73 isDotClassed()74 public boolean isDotClassed() 75 { 76 return isDotClassed; 77 } 78 79 setCaught()80 public void setCaught() 81 { 82 isCaught = true; 83 } 84 85 isCaught()86 public boolean isCaught() 87 { 88 return isCaught; 89 } 90 91 setSimpleEnum(boolean simple)92 public void setSimpleEnum(boolean simple) 93 { 94 isSimpleEnum = simple; 95 } 96 97 isSimpleEnum()98 public boolean isSimpleEnum() 99 { 100 return isSimpleEnum; 101 } 102 103 setContainsStaticInitializer()104 public void setContainsStaticInitializer() 105 { 106 containsStaticInitializer = true; 107 } 108 109 containsStaticInitializer()110 public boolean containsStaticInitializer() 111 { 112 return containsStaticInitializer; 113 } 114 115 setContainsPackageVisibleMembers()116 public void setContainsPackageVisibleMembers() 117 { 118 containsPackageVisibleMembers = true; 119 } 120 121 containsPackageVisibleMembers()122 public boolean containsPackageVisibleMembers() 123 { 124 return containsPackageVisibleMembers; 125 } 126 127 setInvokesPackageVisibleMembers()128 public void setInvokesPackageVisibleMembers() 129 { 130 invokesPackageVisibleMembers = true; 131 } 132 133 invokesPackageVisibleMembers()134 public boolean invokesPackageVisibleMembers() 135 { 136 return invokesPackageVisibleMembers; 137 } 138 139 setTargetClass(Clazz targetClass)140 public void setTargetClass(Clazz targetClass) 141 { 142 this.targetClass = targetClass; 143 } 144 145 getTargetClass()146 public Clazz getTargetClass() 147 { 148 return targetClass; 149 } 150 151 merge(ClassOptimizationInfo other)152 public void merge(ClassOptimizationInfo other) 153 { 154 this.isInstantiated |= other.isInstantiated; 155 this.isInstanceofed |= other.isInstanceofed; 156 this.isDotClassed |= other.isDotClassed; 157 this.isCaught |= other.isCaught; 158 this.containsStaticInitializer |= other.containsStaticInitializer; 159 this.containsPackageVisibleMembers |= other.containsPackageVisibleMembers; 160 this.invokesPackageVisibleMembers |= other.invokesPackageVisibleMembers; 161 } 162 163 setClassOptimizationInfo(Clazz clazz)164 public static void setClassOptimizationInfo(Clazz clazz) 165 { 166 clazz.setVisitorInfo(new ClassOptimizationInfo()); 167 } 168 169 getClassOptimizationInfo(Clazz clazz)170 public static ClassOptimizationInfo getClassOptimizationInfo(Clazz clazz) 171 { 172 Object visitorInfo = clazz.getVisitorInfo(); 173 return visitorInfo instanceof ClassOptimizationInfo ? 174 (ClassOptimizationInfo)visitorInfo : 175 null; 176 } 177 } 178