Style tweaking

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Style tweaking

Mikhail Yakshin
Hi, Checkstyle users and developers,

I'd like to thank Checkstyle developers for such a great product -
recently I've found out that I need style enforcement in some of my
projects and Checkstyle was a great boon :)

However, I have some questions about tweaking Checkstyle XMLs with
check options to match our team's style and default Eclipse/IDEA
practices, namely:

1. How do I enforce the following style in array initializers:

String[] a = new String[] { "a", "b", "c" };

Checkstyle includes "no whitespace after" check that specifically
disallows this style, insisting on:

String[] a = new String[] {"a", "b", "c"};

I can disable it and it will pass, but in fact, I'd like to enforce
the opposite - having whitespaces before and after "{" and before "}"
in array initializers.

2. Many of our classes are serializable and thus carry
serialVersionUID constant, such as:

    private static final long serialVersionUID = -4622100204472117552L;

How can I check that:
a) There's no Javadoc for this one - it's kind of pointless to include one.
b) It's the topmost line in a class, if it presents

3. How do I enforce the following style of class fields:

class MyClass {
    private int f1;

    public MyClass(int f1) {
        this.f1 = f1;

I've managed to disable the opposite check - that complained that
supplying f1 in constructors hinders visibility of f1, but I want to
enforce it, i.e. find cases such as

public MyClass(int _f1) {
    f1 = _f1;


public MyClass(int someOtherFieldName) {
    f1 = someOtherFieldName;

and mark them as failing the check.

Thanks :)

WBR, Mikhail Yakshin

Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
Checkstyle-user mailing list
[hidden email]