CallGraphBuilder cg = new CallGraphBuilder(DumbPointerAnalysis.v(),
true);
cg.build();
CallGraph callGraph = Scene.v().getCallGraph();
ReachableMethods reachableMethods = new ReachableMethods(callGraph,
EntryPoints.v().application());
reachableMethods.update();
Hierarchy hierarchy = Scene.v().getActiveHierarchy();
final Set createableClasses = new HashSet();
for (Iterator reachables = reachableMethods.listener(); reachables
.hasNext();) {
SootMethod method = (SootMethod) reachables.next();
//String methodName = method.getSignature();
if (method.getName().equals("<init>")
&& !method.getDeclaringClass().getName().startsWith("java")) {
createableClasses
.addAll(hierarchy.getSuperclassesOfIncluding(method
.getDeclaringClass()));
_addAllInterfaces(createableClasses, method.getDeclaringClass());
}
}
System.out.println("createableClasses = " + createableClasses);
// Now create a new set of reachable methods that only
// includes methods that are static or are declared in classes
// that can are created.
Filter filter = new Filter(new EdgePredicate() {
public boolean want(Edge e) {
SootMethod target = e.tgt();
return e.isExplicit()
&& (target.isStatic() || createableClasses
.contains(target.getDeclaringClass()));
}
});
Set necessaryClasses = new HashSet();
ReachableMethods RTAReachableMethods = new ReachableMethods(callGraph,
EntryPoints.v().application().iterator(), filter);
RTAReachableMethods.update();
List list = new LinkedList();
for (Iterator reachables = RTAReachableMethods.listener(); reachables
.hasNext();) {
SootMethod method = (SootMethod) reachables.next();
String methodName = method.getSignature();
list.add(methodName);