size() == 0 -> isEmpty()

There exists an inspection to convert the statement

collection.size() == 0

to

collection.isEmpty()

but unfortunately, I can't find the opposite to change

!collection.isEmpty()

to

collection.size() > 0

Am I missing something?

Tom

4 comments
Comment actions Permalink

Hello Tom,

You can use Structural Search for this kind of transformation. I'm not sure
it would be useful to have in a product (as for me, I don't find the second
variant to be more readable than the first one).

There exists an inspection to convert the statement

collection.size() == 0

to

collection.isEmpty()

but unfortunately, I can't find the opposite to change

!collection.isEmpty()

to

collection.size() > 0

Am I missing something?

Tom

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

You can use Structural Search for this kind of transformation.


That's what I've done so far. BTW, I remember that there were structural
replace intentions in the past, but I can't find them any more. Are they gone?

I don't find the second variant to be more readable than the first one


Please leave this option to the user. There exists a couple of bidirectional
changes with the inspections which make IDEA very configurable to the
personal taste.

Tom


Dmitry Jemerov wrote:

Hello Tom,

You can use Structural Search for this kind of transformation. I'm not
sure it would be useful to have in a product (as for me, I don't find
the second variant to be more readable than the first one).

>> There exists an inspection to convert the statement
>>
>> collection.size() == 0
>>
>> to
>>
>> collection.isEmpty()
>>
>> but unfortunately, I can't find the opposite to change
>>
>> !collection.isEmpty()
>>
>> to
>>
>> collection.size() > 0
>>
>> Am I missing something?
>>
>> Tom
>>

0
Comment actions Permalink

Hello Tom,

>> You can use Structural Search for this kind of transformation.
>>

That's what I've done so far. BTW, I remember that there were
structural replace intentions in the past, but I can't find them any
more. Are they gone?


No, they're still there. Settings | Inspections | General | Structural Search
Inspection.

>> I don't find the second variant to be more readable than the first
>> one
>>

Please leave this option to the user. There exists a couple of
bidirectional changes with the inspections which make IDEA very
configurable to the personal taste.


JIRA issue is welcome as usual.


Tom

Dmitry Jemerov wrote:

>> Hello Tom,
>>
>> You can use Structural Search for this kind of transformation. I'm
>> not sure it would be useful to have in a product (as for me, I don't
>> find the second variant to be more readable than the first one).
>>
>>> There exists an inspection to convert the statement
>>>
>>> collection.size() == 0
>>>
>>> to
>>>
>>> collection.isEmpty()
>>>
>>> but unfortunately, I can't find the opposite to change
>>>
>>> !collection.isEmpty()
>>>
>>> to
>>>
>>> collection.size() > 0
>>>
>>> Am I missing something?
>>>
>>> Tom
>>>
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

No, they're still there. Settings | Inspections | General | Structural Search Inspection.


Thanks. I hope, I remember it. ;)

JIRA issue is welcome as usual.


IDEA-24166

Tom



Dmitry Jemerov wrote:

Hello Tom,

>>> You can use Structural Search for this kind of transformation.
>>>
>> That's what I've done so far. BTW, I remember that there were
>> structural replace intentions in the past, but I can't find them any
>> more. Are they gone?


No, they're still there. Settings | Inspections | General | Structural
Search Inspection.

>>
>>> I don't find the second variant to be more readable than the first
>>> one
>>>
>> Please leave this option to the user. There exists a couple of
>> bidirectional changes with the inspections which make IDEA very
>> configurable to the personal taste.


JIRA issue is welcome as usual.

>>
>> Tom
>>
>> Dmitry Jemerov wrote:
>>
>>> Hello Tom,
>>>
>>> You can use Structural Search for this kind of transformation. I'm
>>> not sure it would be useful to have in a product (as for me, I don't
>>> find the second variant to be more readable than the first one).
>>>
>>>> There exists an inspection to convert the statement
>>>>
>>>> collection.size() == 0
>>>>
>>>> to
>>>>
>>>> collection.isEmpty()
>>>>
>>>> but unfortunately, I can't find the opposite to change
>>>>
>>>> !collection.isEmpty()
>>>>
>>>> to
>>>>
>>>> collection.size() > 0
>>>>
>>>> Am I missing something?
>>>>
>>>> Tom
>>>>

0

Please sign in to leave a comment.