-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static MethodCount #14695
Comments
We will not add this token, we try to follow the JLS as closely as possible (without too many breaking changes for past weirdness). This sounds like a good candidate for MatchXPathCheck. @xenoterracide have you considered using this check? A good start might be to create an expression like "if a given class name does not contain "Util" and this class has more than 5 static methods, place a violation on the class". |
We will not add non java tokens.
We will not do this, sorry. You can archive easily what you need by writing your own Check and hosting it in your own repository. There are more examples in web for team custom Checks. |
My head hurts trying to describe this... I want a way to define how many static methods can exist on a utility class vs an instance class or other token as listed on https://checkstyle.org/checks/sizes/methodcount.html
Unfortunately
MethodCount
didn't choose differentiate between static and non static, or between utility classes and instance classes. This is hard to describe because I think What I want is a Token calledUTIL_CLASS_DEF
which probably doesn't work since it's not a real language construct (dear java).Motivation for this is the number of static methods for a utility class is high, but for a regular class if you have more than a couple of public static (probably factory) methods, then your class is probably misdesigned.
Adding these properties and that token could work
A new check to replace the existing check could also work and at least simplify naming. Maybe 2 checks would work as a utility class should have 0 public and protected instance methods, possibly 0 entirely. The problem is that no matter what way I think to solve this it's a cartesian product of what's already there, you could add more checks, explode the properties.
The text was updated successfully, but these errors were encountered: