1 21 package proguard.shrink; 22 23 import proguard.classfile.*; 24 import proguard.classfile.visitor.*; 25 26 27 36 class ShortestUsageMark 37 { 38 private boolean certain; 39 private String reason; 40 private int depth; 41 private Clazz clazz; 42 private Method method; 43 44 45 49 public ShortestUsageMark(String reason) 50 { 51 this.certain = true; 52 this.reason = reason; 53 this.depth = 0; 54 } 55 56 57 63 public ShortestUsageMark(ShortestUsageMark previousUsageMark, 64 String reason, 65 int cost, 66 Clazz clazz) 67 { 68 this(previousUsageMark, reason, cost, clazz, null); 69 } 70 71 72 80 public ShortestUsageMark(ShortestUsageMark previousUsageMark, 81 String reason, 82 int cost, 83 Clazz clazz, 84 Method method) 85 { 86 this.certain = true; 87 this.reason = reason; 88 this.depth = previousUsageMark.depth + cost; 89 this.clazz = clazz; 90 this.method = method; 91 } 92 93 94 99 public ShortestUsageMark(ShortestUsageMark otherUsageMark, 100 boolean certain) 101 { 102 this.certain = certain; 103 this.reason = otherUsageMark.reason; 104 this.depth = otherUsageMark.depth; 105 this.clazz = otherUsageMark.clazz; 106 this.method = otherUsageMark.method; 107 } 108 109 110 113 public boolean isCertain() 114 { 115 return certain; 116 } 117 118 119 122 public String getReason() 123 { 124 return reason; 125 } 126 127 128 132 public boolean isShorter(ShortestUsageMark otherUsageMark) 133 { 134 return this.depth < otherUsageMark.depth; 135 } 136 137 138 141 public boolean isCausedBy(Clazz clazz) 142 { 143 return clazz.equals(this.clazz); 144 } 145 146 147 151 public void acceptClassVisitor(ClassVisitor classVisitor) 152 { 153 if (clazz != null && 154 method == null) 155 { 156 clazz.accept(classVisitor); 157 } 158 } 159 160 161 164 public void acceptMethodVisitor(MemberVisitor memberVisitor) 165 { 166 if (clazz != null && 167 method != null) 168 { 169 method.accept(clazz, memberVisitor); 170 } 171 } 172 173 174 176 public String toString() 177 { 178 return "certain=" + certain + ", depth="+depth+": " + 179 reason + 180 (clazz != null ? clazz.getName() : "(none)") + ": " + 181 (method != null ? method.getName(clazz) : "(none)"); 182 } 183 } 184 | Popular Tags |