Best way to search for instances of a string in Eclipse - eclipse

I am trying to find where a particular variable is being set. Is it possible to search through a set of project source files to find all the possible spots a certain variable might be getting set?
The search in the drop-down menu is a bit confusing to use. After I enter a search I happen to be looking at, and I know it is there, when I do a search from the root of the file system, it tells me that the string is not there :)
Is this a common newbie issue? I just recently started using Eclipse and could just be missing something simple :)
Thanks,
Alex

Select the field where it is declared, then ctrl+shift+H to open the search dialog. The "Java Search" tab should be selected with the Search string populated with your field name, including package. In "Search For" select "Field" and in "Limit To" select "Write accesses" That will show you everywhere that field is assigned.
Here's a screenshot of the search dialog.

I believe the default mapping is Ctrl Shift G.
Highlight the variable and do Ctrl Shift G it will find all references of that variable.
Be careful, it will not just do assignments, so you might be getting more data than you want.

Related

In Eclipse, how can you search within a search result?

"Long live the Unix Pipes".
Since I am working with Eclipse IDE, I would like to perform search within search results. Is that possible? How can I do that?
Ex:
Search for references of User (class).
> Search for validation in this result.
> Finally, search for specific pattern.
This is possible in Eclipse, well as far as the version I am using which is Eclipse Juno 4.2.2; I've used this extensively for impact analysis.
For example:
Search using "File Search" with criteria "employee"
The results will appear in the Tab "Search", assuming you are in the tree view (by default), click the root folder
Again, use the "File Search" this time using the 2nd criteria, for example "default" and making sure to click the Selected resources radio button
Effectively, this searches the keyword "default" from the previous search results produced by searching "employee".
Is it really required?. If you are searching any key in the search results then why don't you use it as search key in previous search itself?.
Eclipse search supports regular expression so you can use multiple search words likes key1 or key2 or key1 and key2 etc to narrow the search results.
Refer this Eclipse File Search Dialog - Regular Expression for Group Unions and Negation
However
You can search in search results with the help of some plugins check here. Take a look at Insta search and glance(Suites for your need) plugin.
Search result can also be exported with the help of this plugin
You cannot. And I am 99% sure of this.
But, just for your info, you can do reference search by pressing Cntrl + G on class name, or method name.

Stop eclipse renaming inside strings

I've been having this problem for some time and have never bothered to fix it since Eclipse has a horrible help system and I can't seem to find the right Google keywords to find what I need.
My problem is that when I refactor a class name, eclipse looks for all potential locations of that name and replaces them.
For instance, if I have a string inside a test case for the "list command" that says something like, "List - list all the users on a team", when I refactor the List.java class to something like UserListCommand.java, the expression inside the string also changes to "UserListCommand - list all the users on a team"
This is SOOO annoying! And like I said, Google is useless when you cannot even think of the right keywords to use.
Has anyone else had this problem and solved it?
Thanks in advance.
Eclipse calls this updating textual occurrences in comments and strings. I sometimes turn this on so javadoc gets updated correctly if I didn't properly link it. But it can be a pain because it sometimes replaces substrings that match.
I've only seen this when renaming classes or interfaces (methods don't seem to do this, at least not for me),
You need to open the Rename Dialog to stop eclipse from updating textual occurrences in comments and strings:
Highlight the type you want to rename, then either:
press Shift+Alt+R
Right click, then go to refactor->rename.. then instead of typing the new name, there should now be a yellow context popup menu under the class name to be changed which says "Enter new name, press Enter to refactor", notice that there is a down arrow to expand the menu. If you press that instead of enter a new name a new drop down menu appears, select Open Rename Dialog...
Once the Rename Dialog is open:
uncheck "update textual occurences in comments and strings (forces preview)" and "Update fully qualified names in non-Java text files (forces preview)"
Hope that helps

Is there a good "find all" function in Eclipse?

I have been using Eclipse for R and C++. So far I have not been able to find a reliable "find all" function. It seems to be an easy concept, I search for a string such as "rows" and the function should return all occurences of it within the that I currently have open. (Even if it's in all files in my owrkspace, that's fine too.)
However, I have either not understood how to use the "search" functions correctly or they are very buggy.
So my question is how do I search for all occurences of a string in a file in Eclpise?
Adobe Dreamweaver, for example, has been able to do this for years.(Although it's completely unrelated to R and C++)
I would like to view a list of all occurences and then be able to click on a specific occurence to go to it.
After opening Eclipse, (corresponding to a workspace), Press "CTRL + H" anywhere and you can search anything
like java files that contain specific "keywords".
all occurences within a java file.
plugins names etc
Just type "rows" or whatever the search term is somewhere in text, select it (so that it becomes highlighted) then press "Alt+Ctrl+g". This will perform a global search for that term, pretty handy.

Simple eclipse search problem

I use the eclipse File Search option very much to search all files in my workspace for a certain content. But how do I specify that it should only return hits from a fixed search criteria? As an example I would like to find all occurrences of the string:
com.mystuff.data
but I also get all the hits for:
com.mystuff.data.ui
How do I make a "this-string-only-search" when searching files in my workspace??
If I understand you correctly, Eclipse don't provide option to search exact word.
You can use regular expression for it.
You can use \bSearchKeyword\b to find exact word.
I suggest that you use regular expressions.
Here are the steps:
Select the checkbox "Regular expression" which is located beside the "Containing text" field.
In the "Containing text" field write: com.mystuff.data\D\W
Note that:
\D means "no digit"
\W means "no alphanumeric"
In case you would like to refine the regular expression, click Ctrl-SPACE, in order to get the regular expression assistance.
Hope this helps.
Best regards
Maybe slightly off-topic but this got me tripped and brought me here - maybe useful for somebody else:
In the Eclipse standard Find/Replace dialogue the section 'Options' (that includes the option 'Whole Word') may be hidden if the Find/Replace dialogue window was previously resized to a smaller size, without any clue to its presence. Resizing it larger brings back the options section. See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=355206
and attached shots.
Eclipse standard Find/Replace dialogue search for Whole Word regards several characters (including period) besides a space as a word delimiter, so you indeed cannot distinguish between "com.mystuff.data" and "com.mystuff.data.ui"
E.g. search 'Stack' with option 'Whole Word' checked:
will match:
Stack
Stack overflow
Stack.overflow
Stack,overflow
Stack[overflow]
Stack(overflow)
Stack-overflow
Stack/overflow
will not match:
Stackoverflow
Stack2overflow
Stack_overflow
Simplest way is to add space in the start and end of your search term.
Try SHFT+ CTRL+R, then on right upper angle select Working Set, then name and specify your resources.
Create Work Set as above, then CTRL+H check checkbox All occurency, then select your Work Set. Or maybe you can create work set in CTRL+H.

finding a function with particular name

How can i search for a function with particular name in my entire project.I dont even know if the function by that name exists.So i cant find references to that function by right clicking and then selecting the required option.
For example in eclipse we have one short curt ctr + shift +R to search for all classes with particular name.
Ctr + 0 to search for function in current class.I want to search in entire workspace
You can use the Java... option in the Search menu. The default options will search the entire workspace for all references and declarations of the search string. If you want to search only for declarations, there is a Limit To option.
Ctrl + H will give you the full text search of Eclipse.
In the tab Java Search you can specify to search for methods only (Limit to) .
At the bottom you can also specify the scope of your search, in your case that would be 'Workspace'.
If that does not suit your need type Ctrl + Shift + L twice, this opens the menu with the list of all Eclipse hotkeys.
There you can for example sort by category and browse all hotkeys in the search category. That will give you quite a good list of the possible search options you get withing eclipse.