1 19 20 package soot.jimple.toolkits.callgraph; 21 import soot.*; 22 import soot.util.*; 23 import soot.util.queue.*; 24 import java.util.*; 25 26 30 public class TransitiveTargets 31 { 32 private CallGraph cg; 33 private Filter filter; 34 public TransitiveTargets( CallGraph cg ) { 35 this.cg = cg; 36 } 37 public TransitiveTargets( CallGraph cg, Filter filter ) { 38 this.cg = cg; 39 this.filter = filter; 40 } 41 public Iterator iterator( Unit u ) { 42 ArrayList methods = new ArrayList(); 43 Iterator it = cg.edgesOutOf( u ); 44 if( filter != null ) it = filter.wrap( it ); 45 while( it.hasNext() ) { 46 Edge e = (Edge) it.next(); 47 methods.add( e.getTgt() ); 48 } 49 return iterator( methods.iterator() ); 50 } 51 public Iterator iterator( MethodOrMethodContext momc ) { 52 ArrayList methods = new ArrayList(); 53 Iterator it = cg.edgesOutOf( momc ); 54 if( filter != null ) it = filter.wrap( it ); 55 while( it.hasNext() ) { 56 Edge e = (Edge) it.next(); 57 methods.add( e.getTgt() ); 58 } 59 return iterator( methods.iterator() ); 60 } 61 public Iterator iterator( Iterator methods ) { 62 Set s = new HashSet(); 63 ArrayList worklist = new ArrayList(); 64 while( methods.hasNext() ) { 65 MethodOrMethodContext method = (MethodOrMethodContext) methods.next(); 66 if( s.add( method ) ) worklist.add( method ); 67 } 68 return iterator( s, worklist ); 69 } 70 private Iterator iterator( Set s, ArrayList worklist ) { 71 for( int i = 0; i < worklist.size(); i++ ) { 72 MethodOrMethodContext method = (MethodOrMethodContext) worklist.get(i); 73 Iterator it = cg.edgesOutOf( method ); 74 if( filter != null ) it = filter.wrap( it ); 75 while( it.hasNext() ) { 76 Edge e = (Edge) it.next(); 77 if( s.add( e.getTgt() ) ) worklist.add( e.getTgt() ); 78 } 79 } 80 return worklist.iterator(); 81 } 82 } 83 84 85 | Popular Tags |