#18 check names of methods + local variables

Lars Kühne
Jens Krinke

Only a subset of identifiers are checked by checkstyle.
It is desirable that it also checks method names and
names of local variables. Example:

class foo$bar_1 {
class foo$bar_2 {
int foo$bar_3;
void foo$bar_4 (int foo$bar_5) {
int foo$bar_6;
class foo$bar_7 {
void foo$bar_8 (int foo$bar_9) {
int foo$bar_10;
while (true) {
int foo$bar_11;
int foo$bar_12;

In this example, only 1, 2, 3, 5, 7 and 9 are checked.
Identifiers 4, 8 (method names), 6, 10, 11 (local
variables) are ignored.


  • Lars Kühne
    Lars Kühne

    Logged In: YES

    This is now implemented in CVS and will be available in the
    next release

  • Jens Krinke
    Jens Krinke

    Logged In: YES

    I have checked the CVS version and it looks great. However,
    there is a slight Problem: Inside Methods, one cannot define
    constants via static final: they are only final there.
    There should be a special check for final non-static: Inside
    methods this is matched against the regexp for constants,
    outside methods a hint "have you meant final static?"
    would be a great improvement.

    BTW, thanks for that great tool: we are using it in
    automated programming courses (see praktomat on sf.net).

  • Lars Kühne
    Lars Kühne

    Logged In: YES


    we have a patch waiting for inclusion that enforces a more
    rigorous use of "final" declarations inside methods. This
    would find the common mistake to "recycle" method variables
    or parameters. We think using final inside methods is good
    style, and that's why the source code of checkstyle uses
    "final" all over the place.

    Combining that with your suggestion to use the "constants"
    pattern for final variables inside methods, this would lead
    to code where all but a few variables are uppercase. I think
    most people would agree that this is not considered readable
    code, or "good style".

    I have submitted your second suggestion as a new Feature
    Request (#516305). Don't expect it to be implemented in the
    near future, though (unless you do it yourself ;-).

    Always good to hear that people find checkstyle useful.