You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 called UTIL_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
name
description
type
default value
since
maxStaticPackage
Specify the maximum number of package methods allowed.
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:
I think What I want is a Token called UTIL_CLASS_DEF which probably doesn't work since it's not a real language construct (dear java).
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".
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: