OverviewDownloadDocumentationPlug-insLinksContact
Features | History | Manual | FAQ | Javadoc
This page generated: December 10 2003

4.3.4. Wrapping

Controls when and how lines gets wrapped.

4.3.4.1. General

Lets you control the general line wrapping options.

4.3.4.1.1. General

Lets you control the general line wrapping options.

  • Wrap lines

    Enables or disables the automatic line wrapping.

  • Line length

    Lets you specify the maximum line length. Jalopy tries (more or less) to limit each line within the given length.

  • Deep indent

    Specifies the length after which a gap will be identified as "deep indented". Jalopy tries to avoid these kind of gaps and will force a line break or apply another indentation scheme, if this size is exceeded.

    Example 4.65. Deep indent size (60) not exceeded

                                                                |                  |
        protected static synchronized File getANewDestinationFile(File dest,       |
                                                                | String packageName,
                                                                | String filename) |
    |----------------- the gap ---------------------------|throws IOException      |
        {                                                       |                  |
        }                                                       |                  |
                                                                |                  |
                                                                60                 79
    

    Example 4.66. Deep indent size (50) exeeded

                                                      |                            |
        protected static synchronized File getANewDestinationFile(File dest,       |
                                                      |           String packageName,
                                                      |           String filename) |
    |----------------- the gap ---------------------------|throws IOException      |
        {                                             |                            |
        }                                             |                            |
                                                      |                            |
                                                      50                           79
    
4.3.4.1.2. Policy

Lets you fine-control the wrapping behaviour.

  • Wrap after left parenthesis

    Lets you control the wrapping behaviour for statement and expression lists.

    If left disabled, the first line break will be preferably inserted behind the first parameter or expression and only occurs after the left parenthesis if the maximum line length would be exceeded.

    Example 4.67. Wrap after left parenthesis (disabled)

                                                                                   |
    appServerReferencesVector.add(new AppServerReference(
            "RemoteApplicationManager",                                            |
            poa.create_reference_with_id(         |
                "RemoteApplicationManager".getBytes(),                             |
                RemoteApplicationManagerHelper.id())));                            |
                                                                                   |
    

    Otherwise the line break will always occur behind the left parenthesis.

    Example 4.68. Wrap after left parenthesis (enabled)

    appServerReferencesVector.add(
        new AppServerReference(
            "RemoteApplicationManager",
            poa.create_reference_with_id(
                "RemoteApplicationManager".getBytes(),
                RemoteApplicationManagerHelper.id())));
    

    This switch affects the output style of method/constructor declarations and calls, creator statements and if-else, for, while and do-while blocks.

    As per default, the wrapped lines will be indended using Standard indentation, but you may want to apply another indentation scheme. See Section 4.3.3.1.1, “Policy” for more information.

  • Wrap before right parenthesis

    Forces a line break before the right parenthesis of parameter or expression lists. The parenthesis will be intended according to the current indentation level. Only takes action if at least one parameter/expression was indeed wrapped.

    This switch affects the output style of method/constructor declarations and calls, creator statements and if-else, for, while and do-while blocks.

    Example 4.69. Right parenthesis (disabled)

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

    Example 4.70. Right parenthesis (enabled)

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

    Both switches combined, looks like the following example:

    Example 4.71. Left and right parenthesis

    appServerReferencesVector.add(
        new AppServerReference(
            "RemoteApplicationManager",
            poa.create_reference_with_id(
                "RemoteApplicationManager".getBytes(),
                RemoteApplicationManagerHelper.id()
            )
        )
    );
    

    For blocks the output may go like this:

    Example 4.72. Left and right parenthesis (wrapped)

    if (
        "pick".equals(m.getName()) && m.isStatic() && m.isPublic()
    ) {
        pickFound = true;
    }
    else if (
        "pick".equals(m.getName()) && m.isStatic() && m.isPublic()
    ) {
        pickFound = true;
    }
    

  • Wrap grouping parentheses

    Lets you control the wrapping behaviour for grouping parentheses. If enabled, linebreaks are inserted after left and before right parentheses of grouped expressions to let the expression(s) stand out.

    Example 4.73. Grouping parentheses (standard indented)

    if (
        !((bankverbindung instanceof ObjectValue)
        || (bankverbindung instanceof PrimitiveValue))
    ) {
        throw new RuntimeException();
    }
    

    Example 4.74. Wrapped grouping parentheses (standard indented)

    if (
        !(
            (bankverbindung instanceof ObjectValue)
            || (bankverbindung instanceof TkPrimitiveValue)
        )
    ) {
        throw new RuntimeException();
    }
    

  • Wrap after assignments

    Lets you control the way wrapping takes action for assignments. If left disabled, line wrapping preferably occurs as part of the expression printing. Otherwise wrapping will be performed right after the assignment.

    Example 4.75. Don't wrap after assignment

    this.interessentenNr = new InteressentenNr(
            Fachschluesselerzeugung.createService()
            .getNeuerFachschluessel(
                FachschluesselerzeugungService.FACHSCHLUESSEL_KZ_INTERESSENT
            )
        );
    

    Example 4.76. Wrap after assignment

    this.interessentenNr =
        new InteressentenNr(
            Fachschluesselerzeugung.createService()
            .getNeuerFachschluessel(
                FachschluesselerzeugungService.FACHSCHLUESSEL_KZ_INTERESSENT
            )
        );
    

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, lines will be wrapped before the operator. The operator will be printed with the continuation line.

    Example 4.77. Wrap before operators

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

  • Wrap after operators

    If enabled, lines will be wrapped after the operator.

    Example 4.78. Wrap after operators

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

    If you happen to use Sun Brace styling, you might want to enable continuation indentation to let the statement body stand out.

4.3.4.2. Always

Lets you choose the statements/expressions that are to be wrapped always.

4.3.4.2.1. Wrap always

For certain cases, the need may arise to force line wrapping to achieve a consistent, uniform look. If you enable any of the following switches, line wrapping will occur for the specified cases no matter whether you have enabled general line wrapping or not.

  • Before extends keyword

    Forces a line break before the extends keyword of a class/interface declaration.

    Example 4.79. Class/Interface extends keyword

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

    Example 4.80. Class/Interface extends keyword (wrapped)

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

    You can control the space printed before the keyword with the Extends Indent setting. If you leave the switch disabled, the clause will be printed with standard indentation.

  • After extends types

    Forces a line wrap after each type name of the extended classes.

    Example 4.81. Class/Interface extends types

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

    Example 4.82. Class/Interface extends types (wrapped)

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

  • Before implements keyword

    Forces a line break before the implements keyword of a class declaration.

    Example 4.83. implements keyword

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

    Example 4.84. implements keyword (wrapped)

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

    You can control the space printed before the keyword with the Implements Indent setting. If you leave the switch disabled, the clause will be printed with standard indentation.

  • After implements types

    Forces a line wrap after each type name of the implemented classes.

    Example 4.85. Class implements types

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

    Example 4.86. Class implements types (wrapped)

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

  • Before throws keyword

    Forces a line break before the throws keyword of a method/constructor declaration.

    Example 4.87. throws keyword

    private File getDestinationFile(File dest, String packageName,
                                    String filename) throws IOException
    {
        ...
    }
    

    Example 4.88. throws keyword (wrapped)

    private File getDestinationFile(File dest, String packageName,
                                    String filename)
                             throws IOException
    {
        ...
    }
    

    You can control the space printed before the keyword with the Throws Indent setting. If you leave the switch disabled, Jalopy tries to align the throws clause with the method/constructor parameters as with the above example. If no alignment is possible, the clause will be printed with standard indentation.

  • After throws types

    Forces a line wrap after each type name of the throws clause of a method/constructor declaration.

    Example 4.89. throws types

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

    Example 4.90. throws types (wrapped)

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

    Example 4.91. throws types (standard indented)

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

  • Method Def parameters

    Forces a line wrap after each parameter of a method or constructor declaration.

    Example 4.92. Method declaration parameters

    public static File create(File file, File directory, int backupLevel)
                       throws IOException
    {
        ...
    }
    

    Example 4.93. Method declaration parameters (wrapped)

    public static File create(File file,
                              File directory,
                              int backupLevel)
                       throws IOException
    {
        ...
    }
    
  • Method Call chains

    Forces a line wrap after each chained method call.

    Example 4.94. Chained Method Call

    message.format(ERROR_SOURCE_ADDRESS).param (m_session.getAimName()).send();
    

    Example 4.95. Chained Method Call (wrapped)

    message.format(ERROR_SOURCE_ADDRESS)
           .param (m_session.getAimName())
           .send();
    

  • Method Call parameters

    Forces a line wrap after each parameter of a method call.

    Example 4.96. Method call

    doSomething();
    _userDatabase.addUser("Name", encryptPassword("password", _secretKey),
                          "123 fake address");
    doSomethingElse();
    

    Example 4.97. Method call (wrapped)

    doSomething();
    _userDatabase.addUser("Name",
                          encryptPassword("password",
                                          _secretKey),
                          "123 fake address");
    doSomethingElse();
    

  • Method Call parameters if nested

    Forces a line wrap after each parameter of a method call if at least one parameter is a method call itself. This option can prove especially useful if one prefers to nest method calls as parameters rather than adding local variables just to hold those parameters.

    Example 4.98. Method call if nested (wrapped)

    doSomething();
    _userDatabase.addUser("Name",
                          encryptPassword("password", _secretKey),
                          "123 fake address");
    doSomethingElse();
    

  • Ternary expression question mark (?)

    Forces a line wrap after the first operand.

    Example 4.99. Ternary expression question mark (deep indented)

    String comma = spaceAfterComma
                   ? COMMA_SPACE : COMMA;
    

    Indentation for consecutive lines depends on the used indenatation policy. You may further want to use continuation indentation.

  • Ternary expression colon (:)

    Forces a line wrap after the second operand.

    Example 4.100. Ternary expression colon

    String comma = spaceAfterComma ? COMMA_SPACE
                                   : COMMA;
    

    If both switches are disabled, ternary expressions are printed in one line (if everything fits in one line, that is).

    Example 4.101. Ternary expressions

    String comma = spaceAfterComma ? COMMA_SPACE : COMMA;
    

    If both switches are enabled, you can force a style like the following:

    Example 4.102. Ternary expressions (continued)

    String comma = spaceAfterComma
        ? COMMA_SPACE
        : COMMA;
    

  • Labels

    Forces a line wrap after labels.

    Example 4.103. 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 4.104. Label (wrapped)

    // 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;
                }
            }
    

4.3.4.2.2. Wrap always when exceed

Lets you force wrapping for all parameter or expressions if the parameter or expression list would otherwise exceed the maximal line length. If you enable any of the following switches, line wrapping may occur for the specified cases no matter whether you have enabled general line wrapping or not.

  • After extends types

    Forces a line wrap after each type name of the extends clause of a class/interface declaration if the whole clause does not fit in one line.

    Example 4.105. Extends types wrapped as needed (standard indented)

    public interface VeryImportantInterface                        |
        extends LeastImportantInterface, LessImportantInterface,   |
            ImportantInterface                                     |
    }                                                              |
        ...                                                        |
    }                                                              |
    

    Example 4.106. Extends types wrapping forced (standard indented)

    public interface VeryImportantInterface                        |
        extends LeastImportantInterface,                           |
            LessImportantInterface,                                |
            ImportantInterface                                     |
    }                                                              |
        ...                                                        |
    }                                                              |
    
  • After implements types

    Forces a line wrap after each type name of the implements clause of a class/interface declaration if the whole clause does not fit in one line.

    Example 4.107. Implements types wrapped as needed (standard indented)

    public class ImportantClass                                    |
        implements ImportantInterface, Serializable, Comparable,   |
            Cloneable                                              |
    }                                                              |
        ...                                                        |
    }                                                              |
    

    Example 4.108. Implements types wrapping forced (standard indented)

    public class ImportantClass                                    |
        implements ImportantInterface,                             |
            Serializable,                                          |
            Comparable,                                            |
            Cloneable                                              |
    }                                                              |
        ...                                                        |
    }                                                              |
    
  • After throws types

    Forces a line wrap after each type name of the throws clause of a method/constructor declaration if the whole clause does not fit in one line.

    Example 4.109. Throws types wrapped as needed (deep indented)

    private File getDestinationFile(File dest, String packageName, |
                                    String filename)               |
                             throws IOException, FooException,     |
                                    FooBarException                |
    {                                                              |
        ...                                                        |
    }                                                              |
    

    Example 4.110. Throws types wrapping forced (deep indented)

    private File getDestinationFile(File dest, String packageName, |
                                    String filename)               |
                             throws IOException,                   |
                                    FooException,                  |
                                    FooBarException                |
    {                                                              |
        ...                                                        |
    }                                                              |
    
  • After parameters/expressions

    If enabled, this switch will cause all parameters/expressions to be wrapped, if and only if the first parameter/expression of the list has been wrapped.

    Example 4.111. Expression list (all wrapped)

    if (
        "pick".equals(m.getName()) &&
        m.isStatic() &&
        m.isPublic()
    ) {
        pickFound = true;
    }
    else if (
        "pick".equals(m.getName()) &&
        m.isStatic() &&
        m.isPublic()
    ) {
        pickFound = true;
    }
    

4.3.4.3. Misc

Lets you control miscellaneous wrapping settings.

4.3.4.3.1. Arrays

Contains options to control the wrapping for arrays.

  • Wrap as needed

    Enabling this options means array elements will be wrapped so that they will be limited within the current line length setting.

    Example 4.112. Wrap as needed

    String[] constraints = {                                               |
        "patternPanel.top=form.top", "patternPanel.hcenter=form.hcenter",  |
        "okButton.top=patternPanel.bottom+20",                             |
        "okButton.right=form.hcenter-10", "cancelButton.vcenter=10",       |
        "cancelButton.left=10"                                             |
    };                                                                     |
    

  • Wrap after element

    Forces a newline after every n-th element.

    Example 4.113. Wrap after element 1

    String[] constraints = {                                               |
        "patternPanel.top=form.top",                                       |
        "patternPanel.hcenter=form.hcenter",                               |
        "okButton.top=patternPanel.bottom+20",                             |
        "okButton.right=form.hcenter-10",                                  |
        "cancelButton.vcenter=10",                                         |
        "cancelButton.left=10"                                             |
    };                                                                     |
    

    Example 4.114. Wrap after element 2

    String[] constraints = {                                               |
        "patternPanel.top=form.top", "patternPanel.hcenter=form.hcenter",
        "okButton.top=patternPanel.bottom+20", "okButton.right=form.hcenter-10",
        "cancelButton.vcenter=10", "cancelButton.left=10"                  |
    };                                                                     |
    

    If both options are left disabled, the array elements will be printed in one line, right after the left curly brace.

to top