InspectionGadgets: Unnecessary but clarifying parentheses

Hello,

I was working on a project lately with a large number of error inspections turned on and found that IDEA highlights an expression like

because it claims the parentheses around hasBar() && isBla() are unnecessary which is of course true.

However, I believe that this is one of the rare cases where unnecessary parentheses actually make the code more readable instead of less readable, so I wish there was an option to "fine-tune" this inspection because as a whole I think it is really nice to see where you can save yourself some parentheses.

I don't know how the inspection works internally, but would it be possible to declare certain pairs of operators as being "almost on the same level within the operator hierarchy" so that parentheses should be used when combining them?

Regards,
Jens

1 comment
Comment actions Permalink

Hi Jens,

I have added a ticket to the Jetbrains JIRA for your request:
http://www.jetbrains.net/jira/browse/IDEADEV-28080
My plan is to get this in Diana.

Bas

Jens Voss wrote:

Hello,

I was working on a project lately with a large number of error inspections turned on and found that IDEA highlights an expression like

 boolean b = isFoo() || (hasBar() && isBla());
> ]]>

because it claims the parentheses around hasBar() && isBla() are unnecessary which is of course true.

However, I believe that this is one of the rare cases where unnecessary parentheses actually make the code more readable instead of less readable, so I wish there was an option to "fine-tune" this inspection because as a whole I think it is really nice to see where you can save yourself some parentheses.

I don't know how the inspection works internally, but would it be possible to declare certain pairs of operators as being "almost on the same level within the operator hierarchy" so that parentheses should be used when combining them?

Regards,
Jens

0

Please sign in to leave a comment.