tags:

views:

185

answers:

3

For example, let's say I want to find all instances of using the == operator with any string object, so that I can replace it with .equals() instead. How can I do such a search? Otherwise I'd have to pick through all my code line-by-line... Thanks :)

+4  A: 

Eclipse doesn't have any special search capabilities for operators. That doesn't mean that you can't do a file search for them though.

You're probably better off running PMD to find issues like this for you.

Kevin
+1 PMD. Add FindBugs, too.
matt b
PMD allows you to write your own rules very easily, using XPath or Java. Does FindBugs do that too?
erickson
"Does FindBugs do that too?"Not *easily*. ;o)
yawmark
A: 

Do a File Search for '=="' and '== "' in all files.

CTRL-H -> File Search tab

Containing text: =="
File name patterns: *.java

And then do the same for the string == " (note there is a space between the == and the "

stephendl
It does not work if you compare string variable like in if (oneString == anotherString)
romaintaz
Aah - good point. I never though of that.
stephendl
+1  A: 

FindBugs may produce warning for this type of coding as well.

Peter Lawrey