For example, if we have method:
private A getA(A a1, A a2) {
if (a1 != null) {
return a1;
} else {
return a2;
}
}
Does IDEA have some hotkey (like Ctrl+Alt+V for extracting variable) to make from this code something like this:
private A selectA(A a1, A a2) {
A result;
if (a1 != null) {
result = a1;
} else {
result = a2;
}
return result;
}
Put the caret at the method name, press Alt+Enter, then choose "Transform body to single exit-point form". It will convert the method to a single return form.
The setting can be found in Settings | Editor | Intentions, then Java | Control flow | Transform body to single exit-point form. It should be enabled by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With