Innspection for String.indexOf(char)

Hi,

I'm wondering if it makes sense to add an inspection that finds
String.indexOf(char) != -1 and String.indexOf(char) == -1 ... those
expressions can be written more clearly as String.contains(char) and
!String.contains(char) since 1.5.

What do yo think?

6 comments
Comment actions Permalink

Don't forget the 'string.indexOf(chr) < 0' statements.

Tom

0
Comment actions Permalink

Sounds useful. Please submit a request.

Bas

Michael Riess wrote:

Hi,

I'm wondering if it makes sense to add an inspection that finds
String.indexOf(char) != -1 and String.indexOf(char) == -1 ... those
expressions can be written more clearly as String.contains(char) and
!String.contains(char) since 1.5.

What do yo think?

0
Comment actions Permalink

Thomas Singer schrieb:

Don't forget the 'string.indexOf(chr) < 0' statements.

Tom


Yes ... <= -1, < 0 and > -1 can also be replaced.

BTW: >= -1 can be replaced by TRUE, and < -1 can be replaced by FALSE. ;)

0
Comment actions Permalink

Oh my so much syntactical variations.
Here's another one: Much of our code is using
indexOf() >= 0

All of these variations reinforce the need for the inspection...

Michael Riess wrote:

Thomas Singer schrieb:

>> Don't forget the 'string.indexOf(chr) < 0' statements.
>>
>> Tom


Yes ... <= -1, < 0 and > -1 can also be replaced.

BTW: >= -1 can be replaced by TRUE, and < -1 can be replaced by FALSE. ;)

0
Comment actions Permalink

And the url for the request so we can vote for it ;)

BoD

Bas Leijdekkers wrote:

Sounds useful. Please submit a request.

Bas

Michael Riess wrote:

>> Hi,
>>
>> I'm wondering if it makes sense to add an inspection that finds
>> String.indexOf(char) != -1 and String.indexOf(char) == -1 ... those
>> expressions can be written more clearly as String.contains(char) and
>> !String.contains(char) since 1.5.
>>
>> What do yo think?

0
Comment actions Permalink

I submitted my first request ... hopefully it's a good one! ;)

http://www.jetbrains.net/jira/browse/IDEADEV-2333

And the url for the request so we can vote for it ;)

BoD

Bas Leijdekkers wrote:

>> Sounds useful. Please submit a request.
>>
>> Bas
>>
>> Michael Riess wrote:
>>
>>> Hi,
>>>
>>> I'm wondering if it makes sense to add an inspection that finds
>>> String.indexOf(char) != -1 and String.indexOf(char) == -1 ... those
>>> expressions can be written more clearly as String.contains(char) and
>>> !String.contains(char) since 1.5.
>>>
>>> What do yo think?

0

Please sign in to leave a comment.