[Skip to content]

Changes

This document describes the changes in the Java formatter engine of Jalopy 1.1 that may have an impact on formatting style (depending on your code convention).

Spurious white space in inline tags

Spurious blank spaces were inserted before and after HTML tags for inline Javadoc tags

/**
 * Invokes {@link #get(Convention.Key, String) <tt>get(key,null)</tt>}
 */

was wrongly formatted as

/**
 * Invokes {@link #get(Convention.Key, String)  <tt> get(key,null) </tt>}
 */                                            ^    ^             ^

and after the 2nd run

/**
 * Invokes {@link #get(Convention.Key, String)   <tt>  get(key,null)  </tt>}
 */                                            ^^    ^^             ^^

Wrong indentation for comments before right curly brace

Comments before closing curly braces could lead to wrong indentation when using endline indent policy. Additionally multiple comments were not correctly lined up

try {
    int x = 1000;
//} catch (NullPointerException ex) {
//  ex.printStackTrace();
} catch (RuntimeException ex) {
    ;
}

was wrongly formatted as

try {
    int x = 1000;
//} catch (NullPointerException ex) {
    //  ex.printStackTrace();
    } catch (RuntimeException ex) {
    ;
}

Now it does (depending on the code convention)

try {
    int x = 1000;
    //} catch (NullPointerException ex) {
    //  ex.printStackTrace();
} catch (RuntimeException ex) {
    ;
}

No indentation for comments before right curly braces

Comments before closing curly braces were only indented according to the current indentation level when the column offset of the comment was greater than the column offset of the brace. Now such comments are always indented (the only exception being 1st column comments, these are always printed according to the associated convention setting)

    void method() {

  // intentionally left blank
    }

was formatted as

    void method() {

    // intentionally left blank
    }

Now it does (depending on the code convention)

    void method() {

        // intentionally left blank
    }

Wrong indentation for comments below multi-vars

Comments below multi-variables were wrongly indented when the endline indentation policy was used

int hhcGoalLow = 0, hhcGoalHigh = 0;

// Load values from front end
Map map = new HashMap();

was wrongly formatted as

int hhcGoalLow = 0, hhcGoalHigh = 0;

    // Load values from front end
Map map = new HashMap();

Now it does (depending on the code convention)

int hhcGoalLow = 0, hhcGoalHigh = 0;

// Load values from front end
Map map = new HashMap();

Wrong wrapping for creator calls

Creator calls that appeared after left parenthesis were not always correctly wrapped and could exceed the maximal line length

                                 |
System.out.println(new Runnable() {
    });                          |

Now it does (depending on the code convention)

                                 |
System.out.println(              |
    new Runnable() {             |
    });                          |

Several statements could exceed line length

if, while, switch and synchronized statements could lead to a crossing of the maximal line length when using Sun brace style

                                                  |
if (isFeatureSelected(data, Keys.IMPORT_SETTINGS)) {
}                                                 |

Was printed as

                                                  |
if (isFeatureSelected(data, Keys.IMPORT_SETTINGS)) {
}                                                 |

Now it does (depending on the code convention)

                                                  |
if (isFeatureSelected(data,                       |
        Keys.IMPORT_SETTINGS)) {                  |
}                                                 |

 

Method calls could exceed line length

Method calls used as last expression in if, while, switch and synchronized statements could lead to a crossing of the maximal line length. Naturally, this only happened when using C brace style or for statements without brace blocks

                                                |
if (isFeatureSelected(data, Keys.IMPORT_SETTINGS))
    takeAction();                               |
                                                |

Was printed as

                                                |
if (isFeatureSelected(data, Keys.IMPORT_SETTINGS))
    takeAction();                               |

Now it does (depending on the code convention)

                                                |
if (isFeatureSelected(data,                     |
        Keys.IMPORT_SETTINGS))                  |
    takeAction();                               |

Exceed line length after return

Expressions after a return statement could exceed the maximal line length. Depending on the settings,

                                                                       |
return (isInterface() ? "interface " : (isPrimitive() ? "" : "class ")) + getName();
                                                                       |

was formatted as

                                                                       |
return (isInterface() ? "interface " : (isPrimitive() ? "" : "class ")) +
    getName();                                                         |
                                                                       |

Now it does (depending on the code convention)

                                                                       |
return                                                                 |
    (isInterface() ? "interface " : (isPrimitive() ? "" : "class ")) + |
    getName();                                                         |
                                                                       |

Unnecessary wrapping for expressions

Expressions enclosed with parentheses lead to unncessary wrapping in some cases.

                                                                        |
if ((crNodeText == null) || (rNodeText.getData().trim().length() == 0)) |
    ;                                                                   |
                                                                        |
if ((ccrNodeText == null) || (rNodeText.getData().trim().length() == 0))|
    ;                                                                   |

Was wrongly printed as

                                                                        |
if ((crNodeText == null) ||                                             |
        (rNodeText.getData().trim().length() == 0))                     |
    ;                                                                   |
                                                                        |
if ((ccrNodeText == null) ||                                            |
        (rNodeText.getData().trim().length() == 0))                     |
    ;                                                                   |

Now it does (depending on the code convention)

                                                                        |
if ((crNodeText == null) || (rNodeText.getData().trim().length() == 0)) |
    ;                                                                   |
                                                                        |
if ((ccrNodeText == null) || (rNodeText.getData().trim().length() == 0))|
    ;                                                                   |

No wrapping at lower level

Chained method calls were not wrapped at a lower level (along the dots) after assignments and parentheses

                        |
longMethodName(one().two().three());
value = one().two().three();
                        |

Was printed as

                        |
longMethodName(         |
    one().two().three());
value =                 |
    one().two().three();|
                        |

even if "Always wrap when exceed left parenthesis" and/or "Always wrap when exceed after assignments" were disabled. Now it respects the settings and if they are disabled, it does

                        |
longMethodName(one()    |
    .two().three());    |
value = one().two()     |
    .three();           |
                        |

Failed assignment aligning

Assignment aligning could fail when an assignment expression span several lines.

ViewEvent event           = new ViewEvent(this, MEDEA_TOURENBERICHT,
        ViewEvent.SEARCH);
OrgeinheitVO gewaehlteOrg = getOrgAuswahl().getSelectedOrg();

was wrongly printed as

ViewEvent    event = new ViewEvent(this, MEDEA_TOURENBERICHT, ViewEvent.SEARCH);
OrgeinheitVO gewaehlteOrg = getOrgAuswahl().getSelectedOrg();

Now it does (depending on the code convention)

ViewEvent event           = new ViewEvent(this, MEDEA_TOURENBERICHT,
        ViewEvent.SEARCH);
OrgeinheitVO gewaehlteOrg = getOrgAuswahl().getSelectedOrg();

Wrong blank lines after package

Formatting interfaces could lead to unexpected results when no import declarations were contained: the setting for blank lines after the package statement was ignored, and always one blank line printed between package and interface declaration statement.

package org.jboss.nukes.addons.modules.news.model;


public interface Story {
}

Was wrongly printed

package org.jboss.nukes.addons.modules.news.model;

public interface Story {
}

Now it does (depending on the code convention)

package org.jboss.nukes.addons.modules.news.model;


public interface Story {
}

Wrong formatting of Javadoc comments

Javadoc comments that only contained a single @todo tag (i.e. no description section) were wrongly printed when the comment appeared before a valid code element

/**
 * @todo  move into separate helper class because similar code is used in
 *        Foo.java
 */
int querySettings() {
}

was wrongly printed as

/** * @todo  move into separate helper class because similar code is used in
 *           Foo.java
 */
int querySettings() {
}

Now it does (depending on the code convention)

/**
 * @todo  move into separate helper class because similar code is used in
 *        InstallHandler.java
 */
int querySettings() {}

Wrong white space within ctor calls

With "Spaces within method calls" enabled, spaces were wrongly printed within constructor calls (this() and super()).

ActiveTestSuite.super( test, result );

was wrongly printed as

ActiveTestSuite.super(  test, result );
                      ^^

Now it does (depending on the code convention)

ActiveTestSuite.super( test, result );

Trailing whitespace upon wrapping

With both "Spaces within method calls" and "Wrap always when exceed after left parenthesis" enabled, a trailing blank space was printed after the left parenthesis upon wrapping

super"The specified assembly is not the event's main"" inventory or its sub-assemly.");¶

was wrongly printed as

super( ¶
   "The specified assembly is not the event's main"" inventory or its sub-assemly.");¶

Now it does (depending on the code convention)

super"The specified assembly is not the event's main"" inventory or its sub-assemly.");¶

Wrong transformation of Javadoc comments

With the "Check HTML tags" option enabled, Javadoc comments that appeared at invalid positions (not before package, class, interface, constructor, method and field declarations) were incorrectly modified

public void foo() {

     /**
      * multi line comment test 2
      * multi line comment test 2
      */

}

was wrongly printed as

public void foo() {

     /**
        multi line comment test 2
        multi line comment test 2

      */

}

Now it does (depending on the code convention)

public void foo() {

     /**
      * multi line comment test 2
      * multi line comment test 2
      */

}

Missing line break for <th>

No line break was printed before <th> tags

/**
 * <table>
 * <tr>
 * <th>Name</th>
 * </tr>
 *
 * <tr>
 * <td>John Doo</td>
 * </tr>
 * </table>
 */

Was wrongly printed as

/**
 * <table>
 *   <tr><th>Name</th>
 *   </tr>
 *
 *   <tr>
 *     <td>John Doo</td>
 *   </tr>
 * </table>
 */

Now it does (depending on your settings)

/**
 * <table>
 *   <tr>
 *     <th>Name</th>
 *   </tr>
 *
 *   <tr>
 *     <td>John Doo</td>
 *   </tr>
 * </table>
 */

What is Jalopy?

Jalopy is a world-class source code formatter for Java. It automates and enforces all aspects of source code layout—to meet a certain coding style without putting any burden on individual developers.

Learn more

Who needs it?

Jalopy is for everyone involved with source code editing. It scales from single developer usage to large scale enterprise deployment and seamlessly integrates with your favorite Java IDE or build tool.

Go and see yourself

I want some!

Concentrate on your problem domain and don’t waste time shuffling characters around. Pricing starts at USD $40 for a single-user license. Buy now using secure online purchase or wire transfer.

What are you waiting for?

Learn the details

Deploy, configure and use the software to best meet your needs. Download the printable user’s guide and learn everything there is to know to put Jalopy’s capabilities to full use.

Download (.pdf - 8.3MB)