Inspection/Quickfix idea
Something really simple here, apologies if it is already implemented,
but I couldn't find it.
After refactoring I ended up with an expression:
Boolean.TRUE.booleanValue()
It would be nice if this was detected and a quick fix to convert to
'true' available.
Cheers,
N.
Please sign in to leave a comment.
Hi Nathan,
Nathan Brown wrote:
> Boolean.TRUE.booleanValue()
I have modified the "Unnecessary Unboxing" inspections quick fix to
convert this to true (or false). If you don't use that inspection, this
is also an excellent use for the "Structural Search Inspection" inspection.
Add two replace templates like this:
Search template 1 "Unboxing Boolean.TRUE":
$BooleanConstant$.booleanValue
Text / regular expression: TRUE
Text / regular expression for java expression type: java.lang.Boolean
Replacement template 1:
true
Search template 2 "Unboxing Boolean.FALSE":
$BooleanConstant$.booleanValue
Text / regular expression: FALSE
Text / regular expression for java expression type: java.lang.Boolean
Replacement template 2:
false
If you want a full blown inspection, please submit a JIRA request.
Perhaps it might even be generalized a little to a "Unboxing a Constant"
inspection, which also reports when constant Integers and other
primitive wrappers are unboxed. Only if people would find that useful of
course.
Bas