ValueBox box = (ValueBox) boxes.next();
Value value = box.getValue();
if (value instanceof InstanceFieldRef) {
// Fix references to fields
InstanceFieldRef r = (InstanceFieldRef) value;
if (object != analysis.getObject((Local) r.getBase())) {
// System.out.println("object = " + object);
// System.out.println("analysis object = " + analysis.getObject((Local)r.getBase()));
// System.out.println("not equal!");
continue;
}
if (SootUtilities.derivesFrom(oldClass, r.getField()
.getDeclaringClass())
&& newClass.declaresFieldByName(r.getField()
.getName())) {
r.setFieldRef(newClass.getFieldByName(
r.getField().getName()).makeRef());
// System.out.println("fieldRef = " +
// box.getValue());
// } else if (r.getField().getDeclaringClass().getName()
// .startsWith(oldClass.getName())) {
// SootClass changeClass =
// _getInnerClassCopy(oldClass,
// r.getField().getDeclaringClass(),
// newClass);
// r.setField(changeClass.getFieldByName(
// r.getField().getName()));
}
} else if (value instanceof CastExpr) {
// Fix casts
CastExpr r = (CastExpr) value;
try {
if (object != analysis.getObject((Local) r.getOp())) {
continue;
}
} catch (Exception ex) {
if (_debug) {
System.out.println("Exception on cast = " + ex);
}
continue;
}
Type type = r.getType();
if (type instanceof RefType) {
SootClass refClass = ((RefType) type)
.getSootClass();
if (refClass == oldClass) {
r.setCastType(RefType.v(newClass));
// System.out.println("newValue = " +
// box.getValue());
// } else if (refClass.getName().startsWith(
// oldClass.getName())) {
// SootClass changeClass =
// _getInnerClassCopy(oldClass,
// refClass, newClass);
// r.setCastType(RefType.v(changeClass));
}
}
// } else if (value instanceof ThisRef) {
// // Fix references to 'this'
// ThisRef r = (ThisRef)value;
// Type type = r.getType();
// if (type instanceof RefType &&
// ((RefType)type).getSootClass() == oldClass) {
// box.setValue(Jimple.v().newThisRef(
// RefType.v(newClass)));
// }
// } else if (value instanceof ParameterRef) {
// // Fix references to a parameter
// ParameterRef r = (ParameterRef)value;
// Type type = r.getType();
// if (type instanceof RefType &&
// ((RefType)type).getSootClass() == oldClass) {
// box.setValue(Jimple.v().newParameterRef(
// RefType.v(newClass), r.getIndex()));
// }
} else if (value instanceof InstanceInvokeExpr) {
// Fix up the method invokes.
InstanceInvokeExpr r = (InstanceInvokeExpr) value;
try {
if (object != analysis.getObject((Local) r
.getBase())) {
// System.out.println("object = " + object);
// System.out.println("analysis object = " + analysis.getObject((Local)r.getBase()));
// System.out.println("not equal!");
continue;
}
} catch (Exception ex) {
if (_debug) {
System.out.println("Exception on invoke = "
+ ex);
}
continue;
}
if (SootUtilities.derivesFrom(oldClass, r.getMethod()
.getDeclaringClass())) {
if (newClass.declaresMethod(r.getMethod()
.getSubSignature())) {
SootMethod replacementMethod = newClass
.getMethod(r.getMethod()
.getSubSignature());
r.setMethodRef(replacementMethod.makeRef());
}
// } else if (r.getMethod().getDeclaringClass().getName().
// startsWith(oldClass.getName())) {
// SootClass changeClass =
// _getInnerClassCopy(oldClass,
// r.getMethod().getDeclaringClass(),
// newClass);
// r.setMethod(changeClass.getMethod(
// r.getMethod().getSubSignature()));
}
} else if (value instanceof NewExpr) {
// Fix up the object creations.
NewExpr r = (NewExpr) value;
if (!(unit instanceof AssignStmt)) {
continue;
}
AssignStmt stmt = (AssignStmt) unit;
try {
if (object != analysis.getObject((Local) stmt
.getLeftOp())) {
continue;
}
} catch (Exception ex) {
if (_debug) {
System.out.println("Exception on new = " + ex);
}
continue;
}
if (r.getBaseType().getSootClass() == oldClass) {
r.setBaseType(RefType.v(newClass));
// System.out.println("newValue = " +
// box.getValue());
// } else if (r.getBaseType().getSootClass().getName().
// startsWith(oldClass.getName())) {