.hasNext();) {
SootMethod method = (SootMethod) reachables.next();
String methodName = method.getSignature();
list.add(methodName);
SootClass declaringClass = method.getDeclaringClass();
if (!declaringClass.getName().startsWith("java")) {
necessaryClasses.add(declaringClass);
}
if (method.isConcrete()) {
for (Iterator units = method.retrieveActiveBody().getUnits()
.iterator(); units.hasNext();) {
Unit unit = (Unit) units.next();
for (Iterator boxes = unit.getUseBoxes().iterator(); boxes
.hasNext();) {
ValueBox box = (ValueBox) boxes.next();
Value value = box.getValue();
if (value instanceof CastExpr) {
CastExpr expr = (CastExpr) value;
Type castType = expr.getCastType();
if (castType instanceof RefType) {
SootClass castClass = ((RefType) castType)
.getSootClass();
if (castClass.isInterface()) {
necessaryClasses.add(castClass);
} else {
necessaryClasses
.addAll(hierarchy
.getSuperclassesOfIncluding(castClass));
}
_addAllInterfaces(necessaryClasses, castClass);
}
} else if (value instanceof InstanceOfExpr) {
InstanceOfExpr expr = (InstanceOfExpr) value;
Type checkType = expr.getCheckType();
if (checkType instanceof RefType) {
SootClass checkClass = ((RefType) checkType)
.getSootClass();
if (!checkClass.isInterface()) {
necessaryClasses
.addAll(hierarchy
.getSuperclassesOfIncluding(checkClass));
}
_addAllInterfaces(necessaryClasses, checkClass);
}
}
}
}
}
}
// Print out all the used methods
Collections.sort(list);
for (Iterator names = list.iterator(); names.hasNext();) {
System.out.println(names.next());
}
try {
// Add to the set of necessary classes all that they depend on.
DependedClasses dependedClasses = new DependedClasses(
necessaryClasses);
FileWriter writer = null;
try {
writer = new FileWriter(outFile);
for (Iterator classes = dependedClasses.list().iterator(); classes
.hasNext();) {
SootClass theClass = (SootClass) classes.next();
if (analyzeAllReachables) {
// Set the class to be an application class, so we can
// analyze it.
theClass.setApplicationClass();
}
writer.write(theClass.getName());
writer.write("\n");
}
} finally {
if (writer != null) {
try {