- Opening the Source Editor
- Managing Automatic Insertion of Closing Characters
- Displaying Line Numbers
- Generating Code Snippets without Leaving the Keyboard
- Using Code Completion
- Inserting Snippets from Code Templates
- Using Editor Hints to Generate Missing Code
- Matching Other Words in a File
- Generating Methods to Implement and Override
- Generating JavaBeans Component Code
- Creating and Using Macros
- Creating and Customizing File Templates
- Handling Imports
- Displaying Javadoc Documentation While Editing
- Formatting Code
- Text Selection Shortcuts
- Navigating within the Current Java File
- Navigating from the Source Editor
- Searching and Replacing
- Deleting Code Safely
- Changing a Method's Signature
- Encapsulating a Field
- Moving a Class to a Different Package
- Moving Class Members to Other Classes
- Creating a Method from Existing Statements
- Creating an Interface from Existing Methods
- Extracting a Superclass to Consolidate Common Methods
- Changing References to Use a Supertype
- Unnesting Classes
- Tracking Notes to Yourself in Your Code
- Comparing Differences Between Two Files
- Splitting the Source Editor
- Maximizing Space for the Source Editor
- Changing Source Editor Keyboard Shortcuts
Creating and Customizing File Templates
You can customize the templates that you create files from in the IDE and create your own templates. This might be useful if you need to add standard elements in all of your files (such as copyright notices) or want to change the way other elements are generated.
You can also create your own templates and make them available in the New File wizard.
There are several macros available for use in templates to generate text dynamically in the created files. These macros are identifiable by the double underscores that appear both before and after the macro name. See Table 5-3 for a list of the macros available.
Table 5-3. Java File Template Macros
Macro |
Substituted Information |
__USER__ |
Your username. If you would like to change the value of __USER__, choose Tools | Options, click Advanced Options, and select the Editing | Java Sources node. Then click the button in the Strings Table property and change the value of USER. |
__DATE__ |
The date the new file is created. |
__TIME__ |
The time the new file is created. |
__NAME__ |
The name of the class (without the file extension). It is best not to use this macro for the class and constructor name in the file (instead, use the filename). |
__PACKAGE__ |
The name of the package where the class is created. |
__PACKAGE_SLASHES__ |
The name of the class' package with slash (/) delimiters instead of periods (.). |
__PACKAGE_AND_NAME__ |
The fully qualified name of the file (such as com.mydomain.mypackage.MyClass). |
__PACKAGE_AND_NAME_SLASHES__ |
The fully qualified name of the file with slash (/)delimiters instead of periods (.). |
__QUOTES__ |
A double quote mark ("). Use this macro if you want the substituted text to appear in quotes in the generated file. (If you place a macro within quote marks in the template, text is not substituted for the macro name in the created file.) |
To edit a template:
- Choose Tools | Template Manager.
- Expand the appropriate category node and select the template that you want to edit.
- Click Open in Editor.
- Edit the template and then save it.
To create a new file template based on another template:
- Choose Tools | Template Manager.
-
Navigate to and select the template on which you want to model the new template and click Duplicate.
A new node appears for the copied template. _1 is appended to the template's name.
- Click Open in Editor.
-
Edit the file, incorporating any of the template macros that you want to use (see Table 5-3), and save it.
If the template is for a Java class, you can use the filename for the class name and constructor name. These are automatically adjusted in the files you create from the template.
To import a file template:
- Choose Tools | Template Manager.
- Select the category folder for the template.
- Click Add to open the Add Template dialog box.
- Navigate to and select the file that you want to import as a template. Then click Add.