I have inherited code laden with ternary conditionals. This style is disallowed by our coding standards (which were introduced after the code has been written).
I am looking for a way to avoid rewriting all these statements manually. Is there a setting/plugin/sth. else in eclipse for this job?
Thank you.
PS. Though I am explicitly looking for a eclipse-based solution, I am not entirely averse to a nice ruby script for this 😉
EDIT : The “press Ctrl+1” approach by Joachim Sauer works for the example case, but does not not for a typical eclipse-generated hashCode
int prime = 31;
int result = 1;
result{Ctrl+1} = prime * result + ((id == null) ? 0 : id.hashCode());
Pressing Ctrl+1 on the marked spot shows the following options only:
Rename in file, rename in workspace, Extract local, Copy to criteria Editor, Extract to local variable
If it would work universally, that would be great. Better still would be a solution that does not involve visting each occurrence.
I am using eclipse 3.7 on OpenSUSE 11, in case this is relevant.
Assuming this sample code:
Place the cursor after the
aand press Ctrl–1. Then select “Replace conditional with ‘if-else'”.That results in this code:
Use Refactor > Inline (Ctrl–Shift–I) as applicable to reduce unnecessary variable declarations.