CS 214: Programming Languages
Spring 2009

Home|Syllabus|Schedule

Help: Changing a Code Template in Eclipse

Instructions

Context

Eclipse generates some code for you. You don't like some of this code, and you want to change it.

Changing

  1. Open Eclipse's preferences, Window -> Preferences.
  2. Navigate to Java -> Code Style -> Code Templates.
  3. Select Code -> Method body (or whatever template you want to change).
  4. Press Edit....
  5. Type in the code you'd rather have generated in the Pattern box.
  6. Press OK enough times to get back to Eclipse.

Example

My favorite code template to change is the default method body. Simply returning null makes debugging problems more difficult. I prefer to throw an exception that tells me I haven't implemented something I should have. I then feel like I don't need a TODO comment to remind me to change the code. When the exception is thrown, then I know the code needs to be changed.

So I change Code -> Method body to be

throw new IllegalStateException("unimplemented method!");