#212 IndentationCheck: Configurable to align children with parent

Oliver Burn
Derek Richardson

I would like to be able to specify the additional indent
used when a statement is continued on a new line
(additional in comparison to the indent of the line that
began the statement). For example, instead of an
additional indent of 2 (my basic offset):

Object o
= new Object();

I would like a continued assignment line to have a
additional indent of 0 (next line begins at the same
column as the previous line):

Object o
= new Object();

And if it's deeper in the line:

aMap.put("SomeVeryLongKey", anotherVar = theValue);

could end up wrapped as:

= theValue);

I think I want to be able to configure that children have
same indentation as parent for any token type.

My goal is to enable Checkstyle to check the line
wrapping policy in The Elements of Java Style by
Vermeulen, Ambler, Bumgardner, Metz, Misfeldt, Shur,
and Thompson (ISBN 0-521-77768-2) (pages 8-10).
Here is a brief summary:

  1. If there are multiple statements on the line, put them
    on different lines. Stop here is the lines are now short
  2. If the line is long because of multiple complex
    expressions, use temporary variables to pre-compute
    sub-expressions. Stop here if the lines are now short
  3. "If the top-level expression on the line contains one
    or more commas...Then introduce a line break after each
    comma. Align each expression following a comma with
    the first character of the expression preceding the
  4. "If the top-level expression on the line contains no
    commas...Then introduce a line break just before the
    operator with the lowest precedence or, if more than
    one operator of equally low precedence exists, between
    each such operator..."
  5. Re-apply steps 3 and 4 until the line is short enough.


  • Logged In: YES

    Sorry, refreshed browser several hours later. D'oh!