Java Reference
In-Depth Information
Placing elements on a new line
The
Place on New Line
group of options is used to specify how you'd like to for-
mat the
else
,
while
,
catch
, and
finally
keywords. Each of these keywords fol-
lows a companion block of code:
else
follows an
if
block,
while
follows a
do
block, and so forth. If selected, the keywords appear on a new line following the
previous block of code; otherwise, they appear on the same line as the preceding
closing brace.
The placement of bracing can now be further refined in the
Braces Placement
option group of the
Indent and Braces tab
. A new option for placement,
Next
line if wrapped
, specifies that the brace should be placed on the next line if text
wrapping was required. For example, if you selected this option for class declara-
tions, the opening brace appears on the same line as the declaration—unless the
declaration is so long that it wrapped across multiple lines, in which case the brace
is placed on its own line immediately following the declaration.
Managing the placement of braces
In the
Braces Placement
option group, you can specify where you would like the
opening brace to appear for class declarations, method declarations, and every-
thing else. There are four possible settings for managing the placement of braces,
and all options appear in the preview area of the tab:
End of line
—The opening brace is positioned at the end of the declara-
tion line.
■
Next line
—The opening brace is positioned at the beginning of the line
following the declaration.
■
Next line
shifted
—Same as
Next line
, but the brace is shifted in one
indentation level. The body of the block is at the same indentation level as
the brace.
■
Next line shifted2
—Same as
Next line
, but the body of the block is shifted
in an additional level of indentation.
■
Two additional options are related to brace placement. If you select the
Special
else if treatment
option, the
else
if
construct is treated almost like a single key-
word and always appears on the same line. If this option is deselected, the
if
appears indented under the
else
. The remaining option,
Indent case from
switch
, does exactly that. If it's selected,
case
statements and their
default
label