Dec 29, 2010

How do I get an instance of ... IStatuslineManager?

As of yesterday the Code Recommenders Demo Tour 2010 is over. This year I had the pleasure to talk at JAX, Andrena Developers Days, Eclipse Summit, FoSER, as well as on several (five or so?) Eclipse demo camps in Darmstadt, Bonn, Kassel, Dortmund and Karlsruhe. Further talks have be given by my colleague Martin at ECOOP and MSR. Quite a lot of events but is was fun and my pleasure to talk to all these audiences. Thanks for your interest in code recommenders and thank you to the organizers of these events. 2011 will be a great year: there are already a few talks scheduled for Java User Groups and others in January, February and March and I'm looking forward to these events. See you there in 2011!

However, aside traveling and talking about code recommenders we also worked on several new features - one of which I want to give a preview in this post. It's a feature I was looking for several years now and now it's there!

Whenever coding, how often did you spent hours on finding a path in the API jungle that returns you a highly required instance of a certain type? For Eclipse developers one such example might be

"How do I get an instance of an IStatusLineManager inside my Eclipse View?"

Personally, it took me more than half an hour to figure out how to obtain such an IStatusLineManager when doing it the first time. Most of the time I spent in manually traversing the Eclipse API jungle to find a method call chain that would return me an instance of the requested IStatusLineManager. The tough part in traversing the API call graph is that my base class ViewPart already provides more than 50 methods I might (!) call - not counting the methods I might invoke on all accessible fields and locals!

"Okay, but how hard can it be to scan 50 methods?" you say. Let's do some math. The call chain I was searching was three hops away. Each method gave me in average 20 more methods to invoke. Summing things up for a call chain of length 2 only, I already ended up in 50*20=1000 potential call chains to check! Make a guess how many call chains to check for a call chain of length 3... (granted, it is much more clever to check the Javadoc uses pages of each accessible type to reduce the search scope.)

The call chain I was looking for was this.getViewSite().getActionBars().getStatusLineManager(). Simple for the expert who knows the API. Challenging to figure out for a developer new to the framework.

I guess, you have been in many very similar situations, right? Haven't you ever thought "Damn, couldn't someone create a smart completion engine that does this **** tedious search for me?" Actually there are some guys who did. They created a fully automated call chain completion engine that searches the API jungle for all possible call chains that - starting from something that is available in your active working context - results in an instance of the requested type (like IStatusLineManager in the example above). This idea was developed by Naiyana Sahavechaphan, Kajal Claypool, and others in 2006 and their tool XSnippet was developed for Eclipse. Although an amazing idea and cited many times in academic world, the idea behind XSnippet never made it into Eclipse. But I can hear IntlliJ users yelling "Yeah, we have this features for years already!" ... right ... sad enough. Time to close that gap.

Java call chain completion is now available for Eclipse!

Whenever you tip ctrl+space twice now, you get this nice completion window which contains all call sequences that will result in an instance of the requested type on the left-hand-side of an assignment. Note that the exact behavior can (needs to) be configured in Eclipse Preferences as depicted below.

The call chain completion is currently under active development by Gary Fritz and Andreas Kaluza. Thanks to you both for your superb work! They made available a prototype implementation of their call chain completion engine. If you wanna check out the current prototype simply download it from, unzip it into your eclipse/dropins/ folder, restart Eclipse and configure code completion as shown above. There is also a short demo video showing code recommenders' call chain completion in action Please note that this is a sneak preview and as such we (Gary, Andreas, and me) appreciate all your comments, bug reports and feature requests! The final version will come along with the first incubator release of Eclipse Code Recommenders. To make this tool as helpful as possible, please comment on this idea and tool, tell your friends, and don't forget to send all bugs and feature requests to our issue tracker. Don't be quiet - let us know what you think about this idea. Your feedback motivates!
Is this all?
No, reimplementing XSnippet is just the beginning. Can you imagine what happens when developers start sharing usage statistics for such code snippets among each other - or even share their own code snippets in a central snippet repository? We could create tons of extremely valuable code snippets for our daily work and - in combination with smart completion engines that know what we need and how to leverage these knowledge base - provide you with code snippets you actually need for your task at hand! This is where we go! Stay tuned... we are working hard on this vision!

All the best,