4545public class AsmAnalyzer {
4646
4747 // Note: a bunch of stuff has package-level access for unit tests. Consider it private.
48-
48+
4949 /** Output logger. */
5050 private final Log mLog ;
5151 /** The input source JAR to parse. */
@@ -59,11 +59,11 @@ public class AsmAnalyzer {
5959
6060 /**
6161 * Creates a new analyzer.
62- *
62+ *
6363 * @param log The log output.
6464 * @param osJarPath The input source JARs to parse.
6565 * @param gen The generator to fill with the class list and dependency list.
66- * @param deriveFrom Keep all classes that derive from these one (these included).
66+ * @param deriveFrom Keep all classes that derive from these one (these included).
6767 * @param includeGlobs Glob patterns of classes to keep, e.g. "com.foo.*"
6868 * ("*" does not matches dots whilst "**" does, "." and "$" are interpreted as-is)
6969 */
@@ -81,16 +81,13 @@ public AsmAnalyzer(Log log, List<String> osJarPath, AsmGenerator gen,
8181 * Fills the generator with classes & dependencies found.
8282 */
8383 public void analyze () throws IOException , LogAbortException {
84-
85- AsmAnalyzer visitor = this ;
86-
8784 Map <String , ClassReader > zipClasses = parseZip (mOsSourceJar );
8885 mLog .info ("Found %d classes in input JAR%s." , zipClasses .size (),
8986 mOsSourceJar .size () > 1 ? "s" : "" );
90-
87+
9188 Map <String , ClassReader > found = findIncludes (zipClasses );
9289 Map <String , ClassReader > deps = findDeps (zipClasses , found );
93-
90+
9491 if (mGen != null ) {
9592 mGen .setKeep (found );
9693 mGen .setDeps (deps );
@@ -117,10 +114,10 @@ Map<String,ClassReader> parseZip(List<String> jarPathList) throws IOException {
117114 }
118115 }
119116 }
120-
117+
121118 return classes ;
122119 }
123-
120+
124121 /**
125122 * Utility that returns the fully qualified binary class name for a ClassReader.
126123 * E.g. it returns something like android.view.View.
@@ -132,7 +129,7 @@ static String classReaderToClassName(ClassReader classReader) {
132129 return classReader .getClassName ().replace ('/' , '.' );
133130 }
134131 }
135-
132+
136133 /**
137134 * Utility that returns the fully qualified binary class name from a path-like FQCN.
138135 * E.g. it returns android.view.View from android/view/View.
@@ -144,7 +141,7 @@ static String internalToBinaryClassName(String className) {
144141 return className .replace ('/' , '.' );
145142 }
146143 }
147-
144+
148145 /**
149146 * Process the "includes" arrays.
150147 * <p/>
@@ -162,11 +159,11 @@ Map<String, ClassReader> findIncludes(Map<String, ClassReader> zipClasses)
162159 for (String s : mDeriveFrom ) {
163160 findClassesDerivingFrom (s , zipClasses , found );
164161 }
165-
162+
166163 return found ;
167164 }
168165
169-
166+
170167 /**
171168 * Uses ASM to find the class reader for the given FQCN class name.
172169 * If found, insert it in the in_out_found map.
@@ -215,7 +212,7 @@ void findGlobs(String globPattern, Map<String, ClassReader> zipClasses,
215212 globPattern += "$" ;
216213
217214 Pattern regexp = Pattern .compile (globPattern );
218-
215+
219216 for (Entry <String , ClassReader > entry : zipClasses .entrySet ()) {
220217 String class_name = entry .getKey ();
221218 if (regexp .matcher (class_name ).matches ()) {
@@ -229,10 +226,9 @@ void findGlobs(String globPattern, Map<String, ClassReader> zipClasses,
229226 * determine if they are derived from the given FQCN super class name.
230227 * Inserts the super class and all the class objects found in the map.
231228 */
232- void findClassesDerivingFrom (String super_name , Map <String , ClassReader > zipClasses ,
233- Map <String , ClassReader > inOutFound ) throws LogAbortException {
234- ClassReader super_clazz = findClass (super_name , zipClasses , inOutFound );
235-
229+ void findClassesDerivingFrom (String super_name ,
230+ Map <String , ClassReader > zipClasses ,
231+ Map <String , ClassReader > inOutFound ) {
236232 for (Entry <String , ClassReader > entry : zipClasses .entrySet ()) {
237233 String className = entry .getKey ();
238234 if (super_name .equals (className )) {
@@ -284,7 +280,7 @@ Map<String, ClassReader> findDeps(Map<String, ClassReader> zipClasses,
284280 for (ClassReader cr : inOutKeepClasses .values ()) {
285281 cr .accept (visitor , 0 /* flags */ );
286282 }
287-
283+
288284 while (new_deps .size () > 0 || new_keep .size () > 0 ) {
289285 deps .putAll (new_deps );
290286 inOutKeepClasses .putAll (new_keep );
@@ -308,12 +304,12 @@ Map<String, ClassReader> findDeps(Map<String, ClassReader> zipClasses,
308304 return deps ;
309305 }
310306
311-
307+
312308
313309 // ----------------------------------
314-
310+
315311 /**
316- * Visitor to collect all the type dependencies from a class.
312+ * Visitor to collect all the type dependencies from a class.
317313 */
318314 public class DependencyVisitor
319315 implements ClassVisitor , FieldVisitor , MethodVisitor , SignatureVisitor , AnnotationVisitor {
@@ -333,7 +329,7 @@ public class DependencyVisitor
333329 * Creates a new visitor that will find all the dependencies for the visited class.
334330 * Types which are already in the zipClasses, keepClasses or inDeps are not marked.
335331 * New dependencies are marked in outDeps.
336- *
332+ *
337333 * @param zipClasses All classes found in the source JAR.
338334 * @param inKeep Classes from which dependencies are to be found.
339335 * @param inDeps Dependencies already known.
@@ -350,7 +346,7 @@ public DependencyVisitor(Map<String, ClassReader> zipClasses,
350346 mInDeps = inDeps ;
351347 mOutDeps = outDeps ;
352348 }
353-
349+
354350 /**
355351 * Considers the given class name as a dependency.
356352 * If it does, add to the mOutDeps map.
@@ -361,7 +357,7 @@ public void considerName(String className) {
361357 }
362358
363359 className = internalToBinaryClassName (className );
364-
360+
365361 // exclude classes that have already been found
366362 if (mInKeep .containsKey (className ) ||
367363 mOutKeep .containsKey (className ) ||
@@ -384,7 +380,7 @@ public void considerName(String className) {
384380 } catch (ClassNotFoundException e ) {
385381 // ignore
386382 }
387-
383+
388384 // accept this class:
389385 // - android classes are added to dependencies
390386 // - non-android classes are added to the list of classes to keep as-is (they don't need
@@ -395,7 +391,7 @@ public void considerName(String className) {
395391 mOutKeep .put (className , cr );
396392 }
397393 }
398-
394+
399395 /**
400396 * Considers this array of names using considerName().
401397 */
@@ -450,7 +446,7 @@ public void considerDesc(String desc) {
450446 }
451447 }
452448
453-
449+
454450 // ---------------------------------------------------
455451 // --- ClassVisitor, FieldVisitor
456452 // ---------------------------------------------------
@@ -460,15 +456,15 @@ public void visit(int version, int access, String name,
460456 String signature , String superName , String [] interfaces ) {
461457 // signature is the signature of this class. May be null if the class is not a generic
462458 // one, and does not extend or implement generic classes or interfaces.
463-
459+
464460 if (signature != null ) {
465461 considerSignature (signature );
466462 }
467463
468464 // superName is the internal of name of the super class (see getInternalName).
469465 // For interfaces, the super class is Object. May be null but only for the Object class.
470466 considerName (superName );
471-
467+
472468 // interfaces is the internal names of the class's interfaces (see getInternalName).
473469 // May be null.
474470 considerNames (interfaces );
@@ -513,7 +509,7 @@ public MethodVisitor visitMethod(int access, String name, String desc,
513509 // signature is the method's signature. May be null if the method parameters, return
514510 // type and exceptions do not use generic types.
515511 considerSignature (signature );
516-
512+
517513 return this ; // returns this to visit the method
518514 }
519515
@@ -525,7 +521,7 @@ public void visitSource(String source, String debug) {
525521 // pass
526522 }
527523
528-
524+
529525 // ---------------------------------------------------
530526 // --- MethodVisitor
531527 // ---------------------------------------------------
@@ -601,7 +597,7 @@ public void visitMaxs(int maxStack, int maxLocals) {
601597
602598 // instruction that invokes a method
603599 public void visitMethodInsn (int opcode , String owner , String name , String desc ) {
604-
600+
605601 // owner is the internal name of the method's owner class
606602 considerName (owner );
607603 // desc is the method's descriptor (see Type).
@@ -610,7 +606,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc)
610606
611607 // instruction multianewarray, whatever that is
612608 public void visitMultiANewArrayInsn (String desc , int dims ) {
613-
609+
614610 // desc an array type descriptor.
615611 considerDesc (desc );
616612 }
@@ -624,7 +620,7 @@ public AnnotationVisitor visitParameterAnnotation(int parameter, String desc,
624620
625621 public void visitTableSwitchInsn (int min , int max , Label dflt , Label [] labels ) {
626622 // pass -- table switch instruction
627-
623+
628624 }
629625
630626 public void visitTryCatchBlock (Label start , Label end , Label handler , String type ) {
@@ -641,10 +637,10 @@ public void visitTypeInsn(int opcode, String type) {
641637 }
642638
643639 public void visitVarInsn (int opcode , int var ) {
644- // pass -- local variable instruction
640+ // pass -- local variable instruction
645641 }
646642
647-
643+
648644 // ---------------------------------------------------
649645 // --- SignatureVisitor
650646 // ---------------------------------------------------
@@ -716,8 +712,8 @@ public void visitTypeVariable(String name) {
716712 public void visitTypeArgument () {
717713 // pass
718714 }
719-
720-
715+
716+
721717 // ---------------------------------------------------
722718 // --- AnnotationVisitor
723719 // ---------------------------------------------------
@@ -746,6 +742,6 @@ public void visitEnum(String name, String desc, String value) {
746742 // desc is the class descriptor of the enumeration class.
747743 considerDesc (desc );
748744 }
749-
745+
750746 }
751747}
0 commit comments