1 17 package org.apache.bcel.verifier; 18 19 import org.apache.bcel.Repository; 20 import org.apache.bcel.classfile.JavaClass; 21 22 31 public class TransitiveHull implements VerifierFactoryObserver { 32 33 34 private int indent = 0; 35 36 37 38 private TransitiveHull() { 39 } 40 41 42 43 public void update( String classname ) { 44 System.gc(); for (int i = 0; i < indent; i++) { 46 System.out.print(" "); 47 } 48 System.out.println(classname); 49 indent += 1; 50 Verifier v = VerifierFactory.getVerifier(classname); 51 VerificationResult vr; 52 vr = v.doPass1(); 53 if (vr != VerificationResult.VR_OK) { 54 System.out.println("Pass 1:\n" + vr); 55 } 56 vr = v.doPass2(); 57 if (vr != VerificationResult.VR_OK) { 58 System.out.println("Pass 2:\n" + vr); 59 } 60 if (vr == VerificationResult.VR_OK) { 61 try { 62 JavaClass jc = Repository.lookupClass(v.getClassName()); 63 for (int i = 0; i < jc.getMethods().length; i++) { 64 vr = v.doPass3a(i); 65 if (vr != VerificationResult.VR_OK) { 66 System.out.println(v.getClassName() + ", Pass 3a, method " + i + " ['" 67 + jc.getMethods()[i] + "']:\n" + vr); 68 } 69 vr = v.doPass3b(i); 70 if (vr != VerificationResult.VR_OK) { 71 System.out.println(v.getClassName() + ", Pass 3b, method " + i + " ['" 72 + jc.getMethods()[i] + "']:\n" + vr); 73 } 74 } 75 } catch (ClassNotFoundException e) { 76 System.err.println("Could not find class " + v.getClassName() + " in Repository"); 77 } 78 } 79 indent -= 1; 80 } 81 82 83 89 public static void main( String [] args ) { 90 if (args.length != 1) { 91 System.out.println("Need exactly one argument: The root class to verify."); 92 System.exit(1); 93 } 94 int dotclasspos = args[0].lastIndexOf(".class"); 95 if (dotclasspos != -1) { 96 args[0] = args[0].substring(0, dotclasspos); 97 } 98 args[0] = args[0].replace('/', '.'); 99 TransitiveHull th = new TransitiveHull(); 100 VerifierFactory.attach(th); 101 VerifierFactory.getVerifier(args[0]); VerifierFactory.detach(th); 103 } 104 } 105 | Popular Tags |