[java] Fix deprecated attributes in XPath rules

This commit is contained in:
Andreas Dangel
2019-10-05 20:47:10 +02:00
parent 0ff97e5959
commit 52341d9d67
3 changed files with 67 additions and 70 deletions

View File

@ -316,13 +316,13 @@ prefix for these methods.
<property name="xpath">
<value>
<![CDATA[
//MethodDeclaration[
MethodDeclarator[count(FormalParameters/FormalParameter) = 0 or $checkParameterizedMethods = 'true']
[starts-with(@Image, 'get')]
and
ResultType/Type/PrimitiveType[@Image = 'boolean']
and not(../Annotation//Name[@Image = 'Override'])
]
//MethodDeclaration
[starts-with(@Name, 'get')]
[@Arity = 0 or $checkParameterizedMethods = 'true']
[
ResultType/Type/PrimitiveType[@Image = 'boolean']
and not(../Annotation//Name[@Image = 'Override'])
]
]]>
</value>
</property>
@ -1647,7 +1647,7 @@ Method names that are very short are not helpful to the reader.
<property name="xpath">
<value>
<![CDATA[
//MethodDeclarator[string-length(@Image) < $minimum]
//MethodDeclaration[string-length(@Name) < $minimum]
]]>
</value>
</property>

View File

@ -1557,11 +1557,11 @@ complexity and find a way to have more fine grained objects.
something like this:
not (
(
starts-with(@Image,'get')
starts-with(@Name,'get')
or
starts-with(@Image,'set')
starts-with(@Name,'set')
or
starts-with(@Image,'is')
starts-with(@Name,'is')
)
and (
(
@ -1571,18 +1571,18 @@ complexity and find a way to have more fine grained objects.
) <= 3
)
)
This will avoid discarding 'real' method...
This will avoid discarding 'real' methods...
-->
<![CDATA[
//ClassOrInterfaceDeclaration/ClassOrInterfaceBody
[
count(./ClassOrInterfaceBodyDeclaration/MethodDeclaration/MethodDeclarator[
count(./ClassOrInterfaceBodyDeclaration/MethodDeclaration[
not (
starts-with(@Image,'get')
starts-with(@Name,'get')
or
starts-with(@Image,'set')
starts-with(@Name,'set')
or
starts-with(@Image,'is')
starts-with(@Name,'is')
)
]) > $maxmethods
]

View File

@ -694,16 +694,16 @@ public String bar(String string) {
<property name="xpath">
<value>
<![CDATA[
//MethodDeclaration[MethodDeclarator[
@Image='onCreate' or
@Image='onConfigurationChanged' or
@Image='onPostCreate' or
@Image='onPostResume' or
@Image='onRestart' or
@Image='onRestoreInstanceState' or
@Image='onResume' or
@Image='onStart'
]]
//MethodDeclaration[
@Name='onCreate' or
@Name='onConfigurationChanged' or
@Name='onPostCreate' or
@Name='onPostResume' or
@Name='onRestart' or
@Name='onRestoreInstanceState' or
@Name='onResume' or
@Name='onStart'
]
/Block[not(
(BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image]))]
[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
@ -741,14 +741,14 @@ Super should be called at the end of the method
<property name="xpath">
<value>
<![CDATA[
//MethodDeclaration[MethodDeclarator[
@Image='finish' or
@Image='onDestroy' or
@Image='onPause' or
@Image='onSaveInstanceState' or
@Image='onStop' or
@Image='onTerminate'
]]
//MethodDeclaration[
@Name='finish' or
@Name='onDestroy' or
@Name='onPause' or
@Name='onSaveInstanceState' or
@Name='onStop' or
@Name='onTerminate'
]
/Block/BlockStatement[last()]
[not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/MethodDeclarator/@Image])]
[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
@ -864,8 +864,8 @@ Object.clone (which is protected) with a public method."
<value>
<![CDATA[
//MethodDeclaration[@Public='false']
[MethodDeclarator/@Image = 'clone']
[MethodDeclarator/FormalParameters/@ParameterCount = 0]
[@Name = 'clone']
[@Arity = 0]
]]>
</value>
</property>
@ -937,8 +937,8 @@ Note: This is only possible with Java 1.5 or higher.
<![CDATA[
//MethodDeclaration
[
MethodDeclarator/@Image = 'clone'
and MethodDeclarator/FormalParameters/@ParameterCount = 0
@Name = 'clone'
and @Arity = 0
and not (ResultType//ClassOrInterfaceType/@Image = ancestor::ClassOrInterfaceDeclaration[1]/@Image)
]
]]>
@ -978,8 +978,8 @@ The method clone() should throw a CloneNotSupportedException.
<![CDATA[
//MethodDeclaration
[
MethodDeclarator/@Image = 'clone'
and count(MethodDeclarator/FormalParameters/*) = 0
@Name = 'clone'
and @Arity = 0
and count(NameList/Name[contains
(@Image,'CloneNotSupportedException')]) = 0
]
@ -1483,7 +1483,7 @@ Empty finalize methods serve no purpose and should be removed. Note that Oracle
<property name="xpath">
<value>
<![CDATA[
//MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]
//MethodDeclaration[@Name='finalize'][@Arity = 0]
/Block[count(*)=0]
]]>
</value>
@ -1849,7 +1849,7 @@ If the finalize() is implemented, its last action should be to call super.finali
<!-- in English: a method declaration of finalize(), with no arguments, containing
a block whose last statement is NOT a call to super.finalize -->
<![CDATA[
//MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]
//MethodDeclaration[@Name='finalize'][@Arity = 0]
/Block
/BlockStatement[last()]
[not(Statement/StatementExpression/PrimaryExpression
@ -1891,7 +1891,7 @@ If the finalize() is implemented, it should do something besides just calling su
<property name="xpath">
<value>
<![CDATA[
//MethodDeclaration[MethodDeclarator[@Image="finalize"][not(FormalParameters/*)]]
//MethodDeclaration[@Name='finalize'][@Arity = 0]
/Block[count(BlockStatement)=1]
/BlockStatement[
Statement/StatementExpression/PrimaryExpression
@ -1928,8 +1928,7 @@ Note that Oracle has declared Object.finalize() as deprecated since JDK 9.
<property name="xpath">
<value>
<![CDATA[
//MethodDeclaration
/MethodDeclarator[@Image='finalize'][FormalParameters[count(*)>0]]
//MethodDeclaration[@Name='finalize'][@Arity > 0]
]]>
</value>
</property>
@ -1962,9 +1961,7 @@ Note that Oracle has declared Object.finalize() as deprecated since JDK 9.
<property name="xpath">
<value>
<![CDATA[
//MethodDeclaration[@Protected="false"]
/MethodDeclarator[@Image="finalize"]
[not(FormalParameters/*)]
//MethodDeclaration[@Protected="false"][@Name='finalize'][@Arity = 0]
]]>
</value>
</property>
@ -2126,11 +2123,11 @@ Some JUnit framework methods are easy to misspell.
<property name="xpath">
<value>
<![CDATA[
//MethodDeclarator[(not(@Image = 'setUp')
and translate(@Image, 'SETuP', 'setUp') = 'setUp')
or (not(@Image = 'tearDown')
and translate(@Image, 'TEARdOWN', 'tearDown') = 'tearDown')]
[FormalParameters[count(*) = 0]]
//MethodDeclaration[(not(@Name = 'setUp')
and translate(@Name, 'SETuP', 'setUp') = 'setUp')
or (not(@Name = 'tearDown')
and translate(@Name, 'TEARdOWN', 'tearDown') = 'tearDown')]
[@Arity = 0]
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[pmd-java:typeIs('junit.framework.TestCase')]
or //MarkerAnnotation/Name[
pmd-java:typeIs('org.junit.Test')
@ -2170,8 +2167,8 @@ The suite() method in a JUnit test needs to be both public and static.
<value>
<![CDATA[
//MethodDeclaration[not(@Static='true') or not(@Public='true')]
[MethodDeclarator/@Image='suite']
[MethodDeclarator/FormalParameters/@ParameterCount=0]
[@Name='suite']
[@Arity = 0]
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[pmd-java:typeIs('junit.framework.TestCase')]
or //MarkerAnnotation/Name[
pmd-java:typeIs('org.junit.Test')
@ -2635,10 +2632,10 @@ Object clone() should be implemented with super.clone().
<property name="xpath">
<value>
<![CDATA[
//MethodDeclarator
[@Image = 'clone']
[count(FormalParameters/*) = 0]
[count(../Block//*[
//MethodDeclaration
[@Name = 'clone']
[@Arity = 0]
[count(./Block//*[
(self::AllocationExpression) and
(./ClassOrInterfaceType/@Image = ancestor::
ClassOrInterfaceDeclaration[1]/@Image)
@ -3008,23 +3005,23 @@ intention to override the equals(Object) method.
<property name="xpath">
<value>
<![CDATA[
//MethodDeclarator[@Image = 'equals']
//MethodDeclaration[@Name = 'equals']
[
(count(FormalParameters/*) = 1
and not (FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
(@Arity = 1
and not (MethodDeclarator/FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
[@Image = 'Object' or @Image = 'java.lang.Object'])
or not (../ResultType/Type/PrimitiveType[@Image = 'boolean'])
or not (ResultType/Type/PrimitiveType[@Image = 'boolean'])
) or (
count(FormalParameters/*) = 2
and ../ResultType/Type/PrimitiveType[@Image = 'boolean']
and FormalParameters//ClassOrInterfaceType[@Image = 'Object' or @Image = 'java.lang.Object']
and not(../../Annotation/MarkerAnnotation/Name[@Image='Override'])
@Arity = 2
and ResultType/Type/PrimitiveType[@Image = 'boolean']
and MethodDeclarator/FormalParameters//ClassOrInterfaceType[@Image = 'Object' or @Image = 'java.lang.Object']
and not(../Annotation/MarkerAnnotation/Name[@Image='Override'])
)
]
| //MethodDeclarator[@Image = 'equal']
| //MethodDeclaration[@Name = 'equal']
[
count(FormalParameters/*) = 1
and FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
@Arity = 1
and MethodDeclarator/FormalParameters/FormalParameter/Type/ReferenceType/ClassOrInterfaceType
[@Image = 'Object' or @Image = 'java.lang.Object']
]
]]>