Skip to main content
  • Log in
  • Manage Cookies
Eclipse Foundation
Download
  • Projects
  • Working Groups
  • Members
  • Community
    • Marketplace
    • Events
    • Planet Eclipse
    • Newsletter
    • Videos
    • Blogs
  • Participate
    • Report a Bug
    • Forums
    • Mailing Lists
    • Wiki
    • IRC
    • Research
  • Eclipse IDE
    • Download
    • Learn More
    • Documentation
    • Getting Started / Support
    • How to Contribute
    • IDE and Tools
    • Newcomer Forum
  • More
      • Community

      • Marketplace
      • Events
      • Planet Eclipse
      • Newsletter
      • Videos
      • Blogs
      • Participate

      • Report a Bug
      • Forums
      • Mailing Lists
      • Wiki
      • IRC
      • Research
      • Eclipse IDE

      • Download
      • Learn More
      • Documentation
      • Getting Started / Support
      • How to Contribute
      • IDE and Tools
      • Newcomer Forum
  1. Home
  2. Blogs
  3. Wayne Beaton's blog
  4. More code templates in Eclipse

More code templates in Eclipse

Tuesday, February 28, 2006 - 08:57 by Wayne Beaton

How about this…

Start typing the name of a method (where a method should go). Don’t worry about the return type or anything else, just the name. Hit ctrl-space. Eclipse will offer to build a new private method with that name. Type “main” and hit ctrl-space and it will build you a new main method stub (complete with all the necessary parameters and return types).

Or… highlight a few lines of code in an existing method and hit ctrl-space. Down near the bottom of suggestions are a few interesting ones, including “do”, “for”, “if”, “runnable”, and others. Select one of these and it will wrap the selected code with a “do” loop, “for” loop, and so on. “Runnable is my favourite; it wraps the code in a new instance of java.lang.Runnable instance.

So…


private void whatDoYouGetWhenYouMultiplySixByNine() {
doSomething();
doSomethingElse();
}

becomes…


private void whatDoYouGetWhenYouMultiplySixByNine() {
new Runnable() {
public void run() {
doSomething();
doSomethingElse();
}
}
}

The best part is that if you look at how these templates are defined, it’s pretty easy to sort out how to define your own. More on that later…

Tags: 
Uncategorized
Source: 
https://waynebeaton.wordpress.com/2006/02/28/more-code-templates-in-eclipse/
  • Wayne Beaton's blog
  • Sign in to post comments.

Eclipse Foundation Blogs

  • Ian Skerrett (857 posts)
  • Wayne Beaton (796 posts)
  • Mike Milinkovich (286 posts)
  • Benjamin Cabé (131 posts)
  • Ivar Grimstad (97 posts)
  • Tanja Obradovic (38 posts)
  • Thabang Mashologu (31 posts)
  • Christopher Guindon (15 posts)
  • Roxanne Joncas (14 posts)
  • Paul Buck (11 posts)
  • Frédéric Desbiens (11 posts)
  • Mikaël Barbero (9 posts)
  • Jameka Woodberry (9 posts)
  • Hudson Kelly (8 posts)
  • Brian King (6 posts)
  • Denis Roy (5 posts)
  • Gabriela Motroc (4 posts)
  • Gael Blondelle (3 posts)
  • Shabnam Mayel (3 posts)
  • Paul White (1 posts)
  • Jacob Harris (1 posts)
  • Stephanie Swart (1 posts)
  • Michael Plagge (1 posts)
  • Sharon Corbett (1 posts)
  • Shanda Giacomoni (1 posts)

Recent blog posts

  • Member Case Study: itemis Builds Its Automotive Industry Business
  • Why I’m Running for the OSI Board of Directors
  • Welcome jadeva GmbH to the Jakarta EE Working Group!
  • Credentials leaked on GitHub
  • Hashtag Jakarta EE #61
  • Eclipse Cloud DevTools Community Update - February 2021
  • Hashtag Jakarta EE #60
  • The 2021 Eclipse Community Newsletter Calendar
  • Hashtag Jakarta EE #59
  • Jakarta EE Marketing and Branding Committee Levels-Up with New Members
More

Eclipse Foundation

  • About Us
  • Contact Us
  • Donate
  • Members
  • Governance
  • Code of Conduct
  • Logo and Artwork
  • Board of Directors

Legal

  • Privacy Policy
  • Terms of Use
  • Copyright Agent
  • Eclipse Public License
  • Legal Resources

Useful Links

  • Report a Bug
  • Documentation
  • How to Contribute
  • Mailing Lists
  • Forums
  • Marketplace

Other

  • IDE and Tools
  • Projects
  • Working Groups
  • Research@Eclipse
  • Report a Vulnerability
  • Service Status

Copyright © Eclipse Foundation. All Rights Reserved.

Back to the top