DeMorgan's Law intention

I have code like this:

if (!isSomething() && foo != null) foo.doSomething();

Why does IDEA not offer the DeMorgan's Law intention here? I would like
to use it to rewrite the code as

if (!(isSomething() || foo == null)) foo.doSomething();

And while we're on the subject, the description of this intention is
rather confusing. It says

This intention replaces either

a || b with !(!a && !b) or
a && b with !(!a || !b)

inside boolean expression.

That's not how I would explain DeMorgan's Law. I would say it replaces

!a && !b with !(a || b) or
!a || !b with !(a && b)

While the way it is now is technically true (since !!a is a), that way
of stating it certainly doesn't make it look like a simplification.
Furthermore, the latter statement is more consistent with the example
shown. (By the way, note the missing word in the current description: It
should read "inside a boolean expression.")

3 comments
Comment actions Permalink


Please file a JIRA item.

--Dave Griffith

0
Comment actions Permalink

I think you have a good point. Please submit a JIRA request (if it works).

Bas

Michael Besosa wrote:

I have code like this:

if (!isSomething() && foo != null) foo.doSomething();

Why does IDEA not offer the DeMorgan's Law intention here? I would like
to use it to rewrite the code as

if (!(isSomething() || foo == null)) foo.doSomething();

And while we're on the subject, the description of this intention is
rather confusing. It says

This intention replaces either

a || b with !(!a && !b) or
a && b with !(!a || !b)

inside boolean expression.

That's not how I would explain DeMorgan's Law. I would say it replaces

!a && !b with !(a || b) or
!a || !b with !(a && b)

While the way it is now is technically true (since !!a is a), that way
of stating it certainly doesn't make it look like a simplification.
Furthermore, the latter statement is more consistent with the example
shown. (By the way, note the missing word in the current description: It
should read "inside a boolean expression.")

0
Comment actions Permalink

Sorry for repeating the message, didn't see Dave's reply there.

Bas Leijdekkers wrote:

I think you have a good point. Please submit a JIRA request (if it works).

Bas

Michael Besosa wrote:

>> I have code like this:
>>
>> if (!isSomething() && foo != null) foo.doSomething();
>>
>> Why does IDEA not offer the DeMorgan's Law intention here? I would like
>> to use it to rewrite the code as
>>
>> if (!(isSomething() || foo == null)) foo.doSomething();
>>
>> And while we're on the subject, the description of this intention is
>> rather confusing. It says
>>
>> This intention replaces either
>>
>> a || b with !(!a && !b) or
>> a && b with !(!a || !b)
>>
>> inside boolean expression.
>>
>> That's not how I would explain DeMorgan's Law. I would say it replaces
>>
>> !a && !b with !(a || b) or
>> !a || !b with !(a && b)
>>
>> While the way it is now is technically true (since !!a is a), that way
>> of stating it certainly doesn't make it look like a simplification.
>> Furthermore, the latter statement is more consistent with the example
>> shown. (By the way, note the missing word in the current description: It
>> should read "inside a boolean expression.")

0

Please sign in to leave a comment.