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.
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 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 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.
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.
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.
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); --->} }
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); -----> } ----->}
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" 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();
}
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 }
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.
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 { ... }
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 { ... }
Specifies the white space to print before the throws keyword in case it was printed on a new line.