Controls the indentation settings.
Lets you change the general indentation settings.
Lets you choose the basic strategy how lines should be indented. Indentation is core to readability and describes the way white space is used to emphasis the logical structure of a program - logically subordinated elements are printed with increased indentation.
Jalopy supports several indentation strategies with different characteristics. You can even mix different strategies with different elements if you can't decide on one global policy.
Please note that adjusting the general indentation strategy will adjust all elements that currently use the same 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.
Standard indentation always tries to keep lines within the maximal line length.
Example 2.566. Method declaration
public void severalParameters(String one, int two, String three, StringObject four, AnotherObject five) { }
Example 2.567. Method call
vector.add(new AppServerReference( "RemoteApplicationManager", poa.create_reference_with_id( "RemoteApplicationManager".getBytes(), RemoteApplicationManagerHelper.id())));
Example 2.568. 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 previous hotspot would lead to a crossing of the maximal line length, the previous 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 many people prefer this strategy as is keeps related code more closely together. The downside is that indentation is not so uniformly distributed and more vertical space might be required.
Mixed endline indentation always tries to keep lines within the maximal line length.
Example 2.569. Method declaration
public void severalParameters(String one, int two, String three, StringObject four, AnotherObject five) { }
Example 2.570. Method call
vector.add(new AppServerReference( "RemoteApplicationManager", poa.create_reference_with_id( "RemoteApplicationManager" .getBytes(), RemoteApplicationManagerHelper .id())));
Example 2.571. 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 downside of consuming more vertical 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.
Please note that we recommend to avoid this strategy when possible, because depending on your wrapping settings it can produce quite scary results. It's only available for historic reasons in order to stay backwards compatible.
Example 2.572. Method declaration
public void severalParameters(String one, int two, String three, StringObject four, AnotherObject five) { }
Example 2.573. Method call
vector.add(new AppServerReference("RemoteApplicationManager", poa .create_reference_with_id("RemoteApplicationManager" .getBytes(), RemoteApplicationManagerHelper .id())));
Example 2.574. 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 intializer takes more than one line to print).
Example 2.575. Array initializer (Endline indented)
String[] s = { "first" }; |
|
String[] s = { |
"first", |
"second" |
}; |
Example 2.576. Array initializer (Standard indented)
String[] s = { "first" }; |
|
String[] s = |
{ |
"first", |
"second" |
}; |
Please note that if you need to enforce a line break before all array initializers, you need to disable the compact brace printing for array initializers. Please see "Compact array initializer" for more information.
Always increase indentation on hotspots
By default, Jalopy always increases indentation after certain code elements to emphasis 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 indentaton would be enough to indicate the basic logical structure of a code statement.
Since 1.7
Example 2.577. Always increase indentation on hotspots
Object value = calculateValue( 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.578. Only increase indentation when absolutely necessary
Object value = 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.
Lets you set different indentation sizes.
Original Tab indent
For documents that contain real tabs, specifies the number of spaces per tab stop.
Please note that it is very important to set the correct number here. Otherwise some indentations or alignments may fail!
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.
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.579. 2 space general indent
public class Preferences { ->private Preferences() ->{ ->} ->public static void main(String[] argv) { ->->com.triemax.jalopy.swing.PreferencesDialog.main(argv); ->} }
Example 2.580. 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.581. 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 Section 2.6.4.2.2, "Continuation" for information on how to enable continuation indentation.
Example 2.582. 2 space continuation indent
if ((condition1 && condition2)
->|| (condition3 && condition4)
->|| !(condition5 && condition6)) {
doSomethingAboutIt();
}
Example 2.583. 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.584. 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.
See "Cuddle empty braces" for more information about the empty braces handling.
Extends indent
If enabled, specifies the white space to print before the extends keyword in case it was printed on a new line.
Example 2.586. 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.587. 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.
Lets you control miscellaneous indentation settings.
Lets you control what elements should be visually aligned to each other.
Variable identifiers
If enabled, the identifiers of consecutive variable declarations are aligned. You can control what declarations are treated as consecutive with different chunk options. Refer to Section 2.6.5.2.2, "Chunks" for more information.
Example 2.589. Variable identifiers
String text = "text"; int a = -1; History.Entry entry = new History.Entry(text);
Example 2.590. Variable identifiers (aligned)
String text = "text"; int a = -1; History.Entry entry = new History.Entry(text);
Assignments
If enabled, consecutive assignment expressions and the assignment parts of consecutive variable declarations are aligned. You can control what statements are treated as consecutive with different chunk options. Refer to Section 2.6.5.2.2, "Chunks" for more information.
Example 2.591. Variable assignments (aligned)
String text = "text"; int a = -1; History.Entry entry = new History.Entry(text);
If both variable alignment options are enabled, you can achieve a style like the following:
Example 2.592. Variable identifiers/assignments (both aligned)
String text = "text"; int a = -1; History.Entry entry = new History.Entry(text);
Declaration parameters
If enabled, aligns the parameters of method/constructor declarations. This only applies if all parameters will be wrapped; either because wrapping is forced or the max. line length is reached. To force aligning, you have to enable the wrapping for method parameters. See "Wrap declaration parameters" for more information.
Example 2.593. Method declaration parameters
public static File create(final File file, File directory, int backupLevel) { ... }
Example 2.594. Method declaration parameters (aligned)
public static File create(final File file, File directory, int backupLevel) { ... }
Array initializers
Forces alignment of the curly braces of array initializers with the declaration. This only applies when using either the standard indentation policy or mixed endline indentation policy, because here by default the braces are indented according to the current indentation level and therefore do not align.
Since 1.0.3
Example 2.595. Array initialization (standard indented)
private static String [] sFields = { "LOCATION.ID", "TRACKING_EVENT.CREATE_TIME", "TRACKING_EVENT.EVENT_TIME", "TRACKING_EVENT.ORIGIN_TIME_ZONE_OFFSET", "TRACKING_EVENT.EVENT_TYPE", };
Example 2.596. Array initialization (standard indented, but aligned)
private static String [] sFields = { "LOCATION.ID", "TRACKING_EVENT.CREATE_TIME", "TRACKING_EVENT.EVENT_TIME", "TRACKING_EVENT.ORIGIN_TIME_ZONE_OFFSET", "TRACKING_EVENT.EVENT_TYPE", };
Enum constants
Lets you align the parameter lists of enum constants. Please note that aligning only takes place if "Wrap after enum constants" has been enabled as well.
Since 1.8
Example 2.597. Enum constants
public enum Code { NOT_READY((byte) 0x09), ERROR((byte) 0x10), ILLEGAL((byte) 0x11); }
Example 2.598. Aligned enum constants
public enum Code { NOT_READY((byte) 0x09), ERROR ((byte) 0x10), ILLEGAL ((byte) 0x11); }
Chained method calls
When disabled, indentation happens according to the current indentation level.
Example 2.599. Method call chain (standard indented)
Schluesselerzeugung.createService()
.getNeuerSchluesselService(
SchluesselService.SCHLUESSEL_KZ_INTERESSENT);
Otherwise indentation is performed relative to the column offset of the first chain link.
Example 2.600. Method call chain (aligned)
Schluesselerzeugung.createService()
.getNeuerSchluesselService(
SchluesselerzeugungService.SCHLUESSEL_KZ_INTERESSENT);
Please note that you can force line breaks for chained method call, see "Wrap chained method calls".
Nested chained method calls
When disabled, indentation happens according to the current indentation level.
Since 1.6
Example 2.601. Method call chain (standard indented)
id = RefData.getSegmentId(RefData.getAccessor().getCutOff(fileInfo
.getCutoffId())
.getTheoreticalDate(),
fileInfo.getExternalSenderId(),
_fileType,
fileInfo.getCustomerFormat()
.getId());
Otherwise indentation is performed relative to the column offset of the first chain link.
Example 2.602. Method call chain (aligned)
id = RefData.getSegmentId(RefData.getAccessor()
.getCutOff(fileInfo.getCutoffId())
.getTheoreticalDate(),
fileInfo.getExternalSenderId(),
_fileType,
fileInfo.getCustomerFormat()
.getId());
Please note that you can force line breaks for nested chained method calls, see "Wrap nested chained method calls".
Ternary expressions
If disabled, ternary expressions are printed according to the current indentation policy. See Section 2.6.4.1.1, "Strategies" for more information.
Example 2.603. Ternary operators (standard indented)
alpha = (aLongBooleanExpression) ? beta | : gamma; |
Example 2.604. Ternary operators (endline indented)
alpha = (aLongBooleanExpression) ? beta |
: gamma; |
If enabled, the second operator will always be aligned relative to the first one.
Note that this option only takes effect, if indeed a line break was inserted before the second expression. You can enforce such line breaks. See "Wrap ternary expression colon" for more information.
Assertion expressions
If enabled, the second expression of assertion statements is aligned.
Example 2.606. Assertion expression (standard indented)
assert ((nBits & ~ALL_BITS) != 0) : "Invalid modifier bits: " + (nBits & ~ALL_BITS);
Example 2.607. Assertion expression (endline indented)
assert ((nBits & ~ALL_BITS) != 0) : "Invalid modifier bits: " + (nBits & ~ALL_BITS);
Example 2.608. Assertion expression (aligned)
assert ((nBits & ~ALL_BITS) != 0) : "Invalid modifier bits: " + (nBits & ~ALL_BITS);
Anonymous inner classes
Lets you force alignment of anonymous inner brace blocks according to the current indentation level. Only applies when standard indentation is used.
Since 1.6
Example 2.609. Anonymous inner class (standard indented)
Action action = new AbstractAction("action") { public void actionPerformed (ActionEvent ev) { } };
Example 2.610. Anonymous inner class (standard indented but aligned)
Action action = new AbstractAction("action") { public void actionPerformed (ActionEvent ev) { } };
Right parenthesis
Forces alignment of wrapped right parentheses with the declaration or call. This only applies when using standard indentation policy, because here by default the parentheses are indented according to the current indentation level.
Example 2.611. Method call (standard indented, 2 spaces indent)
myMethod(
getSomeValue(
param1
),
param2
);
Example 2.612. Method call (standard indented, but aligned)
myMethod(
getSomeValue(
param1
),
param2
);
Example 2.613. Method declaration (standard indented)
public MyCustomStringTemplate createTemplate( Map three, int one, // xxx String two // xxx ) { ... }
Example 2.614. Method declaration (standard indented, but aligned)
public MyCustomStringTemplate createTemplate( Map three, int one, // xxx String two // xxx ) { ... }
Since 1.2.1
Lets you specify extra indentation for consecutive lines of certain elements.
Declaration parameters
With standard indentation enabled, this option causes an extra increase of the indentation level upon wrapping of method and constructor parameters. With endline indentation this option is meaningless.
Example 2.615. Wrapped method parameters
public void aMethod(int param 1, int param2, | int param3) { | int a = param1 + param2 + param3; | } |
Example 2.616. Wrapped method parameters with continuation indentation
public void aMethod(int param 1, int param2, | int param3) { | int a = param1 + param2 + param3; | } |
Blocks
The Sun brace style could make seeing the statement body difficult. To work around this problem, you may want to use continuation indentation in case you like this brace style. This setting applies for if, for, while and do-while blocks.
Example 2.617. Non-continuation indentation
if ((condition1 && condition2) || (condition3 && condition4) || !(condition5 && condition6)) { // BAD WRAPS doSomethingAboutIt(); // MAKE THIS LINE EASY TO MISS }
Example 2.618. Continuation indentation
if ((condition1 && condition2)
|| (condition3 && condition4)
|| !(condition5 && condition6)) {
doSomethingAboutIt();
}
Refer to Section 2.6.1.1, "Layout" for the available brace style options.
Operators
If enabled, indentation will be increased before an operand will be printed.
Example 2.619. Ternary expression (endline indented)
String comma = spaceAfterComma
--->? COMMA_SPACE
--->: COMMA;
return statements
Lets you increase the indentation level after return statements. This is only meaningful when a statement cannot be printed in one line.
Since 1.6
Example 2.620. return statement
return auswahlkriteriumComboBox.getUnselectedValueContent() |
.equals(auswahlkriteriumComboBox.getSelectedItem()); |
Example 2.621. return statement with continuation indentation
return auswahlkriteriumComboBox.getUnselectedValueContent() |
.equals(auswahlkriteriumComboBox.getSelectedItem()); |
As you can see from the above examples, without continuation indentation it might happen that wrapped lines are printed at the same indentation level as the return statement. It really depends where the line wrapping takes place. The two following examples indent both no matter what setting (though different, of course).
Indent class bodies
When enabled, indentation is increased for statements within class, interface, enum and annotation type declarations. Disabling this option might only make sense when using the GNU brace style.
Since 1.4
Example 2.624. Indented class body
public class Foo { --->public Foo() ---> { ---> } --->public boolean isFoo(Object other) ---> { ---> return other instanceof Foo; ---> } }
Example 2.625. Class body without increased indentation
public class Foo { public Foo() { } public boolean isFoo(Object other) { return other instanceof Foo; } }
Indent method bodies
When enabled, indentation is increased for statements within method and constructor bodies. Disabling this option might only make sense when using the GNU brace style.
Since 1.4
Example 2.626. Indented method body
public void toString() { --->return this.line + " " + this.column + " " + this.text; }
Example 2.627. Method body without increased indentation
public void toString() { return this.line + " " + this.column + " " + this.text; }
Indent "switch" bodies
The Sun Java code convention recommends a switch style where case statements are not indented relative to the switch statement as a whole. However, this option allows you to indent the case statements to make the entire switch statement stand out.
Example 2.628. Switch statement (unindented)
switch (prio) { case Priority.ERROR_INT : case Priority.FATAL_INT : color = Color.red; break; case Priority.WARN_INT : color = Color.blue; break; default: color = Color.black; break; }
Example 2.629. Switch statement (indented)
switch (prio) { --->case Priority.ERROR_INT : --->case Priority.FATAL_INT : ---> color = Color.red; ---> break; --->case Priority.WARN_INT : ---> color = Color.blue; ---> break; --->default: ---> color = Color.black; ---> break; }
Indent "case" bodies
When enabled, indentation is increased for statements within case statement bodies.
Since 1.4
Example 2.630. Indented case bodies
switch (prio) { case Priority.ERROR_INT : case Priority.FATAL_INT : --->color = Color.red; --->break; case Priority.WARN_INT : --->color = Color.blue; --->break; default: --->color = Color.black; --->break; }
Example 2.631. Case statements without increased indentation
switch (prio) { case Priority.ERROR_INT : case Priority.FATAL_INT : color = Color.red; break; case Priority.WARN_INT : color = Color.blue; break; default: color = Color.black; break; }
Indent block bodies
When enabled, indentation is increased for statements within blocks. Disabling this option might only make sense when using the GNU brace style.
Since 1.4
Example 2.633. Block without increased indentation
if (true) { doStuff(); assertStuffDoneCorrectly(); }
Indent labels
Specifies whether labels should be indented with the current indentation level.
Example 2.634. Unindented label
// advance to the first CLASS_DEF or INTERFACE_DEF LOOP: for (AST child = tree.getFirstChild(); child != null; child = child.getNextSibling()) { switch (child.getType()) { case JavaTokenTypes.CLASS_DEF : case JavaTokenTypes.INTERFACE_DEF : next = child; break LOOP; default : break; } }
Example 2.635. Indented label
--->--->// advance to the first CLASS_DEF or INTERFACE_DEF --->--->LOOP: for (AST child = tree.getFirstChild(); child != null; child = child.getNextSibling()) { switch (child.getType()) { case JavaTokenTypes.CLASS_DEF : case JavaTokenTypes.INTERFACE_DEF : next = child; break LOOP; default : break; } }
Indent first column comments
By default, all comments will be indented relative to their position in the code to avoid that comments break the logical structure of the program. But as for certain kind of comments it may be useful to put them at the first column, you can control here whether such comments should be printed without indentation.
Example 2.636. First column comment
public static Printer create(AST node) { /* if (node == null) { return new NullPrinter(); } */ return create(node.getType()); }
Example 2.637. Indented comment
public static Printer create(AST node) { /* if (node == null) { return new NullPrinter(); } */ return create(node.getType()); }
Indent ternary operands
When enabled, indentation is increased for the operands of the ternary operator. This option is only present for historic reasons - to be able to address some unwanted behavior without breaking backwards compatibility. It is recommended to have this option enabled.
Since 1.8
Lets you control the tab settings.
Use tabs to indent
Normally, Jalopy uses spaces to indent lines. If you prefer hard tabs, check this option.
Please note that it is very important that you specify the correct tab size for your original sources on the general indentation page.
You can change the original tab indent on the general indentation settings page, see the Original Tab indent option.
Example 2.640. Use tabs for indentation
» if ( true ) { » » methodCall(param1, » » » param2 » » » param3); » }
Use only leading tabs
When enabled, tabs are only used up to the current brace level, spaces are used afterwards.
Example 2.641. Leading indentation
» if (test()) {
» » methodCall(param1,
» » ····param2
» » ····param3);
» }
Use tabs in comments
When enabled, hard tabs are used for printing indentation in comments.
Since 1.2.1


