Indentation

Controls the indentation settings. Indentation is core to readability and describes the way white space is used to emphasize the logical structure of a program—logically subordinated elements are printed with increased indentation.

General

Lets you change the general indentation settings.

Figure 2.41. Indentation settings page

Indentation settings page

Strategies

Lets you choose the general strategy how lines should be indented. Jalopy supports several indentation strategies with different characteristics. You can even use different strategies for different elements, if you can’t decide on one global policy.

Changing the general indentation strategy in the tree widget will adjust all subordinated elements that are configured to use the prior general indentation strategy as well.

Standard

With standard indentation, lines will be always indented according to the current indentation level. The indentation level changes as the block or parentheses level changes. Standard indentation gives you great consistency: Because indentation always uses the same sizes (multiples of the defined “Indent size”), source code is very uniformly layed out and the white space gaps tend to be small.

When standard indentation is enabled, line wrapping will always try to keep lines within the maximal line length.

Example 2.250. Method declaration

public void severalParameters(String one, int two,
    String three, StringObject four, AnotherObject five)
{
}

Example 2.251. Method call

vector.add(new AppServer(
        "RemoteApplicationManager",
        poa.create_reference_with_id(
            "RemoteApplicationManager".getBytes(),
            RemoteApplicationManager.id())));

Example 2.252. Assignment

doublette[PflegeController.GEBURTSDATUM] =
    resultSetRow[i].field[0].substring(0, 2) + "." +
    resultSetRow[i].field[0].substring(2, 4) + "." +
    resultSetRow[i].field[0].substring(4, 6);

Mixed Endline

Mixed endline indentation preferably lays out code relative to the most recent left parenthesis, assignment or curly brace offset (the hotspots). Whenever rigorously orienting on only the current hotspot would lead to a crossing of the maximal line length, the preceding hotspot is checked. This process is done recursively, therefore in rare cases, this strategy produces the exact same result as standard indentation. Mixed endline indentation uses bigger white space gaps than standard indentation as code tends to move towards the right edge—but this keeps related code more closely together. The downside is that indentation is not so uniformly distributed and more vertical space might be occupied.

When mixed endline indentation is enabled, line wrapping will always try to keep lines within the maximal line length.

Example 2.253. Method declaration

public void severalParameters(String one, int two,
                              String three,
                              StringObject four,
                              AnotherObject five)
{
}

Example 2.254. Method call

vector.add(new AppServer(
               "RemoteApplicationManager",
               poa.create_reference_with_id(
                   "RemoteApplicationManager"
                   .getBytes(),
                   RemoteApplicationManager
                   .id())));

Example 2.255. Assignment

doublette[PflegeController.GEBURTSDATUM] =
    resultSetRow[i].field[0].substring(0, 2) + "." +
    resultSetRow[i].field[0].substring(2, 4) + "." +
    resultSetRow[i].field[0].substring(4, 6);

Strict Endline

Strict endline indentation always lays out code relative to the most recent left parenthesis, assignment or curly brace offset (the hotspots). This way consecutive code sections are somewhat easier to recognize at the possible downside of consuming more vertical and/or horizontal space.

Strict endline indentation generally tries to keep lines within the maximal line length, but favors aligning over wrapping, and thus will often lead to code crossing the maximal line length.

Note

It is recommend to avoid this strategy when possible, because depending on your wrapping settings it can produce quite scary results. It’s mostly available for historic reasons in order to provide backwards compatibility and allow for a smooth transition phase

Example 2.256. Method declaration

public void severalParameters(String one, int two,
                              String three,
                              StringObject four,
                              AnotherObject five)
{
}

Example 2.257. Method call

vector.add(new AppServer("RemoteApplicationManager",
                         poa
                         .create_reference_with_id("RemoteApplicationManager"
                                                   .getBytes(),
                                                   RemoteApplicationManager
                                                   .id())));

Example 2.258. Assignment

doublette[PflegeController.GEBURTSDATUM] = resultSetRow[i]
                                           .field[0]
                                           .substring(0,
                                                      2) +
                                           "." +
                                           resultSetRow[i]
                                           .field[0]
                                           .substring(2,
                                                      4) +
                                           "." +
                                           resultSetRow[i]
                                           .field[0]
                                           .substring(4,
                                                      6);

Regarding array initializers, any of the endline indentation strategies will cause the initializer to be printed right after the assignment. But when enabled, standard indentation might cause the initializer to be printed on a line of its own (but only when the initializer takes more than one line to print).

Example 2.259. Array initializer (Endline indented)

String[] s = { "first" };   |
                            |
String[] s = {              |
                 "first",   |
                 "second"   |
             };             |

Example 2.260. Array initializer (Standard indented)

String[] s = { "first" };   |
                            |
String[] s =                |
    {                       |
        "first",            |
        "second"            |
    };                      |

If you want to enforce a line break before all array initializers, you need to disable the compact brace printing for array initializers. See the section called “Arrays” for more information.

Always increase indentation on hotspots

By default, Jalopy always increases indentation after certain code elements to emphasize scope and nesting level. Depending on your settings, hotspots might be left curly braces, left parentheses, operators and certain keywords like return and assert. Now, it can be that indentation is increased in a way that could be seen as superfluous, because already one level of indentation would be enough to indicate the basic logical structure of a code statement.

Example 2.261. Always increase indentation on hotspots

Object value class="bold">= calculateValueclass="bold">( getFirstNumber(),
»   »   getSecondNumber(), getThirdNumber() );


As you can see from the above example, if the option is enabled, indentation will be increased on every hotspot (here the assignment and left parentheses), which for deeply nested code can easily take up quite some horizontal space. The second increase does not add significant information. If you prefer a more dense layout, disabling the option will cause indentation to be increased only when really necessary. The result often takes considerably less horizontal space without loosing significant information.

Example 2.262. Only increase indentation when absolutely necessary

Object value class="bold">= calculateValue( getFirstNumber(),
»   getSecondNumber(), getThirdNumber() );


Here, the indentation is only increased once within the statement and thus upon wrapping the remaining call arguments are indented only one level.

Since 1.7

Sizes

Lets you set different indentation sizes.

Original Tab indent

For documents that contain real tabs, specifies the number of spaces per tab stop. Look in your IDE editor or formatting settings for the “Tab Size” or “Tab Width” option and set the Jalopy option to the value found there.

Important

Please be aware that it is essential to set the correct tab size. Otherwise some indentations or alignments may fail.

General indent

Specifies the number of spaces to use for general indentation (studies have found that 2 to 4 spaces for indentation is optimal).

Example 2.263. 2 space general indent

public class Preferences {
->private Preferences()
->{
->}

->public static void main(String[] argv) {
->->com.triemax.jalopy.swing.PreferencesDialog.main(argv);
->}
}

Example 2.264. 4 space general indent

public class Preferences {
--->private Preferences() {
--->}

--->public static void main(String[] argv) {
--->--->com.triemax.jalopy.swing.PreferencesDialog.main(argv);
--->}
}

Leading indent

Specifies the number of spaces to prepend before every line printed.

Example 2.265. 6 space leading indent

----->public class Preferences {
----->    private Preferences() {
----->    }

----->    public static void main(String[] argv) {
----->        com.triemax.jalopy.swing.PreferencesDialog.main(argv);
----->    }
----->}

Continuation indent

Specifies the number of spaces that should be inserted in front of continuation lines, i.e. the consecutive lines in case of a line wrap. Please note that this option only takes effect if continuation indentation is enabled. Refer to the section called “Continuation indent” for information on how to enable continuation indentation.

Example 2.266. 2 space continuation indent

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

Example 2.267. 4 space continuation indent

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

Comment indent

Specifies the number of spaces to insert between trailing comments and the preceding statement.

Example 2.268. 3 space trailing comment indent

new String[] {
    "Sunday",-->// Sunday
    "Monday",-->// Monday
    "Tuesday",-->// Tuesday
    "Wednesday",-->// Wednesday
    "Thursday",-->// Thursday
    "Friday",-->// Friday
    "Saturday"-->// Saturday
}

Cuddled braces indent

Specifies the number of spaces to print before the left curly brace of cuddled empty braces.

Example 2.269. 3 space cuddled braces indent

try {
    in.close();
} catch (IOException ignored)-->{}

See the section called “Cuddle braces” for more information about the empty braces handling.

Extends indent

When enabled, specifies the white space to print before the extends keyword in case it was printed on a new line.

Example 2.270. extends indentation with 6 spaces

public interface Channel
------>extends Puttable, Takable {
    ...
}

Implements indent

Specifies the white space to print before the implements keyword in case it was printed on a new line.

Example 2.271. implements indentation with 8 spaces

public class SynchronizedBoolean
------->implements Comparable, Cloneable {
    ...
}

Throws indent

Specifies the white space to print before the throws keyword in case it was printed on a new line.

Example 2.272. throws indentation with 3 spaces

private static final File getDestinationFile(File dest, String packageName,
                                             String filename)
-->throws IOException, FooException {
    ...
}