Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I restrict search matches in Eclipse to filter out results in comments?

I want to search my whole project for a certain string, but I only want results which are uncommented. It would be great if there was just an option to not include comments in the search results, but I don't see how to do this.

Is there a hidden option for this, or a trick? I could go back to the command line and use grep, but I prefer to have the results within eclipse so I can easily jump to the line number.

like image 268
Erick Robertson Avatar asked Jun 10 '11 12:06

Erick Robertson


2 Answers

In "File Search", you can tick "Regular expressions" and use this regex to search for "some text" but exclude one-line (ie // ...) java comments:

^(?!\s*//).*some text

There's probably a better way to express this. It would be difficult (impossible?) to to write a regex for multi-line comments ie /* ...many lines... */

EDIT:

This regex will also exclude all lines whose first character is * - ie javadoc comments:

^(?!\s*(//|\*)).*some text

While lines that start with * are not necessarily comments, it is rare indeed for java code.

like image 177
Bohemian Avatar answered Nov 10 '22 11:11

Bohemian


You can limit your search results, from the Java Search tab, if you are employing Java Search in the first place.

Searches can be limited to References, Declarations, Implementors and selected other areas of the source code, instead of All ocurrences (which might be the default in your case).

If you are referring to plain text searches (the File Search tab), then you are out of luck.

like image 40
Vineet Reynolds Avatar answered Nov 10 '22 12:11

Vineet Reynolds