private static void _removeDeadObjectCreation(Body body, Set classSet) {
CompleteUnitGraph unitGraph = new CompleteUnitGraph(body);
// this will help us figure out where locals are defined.
SimpleLocalDefs localDefs = new SimpleLocalDefs(unitGraph);
SimpleLiveLocals liveLocals = new SimpleLiveLocals(unitGraph);
for (Iterator units = body.getUnits().snapshotIterator(); units
.hasNext();) {
Stmt stmt = (Stmt) units.next();
if (!stmt.containsInvokeExpr()) {
continue;
}
ValueBox box = stmt.getInvokeExprBox();
Value value = box.getValue();
if (value instanceof SpecialInvokeExpr) {
SpecialInvokeExpr r = (SpecialInvokeExpr) value;
// System.out.println("compare " + r.getMethod().getDeclaringClass());
// System.out.println("with " + theClass);
if (classSet.contains(r.getMethod().getDeclaringClass())
&& !liveLocals.getLiveLocalsAfter(stmt).contains(
r.getBase())) {
// Remove the initialization and the constructor.
// Note: This assumes a fairly tight coupling between
// the new and the object constructor. This may
// not be true.