Java Reference
In-Depth Information
12.2.3
Controlling indentation and braces
The
Indent and Braces
tab in the
Global Code Style
panel controls the basic lay-
out of your code structure by controlling the size of the indentation and the layout
of code blocks. Your tab and indentation settings can be different for different file
types if you desire.
Using tabs instead of spaces for indentation
You can use the
Ta b s i z e
option to specify the width of your tab characters. Nor-
mally, the editor uses space characters for indentation and formatting. When you
press the
Ta b
key, reformat your code, or indent a line, the editor inserts spaces to
apply the indentation. If you enable the
Use Tab Character
option, tab charac-
ters are used instead of spaces. The
Smart Tabs
option uses a combination of tabs
and spaces to achieve your desired formatting, because tabs alone are limited to
multiples of whatever tab size you've specified.
Controlling indent size
The
Indent
option specifies your desired width for one level of indentation. Each
additional level of indentation adds to this width. The
Continuation indent
option specifies the indentation level for statements that are split across two or
more lines of source code. This lets you format the lines after the first line differ-
ently to avoid confusing source code. The
Do not indent top level class members
option is for people who don't like the first tab in their source code. Otherwise
there is a tab indentation in front of members and methods. Activating this
option puts no space in front of class members.
Indenting multiline parameters
Sometimes you'll encounter a line of code that doesn't fit on the current line, but
long lines are undesirable in your coding standard. The code has to be split across
several lines. As you learned earlier, there is a code style setting for continuation
indentation; but this style can potentially be hard to read because clauses,
parameters, and other artifacts don't line up with one another on the screen.
Long lines split in this fashion are called
multiline
code, and
IDEA
provides a
series of settings that lets you specify which cases should be lined up for readabil-
ity and which cases should use normal continuation indentation. These settings
are found under the
Align when multiline
heading.