Java Formatting
This page describes the options in both Options: Editor: Formatting and Project Properties: Formatting if you select the Java language. Options: Editor: Formatting sets global options
whereas Project Properties: Formatting sets project-specific options.
The Preview Window
The Preview window contains sample code that reflects changes you make in Formatting.
Categories
Tabs and Indents
- Use All Languages Settings: Unselect to override the All Languages settings. Unselecting Use All Languages Settings enables the following fields:
- Expand Tabs to Spaces. When selected, inserts spaces when the Tab key is typed.
When unselected, typing the Tab key inserts the tab character (\t) into the file if
possible. It also replaces preceding spaces with the tab character if possible.
The Source Editor calculates where to place tab characters based on the value
of the Tab Size property.
If Expand Tabs to Spaces is unselected and the Number of Spaces per Indent is different
than the Tab Size property, the indentation created by typing the Tab key is
made up of a combination of spaces and tab characters. It is easiest to predict
the location of tab characters if you set Number of Spaces per Indent to an even
multiple or divisor of Tab Size.
- Important: This feature does not convert
existing tabs to spaces. Only tabs that you add after you
enable this option are converted.
- Number of Spaces per Indent: Number of spaces per indentation level for subelements, new lines inside
brackets, etc.
- Tab Size: See the description of Expand Tabs to Spaces, above.
- Right Margin: Position of the vertical red line that indicates the right margin.
- Line Wrap: Whether lines are wrapped when they are longer than the width of the Editor window (no relationship to right margin). Options are:
- Off. No line wrapping (default).
- After words. Words are not broken by line wrapping.
- Anywhere. Lines are broken in the middle of words by line wrapping.
See also Wrapping.
- Continuation Indentation Size: If you place a line break in a code statement, this is how
far the IDE indents the continuation of the code statement after the line break.
- Label Indentation: Specified number adds extra indentation to the current label indentation level.
- Absolute Label Indentation: When selected, the IDE flushes labels completely to the left.
- Indent Top Level Class Members: When selected, the IDE adds indentation size of 4 to all class members (methods, fields, inner classes, initializers).
- Indent Case Statements in Switch: When selected, the IDE adds indentation size of 4 to 'case' statements in relation to 'switch' statement.
- You can experiment with different Tab and Indent settings and see the results in the Preview window.
Alignment
Align the selected elements when you place line breaks before them.
- New lines. The IDE breaks lines before any elements you select here.
- Multiline Alignment. When you place line breaks before any elements you select here,
the IDE aligns the selected elements.
- You can experiment with different Alignment settings and see the results in the Preview window.
Braces
- Braces Placement: Select where to place the braces for each type of declaration listed here. The possible brace locations are:
- Same line
- New line
- New line half indented
- New line indented
- Special "else if" Treatment: When selected, the "else if" is not separated into two lines and the code is kept together in one line.
- Braces Generation: Select where to generate the braces for each type of statement listed here. The possible brace locations are:
- Generate
- Leave Alone
- Eliminate
- You can experiment with different Braces settings and see the results in the Preview window.
Wrapping
In this panel set the rules for the IDE to wrap lines automatically. The panel lists the
possible locations before which the IDE wraps lines. For each location you can have the IDE never
wrap lines, always wrap lines, or wrap lines if the statement is long.
- You can experiment with different Wrapping settings and see the results in the Preview window.
- See also the Line Wrap option in Tabs and Indents.
Blank Lines
Improves readability by setting off sections of code that are logically related according to the specified options. Select the number of blank lines to place in the listed positions. For example, "After Field: 1" places 1 blank line after every field.
- You can experiment with different Blank Lines settings and see the results in the Preview window.
Spaces
In this panel, set where the IDE automatically puts whitespaces. Due to the large number
of possible places to put whitespaces, the places to put whitespaces are displayed in a tree
of categories.
Expand a tree node to see the places under a category, or
collapse a node to hide the places under a category. The categories are:
- Before Keywords (example: "while")
- Before Parentheses (example: "for (")
- Around Operators (example: binary operators)
- Before Left Braces (example: Class declarations, "class Example {")
- Within Parentheses (example: "if ( convert...")
- Other (example: After Commas)
- You can experiment with different Spaces settings and see the results in the Preview window.
Comments
Enable Comments Formatting: Unselect to disable comments formatting. Selecting Enable Comments Formatting enables the following fields:
- General. Selected options specify the style of implementing general code comments.
- Javadoc. Selected options specify the style of implementing comments for Javadoc.
- You can experiment with different Comments settings and see the results in the Preview window.
Imports
- Use Single Class Imports: Select to import only a particular class from a package during import optimization and code generation. Specify the following
import options:
- Import Inner Classes. When selected, the IDE creates imports for the inner classes referenced in your code.
- Class Count To Use Star Import. Number of classes to be imported from a single package until all statements importing a single class are substituted with a statement importing an entire package.
- Members Count To Use Static Star Import. Number of static import statements that are allowed for static members of the same type before type is used.
- Packages To Use Star Import. Specify a list of packages to be imported completely. Click Add to specify the package name or Remove to delete the currently selected entry from the list.
- Use Package Imports: Select to import packages during import optimization and code generation.
- Use Fully Qualified Names: Select to use the fully qualified name of the class during import optimization and code generation.
- Import Layout:
Specify how import statements should be organized in your code:
- Separate Static Imports. When selected, static imports are kept in a separate section. Click Add to add a package name to the list. Click Move Up and Move Down to position certain entries first, or last, or one after another in the list. Click Remove to delete the currently selected entry from the list.
- Separate Groups. When selected, imported classes are grouped as per their packages and sorted alphabetically within a package.
- You can experiment with different Imports settings and see the results in the Preview window.
Legal Notices