Ctrlflow Blog

Categories


Recent Posts


First Steps with Code Search

CtrlflowCtrlflow

To get started with Ctrlflow Code Search Professional, you will need to create a search index. Once you start code search, Code Search will keep the index up-to-date, which allows it to find code snippets almost instantly.
The Start Code Search button needed to begin using Code Search
Like the Eclipse Java Development Tools, Code Search can search for occurrences of types, fields, and methods (only faster!), but its ability to find code snippets is what makes it most useful. The following three examples show you why:

1. How to Best Create Instances of API Classes?

If you are new to an API, one of the first questions is how to create instances of its key classes or interfaces. Even for a comparatively simple API like java.io this is not a trivial question. How to best create an InputStream, for example?

While Eclipse’s built-in search quickly turns up InputStream’s constructors (along with hundreds of irrelevant results), Ctrlflow Code Search Professional presents you with the whole picture: The constructors of FileInputStream and BufferedInputStream are a far more common way of creating an InputStream instance. Also, both Class.getResourceAsStream(…) and URL.openStream() are frequently used alternative routes, so those methods may be worth checking out as well.

Expression Search for Expressions Evaluating to InputStream

Tip: You can find all queries appropriate at the current cursor position in the Java editor’s Code Examples context menu.

2. What Arguments to Pass to API Methods?

One question that sooner or later surfaces when working with any larger API is what “magic” constants to pass as method arguments. Whether it is Java NIO’s OpenOption or SWT’s widget style bits, you are always wondering: “Which value(s) should I pass?”

Ctrlflow Code Search Professional helps to answer this question with its search for values already passed as arguments elsewhere in the code. This way, you can quickly judge which constants are used most often and thus warrant a closer look.

Expression Search for int arg1 of new TableViewer(Composite, int)

Tip: You can run queries appropriate at the current cursor position from the Show Code Examples quick menu (Ctrl+Alt+Shift+H/Cmd+Alt+Shift+H on macOS).

3. What Calls to Make in a Fluent API?

With the advent of Java 8, fluent interfaces and method chaining have finally made their way into the mainstream. Experienced users of the Eclipse IDE explore such APIs using content assist – one method at a time. But this piecemeal approach makes it hard to spot larger patterns. This is where Ctrlflow Code Search Professional and its flexible aggregation options come in: They condense large numbers of method chains into easily-digestable patterns.

Expression Search for Expressions Starting from Instance of Stream

Tip: If you are looking for the most frequent snippets, you sort either by number of Children or Results. But if you want to spot patterns in the snippets, try sorting by Name.

Ctrlflow Code Search Professional offers more than twenty different queries specialized for learning and exploring APIs. Consult the user manual for the full list.

Ctrlflow Code Search Professional

Learn more about all features