Separation

Lets you control the insertion of blank lines to separate statements or declarations with different functions or meanings. Just as related statements should be grouped together, unrelated statements should be separated from each other. In English, the start of a new paragraph is identified with indentation or a blank line. This greatly aids reading ease and helps to improve comprehension and reading speed. When coding, you should strive for a similar goal and always give the reader hints as to how the program is organized.

With Jalopy you are able to enforce consistent blank lines behavior and divide groups of related statements into paragraphs, separate routines from one another and highlight comments. You can give Jalopy complete control over the blank lines handling, or use a more relaxed style and keep existing blank lines up to a given number.

General

Lets you specify the number of blank lines that should appear before, after and between different Java source elements.

Figure 2.46. Blank Lines settings page

Blank Lines settings page

Declaration section

Lets you control how many blank lines should be printed before a new declaration section. A declaration section means an arbitary amount of similar declarations, like e.g. instance initializers, or methods or enum declarations. This option is only meaningful when code sorting is enabled for declarations. Refer to the section called “Declarations” for more information about the code sorting feature.

Since 1.4

Example 2.662. 2 blank lines before code sections

private Foo aFoo;
¶
¶
Constructor(Foo rFoo) {
}
¶
¶
public static void method(Foo rFoo) {
}

Package statement

Lets you control how many blank lines should be printed after the package statement.

Example 2.663. 3 blank lines after package statement

package com.triemax.jalopy.printer;
¶
¶
¶
import antlr.collections.AST;

import com.triemax.jalopy.parser.JavaAST;
import com.triemax.jalopy.parser.JavaTokenTypes;

...

Imports

Lets you control how many blank lines should be printed after the last import statement.

Example 2.664. 4 blank lines after last import statement

package com.triemax.jalopy.printer;

import antlr.collections.AST;

import com.triemax.jalopy.parser.JavaAST;
import com.triemax.jalopy.parser.JavaTokenTypes;
¶
¶
¶
¶
public class Printer {
}

Classes

Lets you control how many blank lines should be printed before the first top level class declaration of a compilation unit and between two class declarations.

Example 2.665. 1 blank line before class declaration

class Foo {
}

The blank lines before setting is only meaningful if the class declaration is the first top level declaration of a compilation unit and not preceded by a package or import statement.

Example 2.666. 2 blank lines between two class declarations

class One {
}
¶
¶
class Two {
}

Interfaces

Lets you control how many blank lines should be printed before the first top level interface declaration of a compilation unit and between two interface declarations.

Example 2.667. 2 blank lines before first interface declarations

¶
¶
interface Fooable {
}

The blank lines before setting is only meaningful if the interface declaration is the first top level declaration of a compilation unit and not preceded by a package or import statement.

Example 2.668. 3 blank lines between two interface declarations

interface One {
}
¶
¶
¶
interface Two {
}

Enums

Lets you control how many blank lines should be printed before the first top level enum declaration of a compilation unit and between two enum declarations. The blank lines before setting is only meaningful if the enum declaration is the first top level declaration of a compilation unit and not preceded by a package or import statement.

Since 1.1

Example 2.669. 3 blank lines between two enum declarations

public enum Season {
    WINTER, SPRING, SUMMER, FALL
}
¶
¶
¶
public enum Day {
    MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}

Annotations

Lets you control how many blank lines should be printed before the first top level annotation declaration of a compilation unit and between two annotation declarations. The blank lines before setting is only meaningful if the annotation declaration is the first top level declaration of a compilation unit and not preceded by a package or import statement.

Since 1.1

Example 2.670. 2 blank lines between two enum declarations

public @interface Name {
    String first();
    String last();
}
¶
¶
public @interface Endorsers {
    String[] value();
}

Methods

Lets you control how many blank lines should be printed between two method/constructor declarations.

Example 2.671. 3 blank lines between two method declarations

public static Printer getInstance() {
    return INSTANCE;
}
¶
¶
¶
public void print(AST node, ASTWriter out)
           throws IOException {
}

Variables

Lets you control how many blank lines should be printed before and after variable declarations.

Example 2.672. 1 blank line before variable declarations

System.out.println();
¶
int a = 1;
int b = 2;

Example 2.673. 2 blank lines after variable declarations

int a = 1;
int b = 2;
¶
¶
System.out.println();

Left curly brace class

Forces the given number of blank lines after left curly braces of class, interface and enum declarations. You need to explicitly enable the option to take effect. When enabled, this option takes highest precedence and overrides all other blank line settings.

Please note that you need to set this option only if you want different left curly blank lines behavior for class level blocks. Otherwise, the corresponding options for left curly brace endline/newline would be enough to enforce consistent behavior.

Since 1.9.1

Example 2.674. Blank lines before Javadoc=1

class Demo {

    /** Demo method */
    public void foo() {
    }
}

Example 2.675. Blank lines before Javadoc=1, Blank lines after left curly braces=0

class Demo {
    /** Demo method */
    public void foo() {
    }
}

Left curly brace method

Forces the given number of blank lines after left curly braces of method and constructor declarations. You need to explicitly enable the option to take effect. When enabled, this option takes highest precedence and overrides all other blank line settings.

Please note that you need to set this option only if you want different left curly blank lines behavior for method level blocks. Otherwise, the corresponding options for left curly brace endline/newline would be enough to force consistent behavior.

Since 1.9.1

Example 2.676. Blank lines before comments=1

public void foo {

    // do something
}

Example 2.677. Blank lines before comments=1, Blank lines after left curly braces=0

public void foo {
    // do something
}

Left curly brace endline

Forces the given number of blank lines after left curly braces that are printed at the end of the line beginning the compound statement (a.k.a. Sun brace style). You need to explicitly enable the option to take effect. When enabled, this option overrides all other blank line settings other than Left curly brace class and Left curly brace method.

Example 2.678. Blank lines before blocks=1

public void foo() {
¶
    if (condition()) {
¶
        if (anotherCondition()) {
            doSomething();
        }
    }
}

Example 2.679. Blank lines before blocks=1, Blank lines after left curly braces=0

public void foo() {
    if (condition()) {
        if (anotherCondition()) {
            doSomething();
        }
    }
}

Left curly brace endline newline

Forces the given number of blank lines after left curly braces that are printed at the beginning of lines (a.k.a. C brace style). When enabled, this option overrides all other blank line settings.

Since 1.7

Example 2.680. Blank lines before blocks=1

public void foo()
{
¶
    if (condition())
    {
¶
        if (anotherCondition())
        {
            doSomething();
        }
    }
}

Example 2.681. Blank lines before blocks=1, Blank lines after left curly braces=0

public void foo()
{
    if (condition())
    {
        if (anotherCondition())
        {
            doSomething();
        }
    }
}

Right curly brace

Forces the given number of blank lines before closing curly braces, no matter what other blank lines settings dictate.

Example 2.682. Blank lines before blocks=1

public void foo() {
    if (condititon()) {
        if (anotherCondition()) {
            doSomething();
¶
        }
¶
    }
¶
}

Blocks

Lets you control how many blank lines should be printed before and after statement blocks (if-else , for, while, do-while, switch, try-catch-finally, synchronized). Note that the “Blank Lines After” setting also applies for anonymous inner classes.

Example 2.683. 2 blank lines before and after blocks

AST type = null;
¶
¶
switch (next.getType()) {
    case JavaTokenTypes.LPAREN :
        type = PrinterUtils.advanceToFirstNonParen(next);
        break;
    default :
        type = next;
        break;
}
¶
¶
AST ident = type.getFirstChild();

Case blocks

Lets you control how many blank lines should be printed before each case block of a switch expression.

Example 2.684. 3 blank lines before case blocks

switch (next.getType()) {
¶
¶
¶
    case JavaTokenTypes.LPAREN :
        type = PrinterUtils.advanceToFirstNonParen(next);
        break;
¶
¶
¶
    default :
        type = next;
        break;
}

Control statements

Lets you control how many blank lines should be printed before the statements return, break and continue.

Example 2.685. 2 blank lines before case control statements

switch (next.getType()) {
    case JavaTokenTypes.LPAREN :
        type = PrinterUtils.advanceToFirstNonParen(next);
¶
¶
        break;

    default :
        type = next;
¶
¶
        break;
}

Note that this setting does not apply when a control statement appears directly after the case or default keyword or when the statement is the single member of a statement block without curly braces.

Example 2.686. Setting takes no effect before case control statements

switch (next.getType()) {
    case JavaTokenTypes.LPAREN :
        break;

    default :
        continue;
}

Example 2.687. Setting takes no effect for single statements in blocks

if (isClean())
    return;

Single-line comments

Lets you control how many blank lines should be printed before single-line comments.

Example 2.688. 1 blank line before single-line comment

System.out.println("ERROR");
¶
// XXX use log4j logger
ex.printStackTrace();

Multi-line comments

Lets you control how many blank lines should be printed before multi-line comments.

Example 2.689. 2 blank lines before multi-line comment

System.out.println("ERROR");
¶
¶
/* XXX use log4j logger */
ex.printStackTrace();

Javadoc comments

Lets you control how many blank lines should be printed before Javadoc comments.

Separator comments

Lets you control how many blank lines should be printed before and after separator comments.

Since 1.7

Example 2.690. 2 blank lines before/after separator comment

protected Foo instance;
¶
¶
//~ Constructors -----------------------------------------------------------
¶
¶
public Demo ( ) {}
public Demo (  Foo anotherFoo ) {}

Header

Lets you control how many blank lines should be printed before and after headers.

Example 2.691. No blank lines after header

// Copyright 1998-2000, Foo, Inc. All Rights Reserved.
// Confidential and Proprietary Information of Foo, Inc.
// Protected by or for use under one or more of the following patents:
// U.S. Patent Nos. X,XXX,XXX. Other Patents Pending.
package com.foobar;

...

Example 2.692. 2 blank lines after header

// Copyright 1998-2000, Foo, Inc. All Rights Reserved.
// Confidential and Proprietary Information of Foo, Inc.
// Protected by or for use under one or more of the following patents:
// U.S. Patent Nos. X,XXX,XXX. Other Patents Pending.
¶
¶
package com.foobar;

...

Footer

Lets you control how many blank lines should be printed before and after footers.

SQLJ clauses

Lets you control how many blank lines should be printed before and after SQLJ clauses.

Example 2.693. 2 blank lines before/after SQLJ clause

Integer salesRepID   = new Integer(358);
String  salesRepName = "Jouni Seppanen";
Date    dateSold     = new Date(97,11,6);
¶
¶
#sql { INSERT INTO SALES VALUES( :itemID,:itemName,:dateSold,:totalCost,
      :salesRepID,:salesRepName) };
¶
¶
SalesRecs sales;

Assignment section

Lets you control how many blank lines are printed after a section with several (at least two) consecutive assignment expressions.

Since 1.4

Example 2.694. 1 blank line after assignment section

c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(0, 0, 0, 0);
¶
middlePanel.add(buttonsPanel, c);