0

I need to perform some validations to some of my classes, for example:

  1. Every class field must be final or have one write per program (singleton);

  2. If the field it's not final, then it must be private;

  3. Every array must be private.

I've already saw that findbugs and checkstyle can do this kind of checks, but I didn't saw them by default, and the only option I've found it's developing plugins for checkstyle (for convention checks) and for findbugs (for bug detection). Is there any better alternative?

I'm using Windows 7 x64 with Eclipse Indigo with FindBugs and CheckStyle plugins.

rnunes
  • 2,785
  • 7
  • 28
  • 56
  • 1
    We are using sonar for those checks, which in turn uses findbugs, pmd and checkstyle. (2) is already covered by at least one of these tools, as this was marked by sonar with the default rule set. Not sure about (1), but I think eclipse itself can already warn about these. As for (3), that somewhat overlaps with (2), does it not? – arne.b Nov 20 '12 at 12:57

4 Answers4

4

Configure Eclipse warnings (some good ones are set to inactive !):

  • check unused parameters
  • suggests making methods static
  • concerning the private you should use other tools (perhaps PMD or CheckStyle)
  • ...

Eclipse save actions:

  • Adds final where possible
  • can enforce some coding style by automatic formatting code

Use FindBugs and FindBugs contrib to find more mistakes. PMD and CheckStyle if you want to perform style/formatting checks.

I would also suggest using errors instead of warnings, this forces me to deal with some evil warnings which must be fixed. Same for FindBugs, if you use the Maven plugin you can make the build fail in case of bugs (so select your rules carefully). I run additional optional rules inside Eclipse as a complement.

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
1

We used some eclipse built-ins functionality for warnings and errors (for the basics) and findbugs for more complicated issues.

But if we had some really specific thing that we wanted to check (Like all classes that ended with the word Singleton was called only in specific package) we wrote some text scanners scripts (in perl) to do so.

I wouldn't recommend it so much, but if you have to...

shem
  • 4,686
  • 2
  • 32
  • 43
1

Checkstyle can handle all this checks out ofthe box.

In the documentation you can find all possible checks and how to configure them.

Also if this is not enough you have the chance to create your own checks for either checkstyle or finbugs.

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48
0

If the existing checks in checktyle doesn't address your points exactly the way you want, you can use PMD in which custom rules can be easily implemented using XPath expressions. Ref. : how to write a PMD rule