Value value = box.getValue();
/*Type type = */value.getType();
if (value instanceof NewExpr) {
// Fix kernel exceptions to be runtime exceptions.
NewExpr expr = (NewExpr) value;
SootClass exceptionClass = expr.getBaseType()
.getSootClass();
if (_isPtolemyException(exceptionClass)) {
expr.setBaseType(RefType
.v(PtolemyUtilities.runtimeExceptionClass));
}
} else if (value instanceof CastExpr) {
CastExpr expr = (CastExpr) value;
Type castType = expr.getCastType();
if (castType instanceof RefType
&& _isPtolemyException(((RefType) castType)
.getSootClass())) {
expr.setCastType(RefType
.v(PtolemyUtilities.runtimeExceptionClass));
}
} else if (value instanceof SpecialInvokeExpr) {
// Fix the exception constructors.
SpecialInvokeExpr expr = (SpecialInvokeExpr) value;
SootClass exceptionClass = ((RefType) expr.getBase()
.getType()).getSootClass();
if (_isPtolemyException(exceptionClass)) {
Value foundArg = null;
for (Iterator args = expr.getArgs().iterator(); args
.hasNext();) {
Value arg = (Value) args.next();
if (arg.getType().equals(
RefType.v(PtolemyUtilities.stringClass))) {
foundArg = arg;
break;
}
}
if ((foundArg == null) || _obfuscate) {
box
.setValue(Jimple
.v()
.newSpecialInvokeExpr(
(Local) expr.getBase(),
PtolemyUtilities.runtimeExceptionConstructor
.makeRef(),
Collections.EMPTY_LIST));
} else {
box
.setValue(Jimple
.v()
.newSpecialInvokeExpr(
(Local) expr.getBase(),
PtolemyUtilities.runtimeExceptionStringConstructor
.makeRef(),
foundArg));
}
}
} else if (value instanceof VirtualInvokeExpr) {
VirtualInvokeExpr expr = (VirtualInvokeExpr) value;
Type exceptionType = expr.getBase().getType();
if (exceptionType instanceof RefType) {
SootClass exceptionClass = ((RefType) exceptionType)
.getSootClass();
if (_isPtolemyException(exceptionClass)) {
SootMethod method = expr.getMethod();
if (method.getName().equals("getMessage")) {
if (unit instanceof InvokeStmt) {
body.getUnits().remove(unit);
} else {