Check if the first variable in a class is a constant named LOG

34 Views Asked by At

There are actually a couple of questions, the first one from the title:

  1. How can I write a check that checks wheter the very first field in a class is a constant named LOG?

    For example, this would pass the check:

    public class MyClass {
    
        private static final Logger LOG = LoggerFactory.getLogger(MyClass.class);
        .
        .
        .
    }
    

    while this would fail the check:

    public class MyClass {
    
        private String someString;
    
        private static final Logger LOG = LoggerFactory.getLogger(MyClass.class);
        .
        .
        .
    }
    

    Note that the LOG field should be declared as the first variable only if it is declared in the class (I don't want checkstyle to fail while checking model classes which almost always have no LOG constant defined).

0

There are 0 best solutions below