• Home
  • About

Eclipse Tips

Feeds:
Posts
Comments

Content assist and templates

November 29, 2007 by David

Let’s face it, we’d all like to do a little less typing and a little more sailing, wouldn’t we? Ctrl-space is the jack-of-all-trades keystroke that will have you typing less and hitting the water in no time. It goes by the intriguing name of “Content Assist” and I must admit that it’s a little hard to describe exactly what it does but basically, if you type it Eclipse will figure out depending on your context (i.e. where the cursor is) a whole bunch of useful ways to assist you by autogenerating code. One particularly interesting use of Content Assist is with templates. Simply type a keyword (that you can configure – more on that later), hit Ctrl-space, and a drop down of choices will appear. Where you see this icon template_obj.gif beside an option, it means that Eclipse can drop some template code into the editor. Here’s an example: let’s add a new unit test method. Open up a test class, find a blank line and type “Test” then Ctrl-space. If you’re using JUnit4, one of your choices will be “Test – test method (JUnit 4)”. Select it and Eclipse will generate a template for a JUnit 4 test method:

@Test
public void testname() throws Exception {

}

Nice! There are many other examples of Content Assist templates, all of which can be configured however you like in Window > Preferences > Java > Editor > Templates. You can add new ones as well.

Today’s tip:

Ctrl-space: Content Assist to select template code

Posted in editor | Tagged look ma no hands | No Comments Yet

  • Archives

    • June 2008
    • December 2007
    • November 2007
  • Category Cloud

    debug editor help navigation other plugins refactoring run search

Blog at WordPress.com.

Theme: Mistylook by Sadish.