commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Herbert <>
Subject Re: New Sub-project Proposal.
Date Mon, 23 Sep 2019 11:25:06 GMT
On 23/09/2019 11:13, Claude Warren wrote:
> For the style issues.... is there an Eclipse style package that meets the
> commons style or some other tool that will correctly configure the format
> and style options in Eclipse?

The Commons style across most projects is loosely based on the Java 
coding style, although there is no definite single style. Checkstyle is 
used to make sure the code is consistent in the project so you should 
aim to pass those checks. Just run:

mvn checkstyle:checkstyle

You can then look at the report in target/site/checkstyle.html

You can even get a plugin for Eclipse for checkstyle [1]. It can be 
setup to work with the project checkstyle config and suppression file. 
This will highlight problems for you directly in the Eclipse editor.

However it is useful to let a formatter do some work for you. Personally 
I rarely use the Eclipse formatter for Commons and not on a whole file. 
It is useful to highlight sections of code and then run the formatter on 
those. It will help speed up reformatting. E.g. if you have lots of 
loops and if statements with braces on the 'wrong' line.

I attached a modified version of the built-in Java coding style from 
eclipse that I use for the Commons RNG project.

This one is based on 120 characters per line and a few other project 
specific styles. You may have to tweak the settings to match what the 
project checkstyle configuration will allow. For example line wrapping 
with expressions will either have the operator on the same line or the 
next line.

I do not trust the formatter to run as fire-and-forget. I would locally 
stash/stage files in git, run the formatter then do a diff to see what 
it has done. You can do this with the git tools within Eclipse (e.g. 
Compare with index).

Note that Eclipse has poor options for formatting HTML in comments. For 
example it compresses list elements <LI> into one large line whereas it 
is more human readable to have each on a single line. So make sure to 
check any javadoc with large blocks containing HTML tags. Or do not 
format them and only locally highlight code for formatting.

If you find that this example is nowhere close to the 
commons-collections checkstyle rules then just throw it away and start 
from the default java codestyle in Eclipse. Configuring the rules is 
pretty easy.



View raw message