if (triviallyTrue) {
// remove the cast operation
ctx.replaceMe(x.getExpr());
} else if (triviallyFalse && toType != program.getTypeNull()) {
// replace with a magic NULL cast, unless it's already a cast to NULL
JCastOperation newOp = new JCastOperation(x.getSourceInfo(),
program.getTypeNull(), x.getExpr());
ctx.replaceMe(newOp);
} else {
// If possible, try to use a narrower cast
JReferenceType tighterType = getSingleConcreteType(toType);
if (tighterType != null && tighterType != toType) {
JCastOperation newOp = new JCastOperation(x.getSourceInfo(),
tighterType, x.getExpr());
ctx.replaceMe(newOp);
}
}
}