Java PMD-检查太多的公共方法(但排除构造函数和getter/setter)
我希望添加一个PMD检查,以确保一个类没有太多的公共方法,但我不希望在检查中包括构造函数和getter/setter ExcessivePublicCount检查包括构造函数、getter/setter和公共变量,我看不到定制它的方法 TooManyMethods检查不包括getter/setter,但包括其他所有内容(包括私有方法)。检查的XPath代码如下所示Java PMD-检查太多的公共方法(但排除构造函数和getter/setter),java,xpath,static-analysis,pmd,Java,Xpath,Static Analysis,Pmd,我希望添加一个PMD检查,以确保一个类没有太多的公共方法,但我不希望在检查中包括构造函数和getter/setter ExcessivePublicCount检查包括构造函数、getter/setter和公共变量,我看不到定制它的方法 TooManyMethods检查不包括getter/setter,但包括其他所有内容(包括私有方法)。检查的XPath代码如下所示 //ClassOrInterfaceDeclaration/ClassOrInterfaceBody [ count(des
//ClassOrInterfaceDeclaration/ClassOrInterfaceBody
[
count(descendant::MethodDeclarator[
not
(
starts-with(@Image,'get')
or
starts-with(@Image,'set')
)
]) > $maxmethods
]
有人能帮我修改这个以实现我想要的吗,或者建议用PMD实现这个目的的另一种方法吗
//ClassOrInterfaceDeclaration/ClassOrInterfaceBody [
count(descendant::MethodDeclarator[
..[@Public='true']
and
not
(
starts-with(@Image,'get')
or
starts-with(@Image,'set')
or
starts-with(@Image,'is')
)
] ) > $maxmethods
]
您正在计算MethodDeclarator,因此不应包括MethodDeclarator。..[@Public='true']
从MethodDeclarator返回MethodDeclaration,然后检查它是否是公共的