« Back

Liferay Code Format

Company Blogs December 26, 2007 By Minhchau Dang Staff

After reading through Jorge's blog post on the guidelines for Liferay contributions, and after following the link to the style guidelines on the Liferay wiki, I put together a configuration file which works with Eclipse's built-in code formatter to adjust the whitespace in your code so that is compatible with the stated Liferay guidelines.

To use this configuration file, go to your Eclipse preferences dialog. Check under Java > Code Style > Formatter (screenshot), and then Import the above linked file. A new profile called "Liferay [user]" will then be made available (screenshot). Finally, click the Apply button to set it for the current workspace.

Once this configuration file is imported and applied to the current workspace, every time you run Source > Format, Eclipse will automatically adjust the whitespace in your code to make it conform to the stated Liferay guidelines. To bulk reformat, you can right-click on any given folder while in the Navigator view (or Ctrl+Click on the folder under OS X), and select Source > Format.

I don't know of any tools which help satisfy all of the Liferay style guidelines not pertaining to whitespace. However, based on its documentation, the commercial version of Jalopy from TRIEMAX software appears to come very close with its sorting capabilities.

Threaded Replies Author Date
Why don't you just use checkstyle? John Arne December 29, 2007 6:23 AM
I'd never heard of the checkstyle project... Minhchau Dang January 11, 2008 10:27 AM
Hi Minhchau, That's very nice. Could you add... Jorge Ferrer December 30, 2007 7:42 AM
It is an old article... what is the current... Steffen Schuler July 20, 2016 6:31 AM

Why don't you just use checkstyle?
Posted on 12/29/07 6:23 AM.
Hi Minhchau,

That's very nice. Could you add it to the wiki article?
Posted on 12/30/07 7:42 AM.
I'd never heard of the checkstyle project (http://checkstyle.sourceforge.net/) before your reply. Thanks for the heads up! At a glance, it likely satisfies the style requirements for a lot of different projects. But, on its own, it still falls short of the Liferay coding requirements described in the wiki.

checkstyle provides one extra feature that Jalopy didn't support (naming conventions), so if we combine all the known tools (both free and commercial), we come pretty close. The only things missing are naming conventions for private methods but not public methods, and grouping of getters and setters for readability.
Posted on 1/11/08 10:27 AM in reply to John Arne.
It is an old article... what is the current state, when it comes to applying style to code? Is there a checkstyle rule file available, these days?
Posted on 7/20/16 6:31 AM.