Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advanced Eclipse Java Search

There is a way to search for type or method declarations or references, using Search > Java in Eclipse. But, what about specifying some more advanced searching criteria, for example:

  • Find all references of class B within subclasses of class A.
  • Find all methods called insert*, within classes implementing interface I and/or within packages named com.foo.*.service.

I've been working on a very large codebase, and having these kinds of queries would help immensely. Browsing the Eclipse Marketplace, closest thing I could find is SEA-QL, but it does not even manage to create an index of all the projects in the workspace.

Any suggestions?

like image 256
javashlook Avatar asked Apr 23 '13 14:04

javashlook


People also ask

How do I search for a specific file in Eclipse Java?

If you want to search in files: Ctrl + H and then choose tab File Search . If you want to search for resources: Ctrl + Shift + R . If you want to search for Java types: Ctrl + Shift + T . If you want more shortcut keys: Ctrl + Shift + L .

How do I enable search in Eclipse?

The Eclipse search dialog box allows you to search for files that contain a literal or a character pattern in the entire workspace, a set of projects, a specific project or folders selects in the package explorer view. Clicking on the Search menu and selecting Search or File or Java. Clicking Ctrl + H.

How do I search for a package in Eclipse?

Ctrl+H opens the search dialog which you can use to search for packages. Show activity on this post. Click on the root package and start typing the name of the package you are looking for.

How do I search for multiple words in Eclipse?

Use the built-in Eclipse Search dialog. The Search menu contains multiple items (Search→ Search, Search→ File, Search→ Help, and Search→ Java), but all of them open the same dialog.


1 Answers

What you're asking for sounds wonderful to me - I don't know of any built in functionality that will easily give what you're asking for. Perhaps someone will suggest a plugin.

However, have you considered a combination of: - "Working Sets" - Regular Expressions - Saved searches

to help alleviate some pain?

A suggestion for your second example: Create a "working set" containing the com.foo.* packages Do a "File" (not Java) search with the Regular Expressions option checked, searching in files of type *.java, for something like:

implements.*I.*\R.*insert

You could make the regex more or less explicit depending on the method signature of the "insert" method.

Saving the searches would allow you to build up (and share) a library of frequently used expressions.

I hacked this example from another SO question and some blogs: Useful regex for Eclipse searching and Eclipse Regex find and replacing amongst others.

You'd also have the added benefit of brushing up on your Regex skills (something I know I need to do myself!)

Incidentally, what source control platform are you using? There are search tools (think Google) available that you can plug in to some source control systems. For example, I use this tool: SVN Query and I'm sure there are others. This also isn't a clean solution to what you're asking. Sorry I don't have a straight answer! Hope someone has a useful suggestion!

like image 100
GrahamMc Avatar answered Sep 28 '22 05:09

GrahamMc