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 http://goo.gl/fMHfh, 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 http://goo.gl/aTgTX. 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!
All the best,
Marcel
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 http://goo.gl/fMHfh, 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 http://goo.gl/aTgTX. 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,
Marcel
Very handy indeed! However, using the "Use" link at the top of a type's Javadoc page shows a handy list of all methods that accept or return an instance of that type. That is, it shouldn't take a half hour to find in the worst case.
ReplyDeleteRight, with the Use link it boils down to 10 minutes at most :-) Anyway, the "cool part" will be the (crowd-sourced) code snippet repository with usage statistics. That's "XSnippet 2.0" :-)
ReplyDeleteWOW!!
ReplyDeleteThis is cool!
BTW, I've never used the "Use" link before... bwahaha, I'm too dumb ;) Macneil & Marcel, Thanks for the hints!
OMG!! ... This is JIT for me! Help for org.eclipse.* newbs is REALLY needed, even after reading the "Platform Plugin Developers Guide"!
ReplyDeleteUse is not that "usefull": Example:
ReplyDeleteUses of Class
org.eclipse.core.runtime.Platform
No usage of org.eclipse.core.runtime.Platform
Yeah. Right.
I think an update site for Code Recommenders would help in its adaption.
ReplyDelete