Update XPath rules to 2.0
This commit is contained in:
@ -48,9 +48,9 @@ from the rest.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
|
||||
//IfBlockStatement/BlockStatement[@CurlyBrace= false()][count(child::*) > 0]
|
||||
|
|
||||
//IfElseBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
|
||||
//IfElseBlockStatement/BlockStatement[@CurlyBrace= false()][count(child::*) > 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -85,7 +85,7 @@ controlled from the rest.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfBlockStatement/BlockStatement[@CurlyBrace='false']
|
||||
//IfBlockStatement/BlockStatement[@CurlyBrace= false()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -142,9 +142,9 @@ from the rest.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForLoopStatement/BlockStatement[@CurlyBrace='false']
|
||||
//ForLoopStatement/BlockStatement[@CurlyBrace= false()]
|
||||
|
|
||||
//ForEachStatement/BlockStatement[@CurlyBrace='false']
|
||||
//ForEachStatement/BlockStatement[@CurlyBrace= false()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -348,7 +348,7 @@ controlled from the rest.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//WhileLoopStatement/BlockStatement[@CurlyBrace='false']
|
||||
//WhileLoopStatement/BlockStatement[@CurlyBrace= false()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -189,7 +189,7 @@ Empty block statements serve no purpose and should be removed.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//Method/ModifierNode[@Abstract!='true' and ../BlockStatement[count(*) = 0]]
|
||||
//Method/ModifierNode[@Abstract!= true() and ../BlockStatement[count(*) = 0]]
|
||||
| //Method/BlockStatement//BlockStatement[count(*) = 0 and @Location != parent::*/@Location]
|
||||
]]>
|
||||
</value>
|
||||
|
@ -122,6 +122,13 @@ public class ElementNode extends AbstractNodeInfo {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return getLocalPart();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("PMD.MissingBreakInSwitch")
|
||||
@Override
|
||||
public AxisIterator iterateAxis(byte axisNumber) {
|
||||
|
@ -41,8 +41,8 @@ public class XPathRule extends AbstractRule {
|
||||
|
||||
static {
|
||||
Map<String, String> tmp = new HashMap<>();
|
||||
tmp.put(XPATH_1_0, XPATH_1_0);
|
||||
tmp.put(XPATH_1_0_COMPATIBILITY, XPATH_1_0_COMPATIBILITY);
|
||||
tmp.put(XPATH_1_0, XPATH_2_0);
|
||||
tmp.put(XPATH_1_0_COMPATIBILITY, XPATH_2_0);
|
||||
tmp.put(XPATH_2_0, XPATH_2_0);
|
||||
XPATH_VERSIONS = Collections.unmodifiableMap(tmp);
|
||||
}
|
||||
@ -51,7 +51,7 @@ public class XPathRule extends AbstractRule {
|
||||
public static final EnumeratedProperty<String> VERSION_DESCRIPTOR = EnumeratedProperty.<String>named("version")
|
||||
.desc("XPath specification version")
|
||||
.mappings(XPATH_VERSIONS)
|
||||
.defaultValue(XPATH_1_0)
|
||||
.defaultValue(XPATH_2_0)
|
||||
.type(String.class)
|
||||
.uiOrder(2.0f)
|
||||
.build();
|
||||
|
@ -324,9 +324,9 @@ behavior especially when instances are distributed by the container on several J
|
||||
)
|
||||
and
|
||||
(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration[
|
||||
(./FieldDeclaration[@Static = 'true'])
|
||||
(./FieldDeclaration[@Static = true()])
|
||||
and
|
||||
(./FieldDeclaration[@Final = 'false'])
|
||||
(./FieldDeclaration[@Final = false()])
|
||||
])
|
||||
]
|
||||
]]></value>
|
||||
|
@ -27,8 +27,8 @@ directly) a protected constructor can be provided prevent direct instantiation.
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration
|
||||
[@Abstract='true'
|
||||
and count( .//MethodDeclaration[@Abstract='true'] )=0 ]
|
||||
[@Abstract= true()
|
||||
and count( .//MethodDeclaration[@Abstract= true()] )=0 ]
|
||||
[count(ImplementsList)=0]
|
||||
[count(.//ExtendsList)=0]
|
||||
]]>
|
||||
@ -380,7 +380,7 @@ better placed in classes or enums. See Effective Java, item 19.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration[@Interface='true'][$ignoreIfHasMethods='false' or not(.//MethodDeclaration)]//FieldDeclaration
|
||||
//ClassOrInterfaceDeclaration[@Interface= true()][$ignoreIfHasMethods= false() or not(.//MethodDeclaration)]//FieldDeclaration
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -426,8 +426,8 @@ By convention, the default label should be the last label in a switch statement.
|
||||
<value>
|
||||
<![CDATA[
|
||||
//SwitchStatement
|
||||
[not(SwitchLabel[position() = last()][@Default='true'])]
|
||||
[SwitchLabel[@Default='true']]
|
||||
[not(SwitchLabel[position() = last()][@Default= true()])]
|
||||
[SwitchLabel[@Default= true()]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -1075,7 +1075,7 @@ can be avoided, they will just return false.
|
||||
//PrimaryExpression[
|
||||
PrimaryPrefix[Name[(ends-with(@Image, '.equals'))]]
|
||||
[
|
||||
(../PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral='true'])
|
||||
(../PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral= true()])
|
||||
and
|
||||
( count(../PrimarySuffix/Arguments/ArgumentList/Expression) = 1 )
|
||||
]
|
||||
|
@ -28,12 +28,12 @@ by {% rule java/codestyle/ClassNamingConventions %}.
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration
|
||||
[@Abstract='true' and @Interface='false']
|
||||
[@Abstract= true() and @Interface= false()]
|
||||
[not (starts-with(@SimpleName,'Abstract'))]
|
||||
|
|
||||
//ClassOrInterfaceDeclaration
|
||||
[@Abstract='false']
|
||||
[$strict='true']
|
||||
[@Abstract= false()]
|
||||
[$strict= true()]
|
||||
[starts-with(@SimpleName, 'Abstract')]
|
||||
]]>
|
||||
</value>
|
||||
@ -116,7 +116,7 @@ If the goal is to avoid defining constants in a scope smaller than the class, th
|
||||
<value>
|
||||
<![CDATA[
|
||||
//LocalVariableDeclaration[
|
||||
@Final = 'true'
|
||||
@Final = true()
|
||||
and not(../../ForStatement)
|
||||
and
|
||||
(
|
||||
@ -213,9 +213,9 @@ Clarify your intent by using private or package access modifiers instead.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration[@Final='true']
|
||||
//ClassOrInterfaceDeclaration[@Final= true()]
|
||||
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
|
||||
/FieldDeclaration[@Protected='true']
|
||||
/FieldDeclaration[@Protected= true()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -244,12 +244,13 @@ visibility cannot be reduced). Clarify your intent by using private or package a
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="version" value="2.0"/>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration[@Final='true' and not(ExtendsList)]
|
||||
//ClassOrInterfaceDeclaration[@Final= true() and not(ExtendsList)]
|
||||
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
|
||||
/MethodDeclaration[@Protected='true' and @Name != 'finalize']
|
||||
/MethodDeclaration[@Protected=true() and @Name != 'finalize']
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -318,7 +319,7 @@ prefix for these methods.
|
||||
<![CDATA[
|
||||
//MethodDeclaration
|
||||
[starts-with(@Name, 'get')]
|
||||
[@Arity = 0 or $checkParameterizedMethods = 'true']
|
||||
[@Arity = 0 or $checkParameterizedMethods = true()]
|
||||
[
|
||||
ResultType/Type/PrimitiveType[@Image = 'boolean']
|
||||
and not(../Annotation//Name[@Image = 'Override'])
|
||||
@ -552,13 +553,13 @@ The rule allows methods and fields annotated with Guava's @VisibleForTesting.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration[@Interface='false']
|
||||
//ClassOrInterfaceDeclaration[@Interface= false()]
|
||||
/ClassOrInterfaceBody
|
||||
/ClassOrInterfaceBodyDeclaration
|
||||
[not(Annotation//Name[ends-with(@Image, 'VisibleForTesting')])]
|
||||
[
|
||||
FieldDeclaration[@PackagePrivate='true']
|
||||
or MethodDeclaration[@PackagePrivate='true']
|
||||
FieldDeclaration[@PackagePrivate= true()]
|
||||
or MethodDeclaration[@PackagePrivate= true()]
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
@ -623,16 +624,16 @@ usage by developers who should be implementing their own versions in the concret
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration[@Abstract = 'true']
|
||||
//ClassOrInterfaceDeclaration[@Abstract = true()]
|
||||
/ClassOrInterfaceBody
|
||||
/ClassOrInterfaceBodyDeclaration
|
||||
/MethodDeclaration[@Abstract = 'false' and @Native = 'false']
|
||||
/MethodDeclaration[@Abstract = false() and @Native = false()]
|
||||
[
|
||||
( boolean(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal/NullLiteral) = 'true' )
|
||||
( boolean(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal/NullLiteral) = true() )
|
||||
or
|
||||
( boolean(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal[@Image = '0']) = 'true' )
|
||||
( boolean(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal[@Image = '0']) = true() )
|
||||
or
|
||||
( boolean(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal[string-length(@Image) = 2]) = 'true' )
|
||||
( boolean(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal[string-length(@Image) = 2]) = true() )
|
||||
or
|
||||
(./Block[count(./BlockStatement) = 1]/BlockStatement/Statement/EmptyStatement)
|
||||
or
|
||||
@ -866,7 +867,7 @@ Names for references to generic values should be limited to a single uppercase l
|
||||
//TypeDeclaration/ClassOrInterfaceDeclaration/TypeParameters/TypeParameter[
|
||||
string-length(@Image) > 1
|
||||
or
|
||||
string:upper-case(@Image) != @Image
|
||||
upper-case(@Image) != @Image
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
@ -947,7 +948,7 @@ by the rule {% rule java/codestyle/ControlStatementBraces %}.
|
||||
<value>
|
||||
<![CDATA[
|
||||
//Statement
|
||||
[parent::IfStatement[@Else='true']]
|
||||
[parent::IfStatement[@Else= true()]]
|
||||
[not(child::Block)]
|
||||
[not(child::IfStatement)]
|
||||
]]>
|
||||
@ -1728,9 +1729,9 @@ by the more general rule {% rule java/codestyle/FieldNamingConventions %}.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration[@Interface='false']
|
||||
//ClassOrInterfaceDeclaration[@Interface= false()]
|
||||
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
|
||||
[@Final='false']
|
||||
[@Final= false()]
|
||||
[VariableDeclarator/VariableDeclaratorId[upper-case(@Image)=@Image]]
|
||||
]]>
|
||||
</value>
|
||||
@ -1767,7 +1768,7 @@ which class a static member comes from (Sun 1.5 Language Guide).
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
.[count(ImportDeclaration[@Static = 'true']) > $maximumStaticImports]
|
||||
.[count(ImportDeclaration[@Static = true()]) > $maximumStaticImports]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -1970,15 +1971,15 @@ which makes the code also more readable.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//VariableInitializer[preceding-sibling::VariableDeclaratorId[1]/@TypeInferred="false"]
|
||||
//VariableInitializer[preceding-sibling::VariableDeclaratorId[1]/@TypeInferred=false()]
|
||||
//PrimaryExpression[not(PrimarySuffix)]
|
||||
[not(ancestor::ArgumentList)]
|
||||
/PrimaryPrefix/AllocationExpression[ClassOrInterfaceType[@AnonymousClass='false']/TypeArguments//ReferenceType[not(.//TypeArguments)]]
|
||||
/PrimaryPrefix/AllocationExpression[ClassOrInterfaceType[@AnonymousClass= false()]/TypeArguments//ReferenceType[not(.//TypeArguments)]]
|
||||
|
|
||||
//StatementExpression[AssignmentOperator][PrimaryExpression/PrimaryPrefix[not(Expression)]]
|
||||
//PrimaryExpression[not(PrimarySuffix)]
|
||||
[not(ancestor::ArgumentList)]
|
||||
/PrimaryPrefix/AllocationExpression[ClassOrInterfaceType[@AnonymousClass='false']/TypeArguments//ReferenceType[not(.//TypeArguments)]]
|
||||
/PrimaryPrefix/AllocationExpression[ClassOrInterfaceType[@AnonymousClass= false()]/TypeArguments//ReferenceType[not(.//TypeArguments)]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -2031,7 +2032,7 @@ List<String> stringsWithDiamond = new ArrayList<>(); // using the diamond operat
|
||||
not(./CastExpression) and
|
||||
not(./EqualityExpression)]
|
||||
|
|
||||
//Expression/AdditiveExpression[not(./PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral='true'])]
|
||||
//Expression/AdditiveExpression[not(./PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral= true()])]
|
||||
/PrimaryExpression[1]/PrimaryPrefix/Expression[
|
||||
count(*)=1 and
|
||||
not(./CastExpression) and
|
||||
@ -2093,9 +2094,9 @@ public class Foo {
|
||||
<![CDATA[
|
||||
//PrimaryExpression
|
||||
[PrimaryPrefix/Name[@Image]]
|
||||
[PrimarySuffix[@Arguments='false' and @ArrayDereference = 'false']]
|
||||
[PrimarySuffix[@Arguments= false() and @ArrayDereference = false()]]
|
||||
[not(PrimarySuffix/MemberSelector)]
|
||||
[ancestor::ClassOrInterfaceBodyDeclaration[1][@AnonymousInnerClass='false']]
|
||||
[ancestor::ClassOrInterfaceBodyDeclaration[1][@AnonymousInnerClass= false()]]
|
||||
/PrimaryPrefix/Name[@Image = ancestor::ClassOrInterfaceDeclaration[1]/@SimpleName]
|
||||
]]>
|
||||
</value>
|
||||
|
@ -27,7 +27,7 @@ protected constructor in order to prevent instantiation than make the class misl
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration
|
||||
[@Abstract = 'true']
|
||||
[@Abstract = true()]
|
||||
[count(//MethodDeclaration) + count(//ConstructorDeclaration) = 0]
|
||||
[not(../Annotation/MarkerAnnotation/Name[pmd-java:typeIs('com.google.auto.value.AutoValue')])]
|
||||
]]>
|
||||
@ -339,9 +339,9 @@ is invoked by a inner class.
|
||||
<value>
|
||||
<![CDATA[
|
||||
TypeDeclaration[count(../TypeDeclaration) = 1]/ClassOrInterfaceDeclaration
|
||||
[@Final = 'false']
|
||||
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private = 'true']) >= 1 ]
|
||||
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[(@Public = 'true') or (@Protected = 'true') or (@PackagePrivate = 'true')]) = 0 ]
|
||||
[@Final = false()]
|
||||
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private = true()]) >= 1 ]
|
||||
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[(@Public = true()) or (@Protected = true()) or (@PackagePrivate = true())]) = 0 ]
|
||||
[not(.//ClassOrInterfaceDeclaration)]
|
||||
]]>
|
||||
</value>
|
||||
@ -370,12 +370,12 @@ Sometimes two consecutive 'if' statements can be consolidated by separating thei
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[@Else='false']/Statement
|
||||
/IfStatement[@Else='false']
|
||||
//IfStatement[@Else= false()]/Statement
|
||||
/IfStatement[@Else= false()]
|
||||
|
|
||||
//IfStatement[@Else='false']/Statement
|
||||
//IfStatement[@Else= false()]/Statement
|
||||
/Block[count(BlockStatement)=1]/BlockStatement
|
||||
/Statement/IfStatement[@Else='false']
|
||||
/Statement/IfStatement[@Else= false()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -727,7 +727,7 @@ in each object at runtime.
|
||||
<value>
|
||||
<![CDATA[
|
||||
//FieldDeclaration
|
||||
[@Final='true' and @Static='false']
|
||||
[@Final= true() and @Static= false()]
|
||||
/VariableDeclarator/VariableInitializer/Expression
|
||||
/PrimaryExpression[not(PrimarySuffix)]/PrimaryPrefix/Literal
|
||||
]]>
|
||||
@ -1373,7 +1373,7 @@ ConditionalAndExpression
|
||||
[EqualityExpression[@Image='!=']//NullLiteral
|
||||
and
|
||||
InstanceOfExpression
|
||||
[PrimaryExpression[count(PrimarySuffix[@ArrayDereference='true'])=0]
|
||||
[PrimaryExpression[count(PrimarySuffix[@ArrayDereference= true()])=0]
|
||||
//Name[not(contains(@Image,'.'))]/@Image = ancestor::ConditionalAndExpression
|
||||
/EqualityExpression/PrimaryExpression/PrimaryPrefix/Name/@Image]
|
||||
and
|
||||
|
@ -94,8 +94,8 @@ and unintentional empty constructors.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ConstructorDeclaration[@Private='false']
|
||||
[count(BlockStatement) = 0 and ($ignoreExplicitConstructorInvocation = 'true' or not(ExplicitConstructorInvocation)) and @containsComment = 'false']
|
||||
//ConstructorDeclaration[@Private= false()]
|
||||
[count(BlockStatement) = 0 and ($ignoreExplicitConstructorInvocation = true() or not(ExplicitConstructorInvocation)) and @containsComment = false()]
|
||||
[not(../Annotation/MarkerAnnotation/Name[pmd-java:typeIs('javax.inject.Inject')])]
|
||||
]]>
|
||||
</value>
|
||||
@ -128,7 +128,7 @@ empty methods.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclaration/Block[count(BlockStatement) = 0 and @containsComment = 'false']
|
||||
//MethodDeclaration/Block[count(BlockStatement) = 0 and @containsComment = false()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -734,7 +734,7 @@ public String bar(String string) {
|
||||
@Name='onStart'
|
||||
]
|
||||
/Block[not(
|
||||
(BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name]))]
|
||||
(BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier= true()]]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name]))]
|
||||
[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
|
||||
pmd-java:typeIs('android.app.Activity') or
|
||||
pmd-java:typeIs('android.app.Application') or
|
||||
@ -779,7 +779,7 @@ Super should be called at the end of the method
|
||||
@Name='onTerminate'
|
||||
]
|
||||
/Block/BlockStatement[last()]
|
||||
[not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name])]
|
||||
[not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier= true()]]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name])]
|
||||
[ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[
|
||||
pmd-java:typeIs('android.app.Activity') or
|
||||
pmd-java:typeIs('android.app.Application') or
|
||||
@ -892,7 +892,7 @@ Object.clone (which is protected) with a public method."
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclaration[@Public='false']
|
||||
//MethodDeclaration[@Public= false()]
|
||||
[@Name = 'clone']
|
||||
[@Arity = 0]
|
||||
]]>
|
||||
@ -1013,7 +1013,7 @@ and count(NameList/Name[contains
|
||||
(@Image,'CloneNotSupportedException')]) = 0
|
||||
]
|
||||
[
|
||||
../../../../ClassOrInterfaceDeclaration[@Final = 'false']
|
||||
../../../../ClassOrInterfaceDeclaration[@Final = false()]
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
@ -1474,7 +1474,7 @@ or reported.
|
||||
<value>
|
||||
<![CDATA[
|
||||
//CatchStatement
|
||||
[count(Block/BlockStatement) = 0 and ($allowCommentedBlocks != 'true' or Block/@containsComment = 'false')]
|
||||
[count(Block/BlockStatement) = 0 and ($allowCommentedBlocks != true() or Block/@containsComment = false())]
|
||||
[FormalParameter/Type/ReferenceType
|
||||
/ClassOrInterfaceType[@Image != 'InterruptedException' and @Image != 'CloneNotSupportedException']
|
||||
]
|
||||
@ -1882,13 +1882,13 @@ a block whose last statement is NOT a call to super.finalize -->
|
||||
/Block
|
||||
/BlockStatement[last()]
|
||||
[not(Statement/StatementExpression/PrimaryExpression
|
||||
[./PrimaryPrefix[@SuperModifier='true']]
|
||||
[./PrimaryPrefix[@SuperModifier= true()]]
|
||||
[./PrimarySuffix[@Image='finalize']]
|
||||
)
|
||||
]
|
||||
[not(Statement/TryStatement/FinallyStatement
|
||||
/Block/BlockStatement/Statement/StatementExpression/PrimaryExpression
|
||||
[./PrimaryPrefix[@SuperModifier='true']]
|
||||
[./PrimaryPrefix[@SuperModifier= true()]]
|
||||
[./PrimarySuffix[@Image='finalize']]
|
||||
)
|
||||
]
|
||||
@ -1924,7 +1924,7 @@ If the finalize() is implemented, it should do something besides just calling su
|
||||
/Block[count(BlockStatement)=1]
|
||||
/BlockStatement[
|
||||
Statement/StatementExpression/PrimaryExpression
|
||||
[./PrimaryPrefix[@SuperModifier='true']]
|
||||
[./PrimaryPrefix[@SuperModifier= true()]]
|
||||
[./PrimarySuffix[@Image='finalize']]
|
||||
]
|
||||
]]>
|
||||
@ -1990,7 +1990,7 @@ Note that Oracle has declared Object.finalize() as deprecated since JDK 9.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclaration[@Protected="false"][@Name='finalize'][@Arity = 0]
|
||||
//MethodDeclaration[@Protected=false()][@Name='finalize'][@Arity = 0]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -2199,7 +2199,7 @@ The suite() method in a JUnit test needs to be both public and static.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclaration[not(@Static='true') or not(@Public='true')]
|
||||
//MethodDeclaration[not(@Static= true()) or not(@Public= true())]
|
||||
[@Name='suite']
|
||||
[@Arity = 0]
|
||||
[ancestor::ClassOrInterfaceDeclaration[//ClassOrInterfaceType[pmd-java:typeIs('junit.framework.TestCase')]
|
||||
@ -2248,7 +2248,7 @@ The rule is replaced by {% rule java/errorprone/ProperLogger %}.
|
||||
[../Type/ReferenceType
|
||||
/ClassOrInterfaceType[@Image='Logger']
|
||||
and
|
||||
(..[@Final='false'] or ..[@Static = 'false'] ) ]
|
||||
(..[@Final= false()] or ..[@Static = false()] ) ]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -2372,7 +2372,7 @@ may indicate problematic behaviour. Empty cases are ignored as these indicate an
|
||||
+ count(BlockStatement//Statement/ReturnStatement)
|
||||
+ count(BlockStatement//Statement/ContinueStatement)
|
||||
+ count(BlockStatement//Statement/ThrowStatement)
|
||||
+ count(BlockStatement//Statement/IfStatement[@Else='true' and Statement[2][ReturnStatement|ContinueStatement|ThrowStatement]]/Statement[1][ReturnStatement|ContinueStatement|ThrowStatement])
|
||||
+ count(BlockStatement//Statement/IfStatement[@Else= true() and Statement[2][ReturnStatement|ContinueStatement|ThrowStatement]]/Statement[1][ReturnStatement|ContinueStatement|ThrowStatement])
|
||||
+ count(SwitchLabel[name(following-sibling::node()) = 'SwitchLabel'])
|
||||
+ count(SwitchLabel[count(following-sibling::node()) = 0])
|
||||
< count (SwitchLabel))]
|
||||
@ -2421,7 +2421,7 @@ chain needs an own serialVersionUID field. See also [Should an abstract class ha
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration
|
||||
[@Interface = 'false']
|
||||
[@Interface = false()]
|
||||
[count(ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
|
||||
/FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Image='serialVersionUID']) = 0]
|
||||
[(ImplementsList | ExtendsList)/ClassOrInterfaceType[pmd-java:typeIs('java.io.Serializable')]]
|
||||
@ -2460,14 +2460,13 @@ See the property `annotations`.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration[@Nested=false()]
|
||||
//ClassOrInterfaceDeclaration[@Nested= false()]
|
||||
[
|
||||
(
|
||||
(: at least one constructor :)
|
||||
./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration
|
||||
and
|
||||
(: only private constructors :)
|
||||
count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration) = count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private=true()])
|
||||
(: only private constructors :)count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration) = count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private= true()])
|
||||
and
|
||||
(: all constructors must not be annotated :)
|
||||
(every $x in $annotations satisfies
|
||||
@ -2475,24 +2474,20 @@ See the property `annotations`.
|
||||
../Annotation/MarkerAnnotation/Name[pmd-java:typeIs($x)]))
|
||||
)
|
||||
and
|
||||
(: no static methods :)
|
||||
not(.//MethodDeclaration[@Static=true()])
|
||||
(: no static methods :)not(.//MethodDeclaration[@Static= true()])
|
||||
and
|
||||
(: no (public, package-private, protected) static fields :)
|
||||
not(.//FieldDeclaration[@Private=false()][@Static=true()])
|
||||
(: no (public, package-private, protected) static fields :)not(.//FieldDeclaration[@Private= false()][@Static= true()])
|
||||
and
|
||||
(: no nested classes, that are public and static, and have no constructors at all or a public constructor :)
|
||||
(: and have a method returning the outer class type :)
|
||||
(: or the inner class extends the outer class :)
|
||||
not(.//ClassOrInterfaceDeclaration[@Nested=true()]
|
||||
[@Public=true()]
|
||||
[@Static=true()]
|
||||
[not(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration)
|
||||
or ./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Public=true()]]
|
||||
(: or the inner class extends the outer class :)not(.//ClassOrInterfaceDeclaration[@Nested= true()]
|
||||
[@Public= true()]
|
||||
[@Static= true()]
|
||||
[not(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration) or ./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Public= true()]]
|
||||
[(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/MethodDeclaration
|
||||
[@Public=true()]
|
||||
[@Public= true()]
|
||||
[./ResultType/Type/ReferenceType/ClassOrInterfaceType
|
||||
[@Image = //ClassOrInterfaceDeclaration[@Nested=false()]/@SimpleName]
|
||||
[@Image = //ClassOrInterfaceDeclaration[@Nested= false()]/@SimpleName]
|
||||
]
|
||||
) or (
|
||||
./ExtendsList/ClassOrInterfaceType[@Image = //ClassOrInterfaceDeclaration[@Nested=false()]/@SimpleName]
|
||||
@ -2788,7 +2783,7 @@ NullPointerExceptions.
|
||||
<![CDATA[
|
||||
//MethodDeclaration
|
||||
[
|
||||
(./ResultType/Type[@ArrayType='true'])
|
||||
(./ResultType/Type[@ArrayType= true()])
|
||||
and
|
||||
(./Block/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal/NullLiteral)
|
||||
]
|
||||
@ -2967,9 +2962,9 @@ behavior especially when instances are distributed by the container on several J
|
||||
)
|
||||
and
|
||||
(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration[
|
||||
(./FieldDeclaration[@Static = 'true'])
|
||||
(./FieldDeclaration[@Static = true()])
|
||||
and
|
||||
(./FieldDeclaration[@Final = 'false'])
|
||||
(./FieldDeclaration[@Final = false()])
|
||||
])
|
||||
]
|
||||
]]>
|
||||
@ -3377,7 +3372,7 @@ To make sure the full stacktrace is printed out, use the logging statement with
|
||||
concat(ancestor::ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
|
||||
[Type//ClassOrInterfaceType[@Image='Log']]
|
||||
/VariableDeclarator/VariableDeclaratorId/@Image, '.'))]]
|
||||
[PrimarySuffix/Arguments[@Size='1']]
|
||||
[PrimarySuffix/Arguments[@Size= 1]]
|
||||
[PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Image]
|
||||
]]>
|
||||
</value>
|
||||
|
@ -23,7 +23,7 @@ gets it.
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>//MethodDeclaration[@Synchronized='true']</value>
|
||||
<value>//MethodDeclaration[@Synchronized= true()]</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
@ -102,7 +102,7 @@ the volatile keyword should not be used for maintenance purpose and portability.
|
||||
<priority>2</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>//FieldDeclaration[contains(@Volatile,'true')]</value>
|
||||
<value>//FieldDeclaration[@Volatile = true()]</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
@ -379,7 +379,7 @@ one is chosen. The thread chosen is arbitrary; thus its usually safer to call n
|
||||
<value>
|
||||
<![CDATA[
|
||||
//StatementExpression/PrimaryExpression
|
||||
[PrimarySuffix/Arguments[@Size = '0']]
|
||||
[PrimarySuffix/Arguments[@Size = 0]]
|
||||
[
|
||||
PrimaryPrefix[
|
||||
./Name[@Image='notify' or ends-with(@Image,'.notify')]
|
||||
|
@ -850,7 +850,7 @@ You must use new ArrayList<>(Arrays.asList(...)) if that is inconvenient for you
|
||||
<value>
|
||||
<![CDATA[
|
||||
//Statement[
|
||||
(ForStatement) and (ForStatement//VariableInitializer//Literal[@IntLiteral='true' and @Image='0']) and (count(.//IfStatement)=0)
|
||||
(ForStatement) and (ForStatement//VariableInitializer//Literal[@IntLiteral= true() and @Image='0']) and (count(.//IfStatement)=0)
|
||||
]
|
||||
//StatementExpression[
|
||||
PrimaryExpression/PrimaryPrefix/Name[
|
||||
@ -870,7 +870,7 @@ You must use new ArrayList<>(Arrays.asList(...)) if that is inconvenient for you
|
||||
and
|
||||
PrimaryExpression/PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Name
|
||||
[
|
||||
@Image = ancestor::MethodDeclaration[1]//LocalVariableDeclaration/VariableDeclarator/VariableDeclaratorId[@ArrayType="true"]/@Image
|
||||
@Image = ancestor::MethodDeclaration[1]//LocalVariableDeclaration/VariableDeclarator/VariableDeclaratorId[@ArrayType=true()]/@Image
|
||||
or
|
||||
@Image = ancestor::MethodDeclaration[1]//FormalParameter/VariableDeclaratorId/@Image
|
||||
]
|
||||
|
@ -82,7 +82,7 @@ Global variables can lead to side-effects that are hard to debug.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//Assignment[Name/@GlobalName = 'true']
|
||||
//Assignment[Name/@GlobalName = true()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -25,17 +25,17 @@ indicative of the bug where the assignment operator '=' was used instead of the
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[$allowIf = "false"]/child::node()[1]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = "false" and (@Image = "--" or @Image = "++")]]
|
||||
//IfStatement[$allowIf = false()]/child::node()[1]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = false() and (@Image = "--" or @Image = "++")]]
|
||||
|
|
||||
//WhileLoop[$allowWhile = "false"]/child::node()[1]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = "false" and (@Image = "--" or @Image = "++")]]
|
||||
//WhileLoop[$allowWhile = false()]/child::node()[1]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = false() and (@Image = "--" or @Image = "++")]]
|
||||
|
|
||||
//DoLoop[$allowWhile = "false"]/child::node()[2]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = "false" and (@Image = "--" or @Image = "++")]]
|
||||
//DoLoop[$allowWhile = false()]/child::node()[2]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = false() and (@Image = "--" or @Image = "++")]]
|
||||
|
|
||||
//ForLoop[$allowFor = "false"]/child::node()[2]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = "false" and (@Image = "--" or @Image = "++")]]
|
||||
//ForLoop[$allowFor = false()]/child::node()[2]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = false() and (@Image = "--" or @Image = "++")]]
|
||||
|
|
||||
//ConditionalExpression[$allowTernary = "false"]/child::node()[1]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = "false" and (@Image = "--" or @Image = "++")]]
|
||||
//ConditionalExpression[$allowTernary = false()]/child::node()[1]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = false() and (@Image = "--" or @Image = "++")]]
|
||||
|
|
||||
//ConditionalExpression[$allowTernaryResults = "false"]/child::node()[position() = 2 or position() = 3]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = "false" and (@Image = "--" or @Image = "++")]]
|
||||
//ConditionalExpression[$allowTernaryResults = false()]/child::node()[position() = 2 or position() = 3]/descendant-or-self::node()[self::Assignment or self::UnaryExpression[$allowIncrementDecrement = false() and (@Image = "--" or @Image = "++")]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -110,7 +110,7 @@ Avoid using if..else statements without using curly braces.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ExpressionStatement[parent::IfStatement[@Else = "true"]]
|
||||
//ExpressionStatement[parent::IfStatement[@Else = true()]]
|
||||
[not(child::Scope)]
|
||||
[not(child::IfStatement)]
|
||||
]]>
|
||||
@ -149,7 +149,7 @@ Avoid using if statements without using curly braces.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[@Else = "false" and not(child::Scope)]
|
||||
//IfStatement[@Else = false() and not(child::Scope)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -23,9 +23,9 @@ This rule helps improve code portability due to differences in browser treatment
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ObjectLiteral[$allowObjectLiteral = "false" and @TrailingComma = 'true']
|
||||
//ObjectLiteral[$allowObjectLiteral = false() and @TrailingComma = true()]
|
||||
|
|
||||
//ArrayLiteral[$allowArrayLiteral = "false" and @TrailingComma = 'true']
|
||||
//ArrayLiteral[$allowArrayLiteral = false() and @TrailingComma = true()]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -62,7 +62,7 @@ same type. The === operator avoids the casting.
|
||||
<![CDATA[
|
||||
//InfixExpression[(@Image = "==" or @Image = "!=")
|
||||
and
|
||||
(child::KeywordLiteral[@Image = "true" or @Image = "false"]
|
||||
(child::KeywordLiteral[@Image = true() or @Image = false()]
|
||||
or
|
||||
child::NumberLiteral)
|
||||
]
|
||||
|
@ -150,13 +150,13 @@ In case you have loops please name the loop variables more meaningful.
|
||||
<value>
|
||||
<![CDATA[
|
||||
//CursorForLoopStatement[
|
||||
$allowSimpleLoops = 'false' or
|
||||
$allowSimpleLoops = false() or
|
||||
(Statement//CursorForLoopStatement or ancestor::CursorForLoopStatement)
|
||||
]
|
||||
/ForIndex[not(matches(@Image, $cursorPattern))]
|
||||
|
|
||||
//ForStatement[
|
||||
$allowSimpleLoops = 'false' or
|
||||
$allowSimpleLoops = false() or
|
||||
(Statement//ForStatement or ancestor::ForStatement)
|
||||
]
|
||||
/ForIndex[not(matches(@Image, $indexPattern))]
|
||||
|
@ -38,7 +38,7 @@ cutting through 100% of the document.
|
||||
or
|
||||
contains(@select,'descendant-self::')
|
||||
or (
|
||||
($checkSelfDescendantAbreviation = 'true' )
|
||||
($checkSelfDescendantAbreviation = true() )
|
||||
and
|
||||
contains(@select,'//')
|
||||
)
|
||||
|
Reference in New Issue
Block a user