Wrapping

Controls when and how lines are wrapped.

General

Lets you control the general line wrapping options.

Figure 2.36. Wrapping settings page

Wrapping settings page
General

Lets you control the general line wrapping options.

Wrap lines

Enables or disables automatic line wrapping. When enabled, Jalopy tries to keep lines within the maximal line length and breaks statements across lines when necessary.

Please note that disabling line wrapping does not mean that existing line breaks will be kept, but rather that no efforts are taken to keep lines in between the maximal line length upon reformatting!

Line length

Lets you specify the maximal line length. Jalopy tries (more or less - depending on the used indentation scheme) to limit each line within the given length.

Policy

Lets you define the wrapping policy for operators.

Line wrapping will often occur with statements that consist of several (possibly long) expressions. Here you specify whether line wrapping should occur before or after the expression operator.

Wrap before operators

If enabled, line breaks will be inserted before operators.

Example 2.424. Wrap before operators (Standard indented)

if ((condition1 && condition2)
    || (condition3 && condition4)
    || !(condition5 && condition6)) {
    doSomethingAboutIt();
}
Wrap after operators

If enabled, line breaks will be inserted after operators.

Example 2.425. Wrap after operators (Standard indented)

if ((condition1 && condition2) ||
    (condition3 && condition4) ||
    !(condition5 && condition6)) {
    doSomethingAboutIt();
}

Please note that wrapping for the comma and dot operator is currently always performed after the operators!

If you happen to use Sun Brace styling, you might want to enable continuation indentation for blocks to let the statement body stand out. See "Block continuation indentation" for more information.

Keep line breaks

Lets you specify around which code elements line breaks should be kept.

Declaration parameters

When enabled, existing line breaks after the commas of declaration parameters are kept. Otherwise line wrapping is performed according to the current settings.

Since 1.6

Example 2.426. Nicely laid out method declaration

void test( String rName,
           boolean rPendandic ) {
    ...
}

After formatting this code could look like this (because everything fits in one line):

Example 2.427. Method call after formatting

void test( String rName, boolean rPendandic ) {
    ...
}

But with the "Keep line breaks" option enabled, it may look like this:

Example 2.428. Method declaration after formatting with kept line breaks (Endline indented)

void test( String rName,
           boolean rPendandic ) {
    ...
}
Call arguments

When enabled, existing line breaks after the commas of call arguments are kept. Otherwise line wrapping is performed according to the current settings.

Since 1.6

Example 2.429. Nicely laid out method call

obj.method1( test,
             test2,
             test3 );

After formatting this code could look like this (because everything fits in one line):

Example 2.430. Method call after formatting

obj.method1( test, test2, test3 );

But with the "Keep line breaks" option enabled, it may look like this:

Example 2.431. Method call after formatting with kept line breaks (Endline indented)

obj.method1( test,
             test2,
             test3 );
Operators

When enabled, existing line breaks before or after infix operators and the comma operator of method declaration parameters or method call arguments are kept. Otherwise line wrapping is performed according to the current settings.

Since 1.0

Example 2.432. Operators with forced line breaks

if ((condition1 && condition2)
    || (condition3 && condition4)
    || !(condition5 && condition6))
{
    ...
}

After formatting this code could look like this (because not everything fits in one line and not line breaks are forced):

Example 2.433. Operators after formatting (wrapping is done on-demand)

if ((condition1 && condition2) || (condition3 && condition4) ||
    !(condition5 && condition6))
{
    ...
}

But with the "Keep line breaks" option enabled, it may look like this:

Example 2.434. Operators after formatting with kept line breaks

if ((condition1 && condition2) ||
    (condition3 && condition4) ||
    !(condition5 && condition6))
{
    ...
}

Please note that it does not matter what wrapping policy for operators you choose. Jalopy will keep line breaks even if the operators move!

String concats

When enabled, existing line breaks before or after the plus operator of concatenated string literals are kept. Otherwise line wrapping is performed according to the current settings.

Since 1.0.1

Example 2.435. Nicely laid out string constant

query = "select a.prop_text, "
        + "       a.contest_title, "
        + "  from contest a "
        + "  where a.language_code = b.language_code "
        + "    and b.bob = c.bob "
        + "    and a.x = ? "
        + "  order by a.bob, "
        + "           c.language";

After formatting this code could look like this:

Example 2.436. String constant after formatting

query = "select a.prop_text, " + "       a.contest_title, " +
    "  from contest a "  + "  where a.language_code = b.language_code " +
    "    and b.bob = c.bob " + "    and a.x = ? " + "  order by a.bob, " +
    "           c.language";

But with the "Keep string concats" option enabled, it may look like this:

Example 2.437. String constant after formatting with "Keep line breaks" (Standard indented)

query = "select a.prop_text, " +
    "       a.contest_title, " +
    "  from contest a " +
    "  where a.language_code = b.language_code " +
    "    and b.bob = c.bob " +
    "    and a.x = ? " +
    "  order by a.bob, " +
    "           c.language";

Please note that it does not matter what wrapping policy for operators you choose. Jalopy will keep line breaks even if the operators move!

Array elements

When enabled, existing line breaks after the separator comma of array elements are kept. Otherwise line wrapping is performed according to the current settings.

Since 1.5

Example 2.438. Array declarations

String[] foo = new String[]
    {
        "foo",
    };

String[] bar = new String[]
    {
        "bar",
        "car",
    };

Example 2.439. Array declarations after reformat

String[] foo = new String[] { "foo", };

String[] bar = new String[] { "bar", "car", };

Example 2.440. Array declarations after reformat with "Keep line breaks"

String[] foo = new String[]
    {
        "foo",
    };

String[] bar = new String[]
    {
        "bar",
        "car",
    };
Strictly obey "Keep line breaks"

When using endline indentation, line breaks may not always be kept because doing so would break the endline indent contract and lead to inconsistent indentation behavior. Enabling this option will cause Jalopy to keep existing line breaks even in such cases.

Please note that this option is only available when endline indentation is enabled and any of the "Keep line breaks" options selected!

Since 1.8

Take the following example:

Example 2.441. Method call

String firstSymbol = eraseNonBreakingSpaceFromSymbol(
    symbol1, symbol2);

When the option is disabled, Jalopy won't keep the line break before the first call argument because it goes against the endline indentation rules.

Example 2.442. Method call - endline indented

String firstSymbol = eraseNonBreakingSpaceFromSymbol(symbol1,
                                                     symbol2);

But if you really favor keeping the line break, enabling the option would yield:

Example 2.443. Method call - line break kept

String firstSymbol = eraseNonBreakingSpaceFromSymbol(
        symbol1, symbol2);
Treat two string literals as string concatenation

This option lets you control what is considered a string concatenation. By default, Jalopy treats the plus (+) operator as a string concatenation when either one of the operands is a string literal. But you might want to narrow this behavior to only treat two string literals as a string concatenation.

Please note that this option is only available when any of the "Keep line breaks" options is selected!

Since 1.8

When this option is disabled, all operators in the example below would be considered string concatenations and therefore line breaks kept.

Example 2.444. String concatenations

String query = "select a.prop_text, "
               + "       a.contest_title, "
               + "  from contest a "
               + "  where a.language_code = b.language_code ";

String name = "Walther"
              + getNick();

When enabled, only those plus operators with two string literals on either side would retain any line breaks like in the example below.

Example 2.445. String concatenations

String query = "select a.prop_text, "
               + "       a.contest_title, "
               + "  from contest a "
               + "  where a.language_code = b.language_code ";

String name = "Walther" + getNick();
Miscellaneous
Disable wrapping for complex expressions

For complex expressions a common technique to enhance readability is to break the expression into several subexpressions that can be stored in temporary variables that are placed on different lines.

Example 2.446. Complex expression

if (conditionOne &&                                |
    ("foo".equals(aStr) || "bar".equals(aStr))     |
  doSomething();                                   |

Example 2.447. Refactored expression

boolean conditionTwo = "foo".equals(aStr);         |
boolean conditionThree = "bar".equals(aStr);       |
                                                   |
if (conditionOne &&                                |
    (conditionTwo || conditionThree))              |
  doSomething();                                   |

In order to determine occurences of complex expressions, enabling this option will cause automatic line wrapping to be disabled when a complex expression gets printed. A warning message will be logged in the Printer category that informs you about the location of the expression.

Since 1.5

Example 2.448. Flagged complex expression

                                                   |
if (conditionOne && (conditionTwo || conditionThree))
  doSomething();                                   |
Avoid bare left parenthesis

With Endline indentation and "Wrap on-demand after left parenthesis" or "Keep line break for operators" enabled, line breaks after left parentheses may look ugly. If this option is enabled, such line breaks are avoided.

This option was mainly introduced to fix some unwanted behavior of earlier releases without breaking compatiblity. It is recommended to have it enabled.

Since 1.4

Example 2.449. Bare left parenthesis

this.customerNumber = new CustomerNumber(
                                         ServiceManager.createService());

Example 2.450. Avoided bare left parenthesis

this.customerNumber = new CustomerNumber(ServiceManager.createService());