Ctrlflow Blog


Recent Posts

Why Traditional Eclipse Java Search Falls Short


The Eclipse Java Development Tools (JDT) are very good at answering one question: Where is something? Be it a type, method, or field, Eclipse’s built-in Java Search finds it.

However, Java developers often are interested in the answer to a different (and much harder) question: How can I accomplish something? Here, JDT’s traditional approach to search falls short; it presupposes that you know what you are looking for (a particular type, method, or field) and just want to get a list of all its occurrences in your code.

This is where Ctrlflow Code Search Professional comes in.

Eclipse JDT: Searching For Occurrences

Being able to find all references to, say, org.eclipse.swt.widgets.Display is of little help when to really want to know how to obtain an instance thereof. Should you call the constructor? Should you use a factory method? Is there a static INSTANCE field you should be aware of? To answer this question, Eclipse JDT makes you wade through dozens of places where Display occurs in the code, only a few of which actually being expressions obtaining the desired instance:

Search for occurrences of type Display

Ctrlflow Code Search Professional: Searching For Code Snippets

In contrast, Ctrlflow Code Search Professional can answer this question (and many others) directly:

Expression search for expressions evaluating to Display

You immediately see that you can obtain a Display using a simple getter if you have a Widget or IWorkbench in scope. Likewise, you learn about the three most common ways of obtaining the desired instance via static method calls: Display.getDefault(), Display.getCurrent(), and PlatformUI.getWorkbench().getDisplay(). The results are even ranked by their relative frequency, so you can tell which code snippet is the most likely solution.

How It Works

Like every search tool, Ctrlflow Code Search Professional maintains an index. But unlike traditional search tools, Ctrlflow Code Search Professional indexes not just simple strings or identifiers, but whole expressions like PlatformUI.getWorkbench().getDisplay(). Moreover, it also indexes partial expressions like the getDisplay() call highlighted in the above screenshot. In contrast, the indexing performed by JDT misses that call completely when finding references to Display, as the type is hidden within a longer call chain.

Ctrlflow Code Search Professional indexes all expressions found anywhere in your code with respect to multiple dimensions; the simple getDisplay() call above, e.g., will not only found when searching for Expressions evaluating to Display, but also when looking for Expressions starting from instance of IWorkbench:

Expression search for expressions starting from instance of IWorbench

This makes Ctrlflow Code Search Professional the perfect tool to explore APIs. Have a look at the user manual to learn more about the different queries available to search for code snippets and answer your “How” questions.

Ctrlflow Code Search Professional

Learn more about all features