Java Reference
In-Depth Information
Managing spacing
The
Spaces
tab gives you an abundance of options to specify how and when
spaces are used in your code. As you change your options, you can view the effects
of the change in the preview window. The options break into six categories:
Before Parentheses
controls spacing between methods, keywords, and
opening parentheses.
■
Around Operators
controls spacing around mathematical and boolean
symbols.
■
Before Left Brace
controls spacing around curly braces after keywords.
■
Within Parentheses
controls spacing inside parentheses.
■
In Ternary Operator
controls formatting of the ternary operator (
condi-
tion
?
true
:
false
).
■
Other
controls miscellaneous spacing options such as spacing around
punctuation, commas, and so forth.
■
12.2.5
Customizing import statements
The options in the
Imports
tab control how
IDEA
manages import statements.
IDEA
can automatically import classes and packages for you, and it can optimize
your import block based on the settings in this tab.
Optimizing imports
You can use the command
Tools | Optimize Imports
(
Ctrl+Alt+O
) to rearrange
your imports as specified in your layout settings. It also removes unused imports
and uses packages instead of single classes if specified in your options. You can
optimize imports from the
Project
view by right-clicking a file, a package, or
directory and selecting the
Optimize Imports
option from the context menu. If
you wish, you can optimize imports across your entire source tree.
The
Optimize Imports
command has been moved from the
To o l s
menu to the
Code
menu.
Configuring the basic import rules
When you reference a class outside the current package,
IDEA
can automatically
import the necessary class or package for you. The settings on the
Imports
tab of
the
Global Code Style
settings control exactly what is imported and how: