[java] Fix ClassWithOnlyPrivateConstructorsShouldBeFinal with multiple
classes Fixes #3851
This commit is contained in:
@ -338,11 +338,17 @@ is invoked by a inner class.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//TypeDeclaration[count(../TypeDeclaration) = 1]/ClassOrInterfaceDeclaration
|
||||
[@Final = false()]
|
||||
[ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private = true()]]
|
||||
[not(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[(@Public = true()) or (@Protected = true()) or (@PackagePrivate = true())])]
|
||||
[not(.//ClassOrInterfaceDeclaration)]
|
||||
//TypeDeclaration
|
||||
/ClassOrInterfaceDeclaration
|
||||
[@Final = false()]
|
||||
(: at least one private constructor :)
|
||||
[ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private = true()]]
|
||||
(: no public constructor :)
|
||||
[not(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[(@Public = true()) or (@Protected = true()) or (@PackagePrivate = true())])]
|
||||
(: not a base class in the same compilation unit :)
|
||||
[not(@SimpleName = ../../TypeDeclaration/ClassOrInterfaceDeclaration/ExtendsList/ClassOrInterfaceType/@Image)]
|
||||
(: not a base class for a inner class in the same compilation unit :)
|
||||
[not(@SimpleName = .//ClassOrInterfaceDeclaration/ExtendsList/ClassOrInterfaceType/@Image)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -170,6 +170,21 @@ public class Outer {
|
||||
private abstract class Base {
|
||||
private void run() {}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>[java] ClassWithOnlyPrivateConstructorsShouldBeFinal - false negative when a compilation unit contains two class declarations #3851</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>1</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
public class Example { // false-negative here
|
||||
private Example() {
|
||||
}
|
||||
}
|
||||
|
||||
class Another {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user