1 21 package proguard; 22 23 import proguard.classfile.*; 24 import proguard.classfile.util.*; 25 import proguard.classfile.visitor.*; 26 27 import java.util.List ; 28 29 35 public class FullyQualifiedClassNameChecker 36 extends SimplifiedVisitor 37 implements ClassVisitor 38 { 39 private ClassPool programClassPool; 40 private ClassPool libraryClassPool; 41 private WarningPrinter notePrinter; 42 43 44 47 public FullyQualifiedClassNameChecker(ClassPool programClassPool, 48 ClassPool libraryClassPool, 49 WarningPrinter notePrinter) 50 { 51 this.programClassPool = programClassPool; 52 this.libraryClassPool = libraryClassPool; 53 this.notePrinter = notePrinter; 54 } 55 56 57 61 public void checkClassSpecifications(List classSpecifications) 62 { 63 if (classSpecifications != null) 64 { 65 for (int index = 0; index < classSpecifications.size(); index++) 66 { 67 ClassSpecification classSpecification = 68 (ClassSpecification)classSpecifications.get(index); 69 70 checkType(classSpecification.annotationType); 71 checkClassName(classSpecification.className); 72 checkType(classSpecification.extendsAnnotationType); 73 checkClassName(classSpecification.extendsClassName); 74 75 checkMemberSpecifications(classSpecification.fieldSpecifications, true); 76 checkMemberSpecifications(classSpecification.methodSpecifications, false); 77 } 78 } 79 } 80 81 82 86 private void checkMemberSpecifications(List memberSpecifications, boolean isField) 87 { 88 if (memberSpecifications != null) 89 { 90 for (int index = 0; index < memberSpecifications.size(); index++) 91 { 92 MemberSpecification memberSpecification = 93 (MemberSpecification)memberSpecifications.get(index); 94 95 checkType(memberSpecification.annotationType); 96 97 if (isField) 98 { 99 checkType(memberSpecification.descriptor); 100 } 101 else 102 { 103 checkDescriptor(memberSpecification.descriptor); 104 } 105 } 106 } 107 } 108 109 110 114 private void checkDescriptor(String descriptor) 115 { 116 if (descriptor != null) 117 { 118 InternalTypeEnumeration internalTypeEnumeration = 119 new InternalTypeEnumeration(descriptor); 120 121 checkType(internalTypeEnumeration.returnType()); 122 123 while (internalTypeEnumeration.hasMoreTypes()) 124 { 125 checkType(internalTypeEnumeration.nextType()); 126 } 127 } 128 } 129 130 131 135 private void checkType(String type) 136 { 137 if (type != null) 138 { 139 checkClassName(ClassUtil.internalClassNameFromType(type)); 140 } 141 } 142 143 144 148 private void checkClassName(String className) 149 { 150 if (className != null && 151 !containsWildCards(className) && 152 programClassPool.getClass(className) == null && 153 libraryClassPool.getClass(className) == null) 154 { 155 notePrinter.print("Note: the configuration refers to the unknown class '" + 156 ClassUtil.externalClassName(className) + "'"); 157 158 String fullyQualifiedClassName = 159 "**" + ClassConstants.INTERNAL_PACKAGE_SEPARATOR + 160 className.substring(className.lastIndexOf(ClassConstants.INTERNAL_PACKAGE_SEPARATOR)+1); 161 162 ClassNameFilter classNameFilter = 163 new ClassNameFilter(fullyQualifiedClassName, this); 164 165 programClassPool.classesAccept(classNameFilter); 166 libraryClassPool.classesAccept(classNameFilter); 167 } 168 } 169 170 171 private static boolean containsWildCards(String string) 172 { 173 return string != null && 174 (string.indexOf('*') >= 0 || 175 string.indexOf('?') >= 0 || 176 string.indexOf(',') >= 0); 177 } 178 179 180 182 public void visitAnyClass(Clazz clazz) 183 { 184 System.err.println(" Maybe you meant the fully qualified name '" + 185 ClassUtil.externalClassName(clazz.getName()) + "'?"); 186 } 187 } 188
| Popular Tags
|