Whizu

jQuery Mobile in Java

View project on GitHub
Whizu Download
jQuery Mobile widgets
Pages Accordions Buttons Collapsibles
Check out my latest project at www.whizu.me and stop typing passwords with Kee Password Manager. Just like that.

How to selectively turn off the Eclipse code formatter

Written by Rudy D'hauwe on August 8, 2013.

As of version 3.6 Eclipse allows you to selectively turn off code formatting for certain sections of Java code by using a special @formatter comment.

// @formatter:off
...
// @formatter:on

Because Whizu uses a fluent builder API, it comes in handy to be able to selectively turn off the code formatter for readability purposes. Here's an example.

// @formatter:off
HeaderBuilder.create()
    .title("Tournament")
    .button("Add player")
        .onClick(playerList.addEvent())
        .build()
    .build()
    .on(page);
// @formatter:on

Without being able to selectively turn off the code formatter, this piece of code would be auto-formatted by Eclipse as follows.

HeaderBuilder.create().title("Tournament").button("Add player")
    .onClick(playerList.addEvent()).build().build().on(page);

How to enable the @formatter feature in Eclipse

The @formatter on/off feature has to be turned “on” in Eclipse preferences.

Window > Eclipse preferences > Java > Code Style > Formatter

Click on the “Edit” button, the “Off/On Tags” tab, and check “Enable Off/On tags”.

Written by Rudy D'hauwe | Copyright © 2013-2014 | All rights reserved.