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
- Open Eclipse's preferences, Window -> Preferences.
- Navigate to Java -> Code Style -> Code Templates.
- Select Code -> Method body (or whatever template you want to change).
- Press Edit....
- Type in the code you'd rather have generated in the Pattern box.
- 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!");