I have some truly bad code that has returns all over the place making tracing through a nightmare. I would like some way of transforming a method so that it has exactly one point of return. I'm not sure how exceptions should be handled (but I think they could be left as they are).
Consider the following method:
public int blah() {
if (System.currentTimeMillis() > 12L) {
return 4;
}
return 7;
}
Is there a refactoring to transform this to:
public int blah() {
int ret;
if (System.currentTimeMillis() > 12L) {
ret = 4
} else {
ret = 7
}
return ret;
}