Eclipse code template for GWT jsni methods
GWT JavaScriptObject's and JavaScript Overlays are very cool. I've written about them before. It can get a bit tiresome to write jsni methods though, especially all those fiddly slashes, braces and asterisks at the end!
Here's a simple Eclipse code template that does the hard work for you, and lets you quickly tab-and-type through to completing your jsni method without ever having to type those fiddles again:
public final native ${return_type} ${newName}()/*-{
${cursor}
}-*/;
To add this in Eclipse:
- Open the preferences dialog (Window -> Preferences)
- Type "templates" into the filter box (it should have focus already so you can just start typing)
- Select the bold entry under "Java -> Editor -> Templates"
- In the right hand panel you'll see all the existing templates, and some buttons ... Click "New"
- The "name" is also the shortcut for your new template, so enter "jsni"
- Paste in the template text (copy from the code block above).
- Click ok to return to prefs, and ok again to return to the editor and try it out ...
To use your new template:
- Type "jsni" (without quotes) into a java editor and hit ctrl-space (or whatever your auto-complete shortcut is)
- The first option in the auto-complete suggestions should be your "jsni" template - hit return to use it
- Your template appears, and eclipse focuses the first part (the return type) for you to modify
- Modify each part of the template in turn and press tab to move to the next part
- Enjoy!
Recent releases of the Google Eclipse plugin include some nice jsni features that you definitely don't want to miss out on - including code-completion and syntax highlighting.
blog comments powered by Disqus