IG/IPP suggestion

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.


7 comments


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

0

This would probably be handled by "Extract Statement" refactoring at
http://jetbrains.net/jira/browse/IDEABKL-2968.

Vincent Mallet wrote:

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.

0

Ok, thanks. I'll make sure to try it when it gets in.

Vince.


0

Not really. In the case I described we're trying to 'inline' the boolean,
in your case we're 'introducing' a new temp.

Vince.


0

Vincent Mallet wrote:

Not really. In the case I described we're trying to 'inline' the boolean,
in your case we're 'introducing' a new temp.

Vince.


Yes but then a Simplify intention invoked on the if statement would produce the
correct result.

0

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.


0

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:

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.

0

Please sign in to leave a comment.