1 19 20 package soot; 21 import soot.jimple.*; 22 23 26 public class BriefUnitPrinter extends LabeledUnitPrinter { 27 public BriefUnitPrinter( Body body ) { 28 super(body); 29 } 30 31 private boolean baf; 32 public void startUnit( Unit u ) { 33 super.startUnit(u); 34 if( u instanceof Stmt ) { 35 baf = false; 36 } else { 37 baf = true; 38 } 39 } 40 41 public void methodRef( SootMethodRef m ) { 42 handleIndent(); 43 if( !baf && m.resolve().isStatic() ){ 44 output.append( m.declaringClass().getName() ); 45 literal("."); 46 } 47 output.append( m.name() ); 48 } 49 public void fieldRef( SootFieldRef f ) { 50 handleIndent(); 51 if( baf || f.resolve().isStatic() ){ 52 output.append( f.declaringClass().getName() ); 53 literal("."); 54 } 55 output.append(f.name()); 56 } 57 public void identityRef( IdentityRef r ) { 58 handleIndent(); 59 if( r instanceof ThisRef ) { 60 literal("@this"); 61 } else if( r instanceof ParameterRef ) { 62 ParameterRef pr = (ParameterRef) r; 63 literal("@parameter"+pr.getIndex()); 64 } else if( r instanceof CaughtExceptionRef ) { 65 literal("@caughtexception"); 66 } else throw new RuntimeException (); 67 } 68 69 private boolean eatSpace = false; 70 public void literal( String s ) { 71 handleIndent(); 72 if( eatSpace && s.equals(" ") ) { 73 eatSpace = false; 74 return; 75 } 76 eatSpace = false; 77 if( !baf ) { 78 if( false 79 || s.equals( Jimple.STATICINVOKE ) 80 || s.equals( Jimple.VIRTUALINVOKE ) 81 || s.equals( Jimple.INTERFACEINVOKE ) 82 ) { 83 eatSpace = true; 84 return; 85 } 86 } 87 output.append(s); 88 } 89 90 public void type( Type t ) { 91 handleIndent(); 92 output.append( t.toString() ); 93 } 94 } 95 96 | Popular Tags |