1 package com.android.class2nonsdklist; 2 3 import com.android.annotationvisitor.AnnotatedMemberContext; 4 import com.android.annotationvisitor.AnnotationContext; 5 import com.android.annotationvisitor.Status; 6 7 import org.apache.bcel.classfile.DescendingVisitor; 8 import org.apache.bcel.classfile.EmptyVisitor; 9 import org.apache.bcel.classfile.Field; 10 import org.apache.bcel.classfile.FieldOrMethod; 11 import org.apache.bcel.classfile.JavaClass; 12 import org.apache.bcel.classfile.Method; 13 14 /** 15 * A class file visitor that simply prints to stdout the signature of every member within the class. 16 */ 17 public class MemberDumpingVisitor extends EmptyVisitor { 18 19 private final Status mStatus; 20 private final DescendingVisitor mDescendingVisitor; 21 22 /** 23 * Creates a visitor for a class. 24 * 25 * @param clazz Class to visit 26 */ MemberDumpingVisitor(JavaClass clazz, Status status)27 public MemberDumpingVisitor(JavaClass clazz, Status status) { 28 mStatus = status; 29 mDescendingVisitor = new DescendingVisitor(clazz, this); 30 } 31 visit()32 public void visit() { 33 mDescendingVisitor.visit(); 34 } 35 36 @Override visitMethod(Method method)37 public void visitMethod(Method method) { 38 visitMember(method, "L%s;->%s%s"); 39 } 40 41 @Override visitField(Field field)42 public void visitField(Field field) { 43 visitMember(field, "L%s;->%s:%s"); 44 } 45 visitMember(FieldOrMethod member, String signatureFormatString)46 private void visitMember(FieldOrMethod member, String signatureFormatString) { 47 AnnotationContext context = new AnnotatedMemberContext(mStatus, 48 (JavaClass) mDescendingVisitor.predecessor(), member, 49 signatureFormatString); 50 System.out.println(context.getMemberDescriptor()); 51 } 52 } 53