Code Templates Preferences

The Opens the Code Templates preference page Java > Code Style > Code Templates preference page lets you configure the format of newly generated code and comments.

Code and Comments

The code and comment page contains code templates that are used by actions that generate code. Templates contain variables that are substituted when the template is applied. Some variables are available in all templates, some are specific to templates.

Action

Description

Default

Edit...

Opens the Code Template dialog to edit the currently selected code template.

n/a

Import...

Imports code templates from the file system.

n/a

Export...

Exports all selected code templates to the file system.

n/a

Export All...

Exports all code templates to the file system.

n/a

Automatically add comments for new methods, types, modules, packages and files

If selected, newly generated methods, types, modules, packages and files are automatically generated with comments where appropriate. The formats of the generated comments are defined by the Comment Templates.

Off

Comment Templates

Comment templates can contain the variable ${tags} that will be substituted by the standard Javadoc tags (@param, @return..) for the commented element. The 'Overriding method' comment can additionally contain the template ${see_to_overridden}

Template Name

Specifies

Files

Header comment for new files.

Note that this template can be referenced in the 'New Java File' template with ${filecomment}.

Types

The comment for new types.

Note that this template can be referenced in the 'New Java File' template with ${typecomment}.

Fields

The comment for new fields.

Constructors

The comment for new constructors.

Methods

The comment for new methods that do not override a method in a base class and that do not delegate to any other method.

Overriding methods

The comment for new methods that override a method in a base class.

By default, this template is empty. You can add a real Javadoc comment if you want.

Delegating methods

The comment for new methods which delegate to existing methods.

Such methods can be created with the Source > Generate Delegate Methods... action.

Getters

The comment for getter methods.

Setters

The comment for setter methods.

Code Templates

Template Name

Description

New Java files

Used by the New Type wizards when a new Java file is created.

The template can specify where comments are added. Note that the template can contain the variable ${typecomment} and ${filecomment} that will be substituted by the evaluation of the Types respectively Files comment template.

Class body

Used by the New Class wizards when a new Java class is created.

Interface body

Used by the New Interface wizards when a new Java interface is created.

Enum body

Used by the New Enum wizards when a new Java enum is created.

Annotation body

Used by the New Annotation wizards when a new Java annotation is created.

Method body

The 'Method body' templates are used when new method with a body is created that still needs some code to complete its functionality.

It contains the variable ${body_statement} that resolves to a return statement or/and a super-call.

Constructor body

The 'Constructor body' templates are used when new method or constructor with body is created.

It contains the variable ${body_statement} that resolves a super call.

Getter body

The 'Getter body' templates are used when new getter method is created.

It contains the variable ${body_statement} that resolves to the appropriate return statement.

Setter body

The 'Setter body' templates are used when new setter method is created.

It contains the variable ${body_statement} that resolves to the appropriate assignment statement.

Catch block body

The 'Catch block body' template is used when a catch block body is created.

It can use the variables ${exception_type} and ${exception_var}.

Code Template dialog

The following fields and buttons appear in the dialog:

Action

Description

Description

A description of the template

Pattern

The template pattern.

Insert Variables...

Displays a list of pre-defined template specific variables.

Template variables

Source actions
Java editor
Java editor preferences
Templates preferences