IG/IPP suggestion Follow
Given the code:
if (someBoolean) {
someStatement(true);
} else {
someStatement(false);
}.
I'd like an inspection/fix to turn that into
someStatement(someBoolean);
Does that sound reasonable? If so I'll put it in Jira.
Thanks,
Vince.
Please sign in to leave a comment.
There's already a tracker item for this. Maxim posted it too close to the release to risk destabilizing, or I'd have probably done it already. Tricky, but valuable.
--Dave Griffith
This would probably be handled by "Extract Statement" refactoring at
http://jetbrains.net/jira/browse/IDEABKL-2968.
Vincent Mallet wrote:
Ok, thanks. I'll make sure to try it when it gets in.
Vince.
Not really. In the case I described we're trying to 'inline' the boolean,
in your case we're 'introducing' a new temp.
Vince.
Vincent Mallet wrote:
Yes but then a Simplify intention invoked on the if statement would produce the
correct result.
This is really a stretch, and it wouldn't work for me (what's the
point if I can do it by hand twice as fast?)
// Original:
if (someBoolean) {
someStatement(true);
} else {
someStatement(false);
}
// Extract Statement intention:
Boolean temp;
if (someBoolean) {
temp = true;
} else {
temp = false;
}
someSatement(temp);
// Go to "if", Simplify If intention:
Boolean temp;
temp = someBoolean;
someStatement(temp);
// Go to 'temp' declaration, join lines to enable next refactor:
Boolean temp = someBoolean;
someStatement(temp);
// Inline 'temp':
someStatement(someBoolean);
Three extra steps and I can't use the batch inspection.
Vince.
You're right. However I think the fact that this operation requires so many
steps represents flaws in IDEA. Maybe we need a "Simplify Code" refactoring
which performs the last three steps you give.
Vincent Mallet wrote: