| 1 21 package proguard.shrink; 22 23 import proguard.classfile.*; 24 import proguard.classfile.constant.*; 25 import proguard.classfile.constant.visitor.ConstantVisitor; 26 import proguard.classfile.util.SimplifiedVisitor; 27 import proguard.classfile.visitor.ClassVisitor; 28 29 30 38 public class InterfaceUsageMarker 39 extends SimplifiedVisitor 40 implements ClassVisitor, 41 ConstantVisitor 42 { 43 private UsageMarker usageMarker; 44 45 private boolean used; 47 48 49 54 public InterfaceUsageMarker(UsageMarker usageMarker) 55 { 56 this.usageMarker = usageMarker; 57 } 58 59 60 62 public void visitProgramClass(ProgramClass programClass) 63 { 64 boolean classUsed = usageMarker.isUsed(programClass); 65 boolean classPossiblyUsed = usageMarker.isPossiblyUsed(programClass); 66 67 if (classUsed || classPossiblyUsed) 68 { 69 for (int index = 0; index < programClass.u2interfacesCount; index++) 71 { 72 markConstant(programClass, programClass.u2interfaces[index]); 75 classUsed |= used; 76 } 77 78 if (classPossiblyUsed) 80 { 81 if (classUsed) 83 { 84 usageMarker.markAsUsed(programClass); 87 88 markConstant(programClass, programClass.u2thisClass); 90 91 if (programClass.u2superClass != 0) 93 { 94 markConstant(programClass, programClass.u2superClass); 95 } 96 } 97 else 98 { 99 usageMarker.markAsUnused(programClass); 101 } 102 } 103 } 104 105 used = classUsed; 107 } 108 109 110 public void visitLibraryClass(LibraryClass libraryClass) 111 { 112 used = true; 114 } 115 116 117 119 public void visitClassConstant(Clazz clazz, ClassConstant classConstant) 120 { 121 boolean classUsed = usageMarker.isUsed(classConstant); 122 123 if (!classUsed) 124 { 125 classConstant.referencedClassAccept(this); 128 classUsed = used; 129 130 if (classUsed) 131 { 132 usageMarker.markAsUsed(classConstant); 135 136 markConstant(clazz, classConstant.u2nameIndex); 137 } 138 } 139 140 used = classUsed; 142 } 143 144 145 public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) 146 { 147 if (!usageMarker.isUsed(utf8Constant)) 148 { 149 usageMarker.markAsUsed(utf8Constant); 150 } 151 } 152 153 154 156 160 private void markConstant(Clazz clazz, int index) 161 { 162 clazz.constantPoolEntryAccept(index, this); 163 } 164 } 165 | Popular Tags |