diff --git a/pmd-apex/src/main/resources/category/apex/codestyle.xml b/pmd-apex/src/main/resources/category/apex/codestyle.xml index 262b6f9757..72c22c83ce 100644 --- a/pmd-apex/src/main/resources/category/apex/codestyle.xml +++ b/pmd-apex/src/main/resources/category/apex/codestyle.xml @@ -48,9 +48,9 @@ from the rest. 0] +//IfBlockStatement/BlockStatement[@CurlyBrace= false()][count(child::*) > 0] | -//IfElseBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0] +//IfElseBlockStatement/BlockStatement[@CurlyBrace= false()][count(child::*) > 0] ]]> @@ -85,7 +85,7 @@ controlled from the rest. @@ -142,9 +142,9 @@ from the rest. @@ -348,7 +348,7 @@ controlled from the rest. diff --git a/pmd-apex/src/main/resources/category/apex/errorprone.xml b/pmd-apex/src/main/resources/category/apex/errorprone.xml index c96110f960..17c9182938 100644 --- a/pmd-apex/src/main/resources/category/apex/errorprone.xml +++ b/pmd-apex/src/main/resources/category/apex/errorprone.xml @@ -189,7 +189,7 @@ Empty block statements serve no purpose and should be removed. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java index 4663e7f1bf..94bec1fbb1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java @@ -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) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java index 773d64a5c0..55257976f9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java @@ -41,8 +41,8 @@ public class XPathRule extends AbstractRule { static { Map 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 VERSION_DESCRIPTOR = EnumeratedProperty.named("version") .desc("XPath specification version") .mappings(XPATH_VERSIONS) - .defaultValue(XPATH_1_0) + .defaultValue(XPATH_2_0) .type(String.class) .uiOrder(2.0f) .build(); diff --git a/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml b/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml index f158927f95..607967f6fd 100644 --- a/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml +++ b/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml @@ -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()]) ]) ] ]]> diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml index 5c089e46d7..7dd321aee1 100644 --- a/pmd-java/src/main/resources/category/java/bestpractices.xml +++ b/pmd-java/src/main/resources/category/java/bestpractices.xml @@ -27,8 +27,8 @@ directly) a protected constructor can be provided prevent direct instantiation. @@ -380,7 +380,7 @@ better placed in classes or enums. See Effective Java, item 19. @@ -426,8 +426,8 @@ By convention, the default label should be the last label in a switch statement. @@ -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 ) ] diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 6f8e3e2ae4..1cb7beabeb 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -28,12 +28,12 @@ by {% rule java/codestyle/ClassNamingConventions %}. @@ -116,7 +116,7 @@ If the goal is to avoid defining constants in a scope smaller than the class, th @@ -244,12 +244,13 @@ visibility cannot be reduced). Clarify your intent by using private or package a 3 + @@ -318,7 +319,7 @@ prefix for these methods. @@ -623,16 +624,16 @@ usage by developers who should be implementing their own versions in the concret 1 or - string:upper-case(@Image) != @Image + upper-case(@Image) != @Image ] ]]> @@ -947,7 +948,7 @@ by the rule {% rule java/codestyle/ControlStatementBraces %}. @@ -1728,9 +1729,9 @@ by the more general rule {% rule java/codestyle/FieldNamingConventions %}. @@ -1767,7 +1768,7 @@ which class a static member comes from (Sun 1.5 Language Guide). $maximumStaticImports] +.[count(ImportDeclaration[@Static = true()]) > $maximumStaticImports] ]]> @@ -1970,15 +1971,15 @@ which makes the code also more readable. @@ -2031,7 +2032,7 @@ List 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 { diff --git a/pmd-java/src/main/resources/category/java/design.xml b/pmd-java/src/main/resources/category/java/design.xml index 73008d3e30..4a3dfa92dc 100644 --- a/pmd-java/src/main/resources/category/java/design.xml +++ b/pmd-java/src/main/resources/category/java/design.xml @@ -27,7 +27,7 @@ protected constructor in order to prevent instantiation than make the class misl @@ -339,9 +339,9 @@ is invoked by a inner class. = 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)] ]]> @@ -370,12 +370,12 @@ Sometimes two consecutive 'if' statements can be consolidated by separating thei @@ -727,7 +727,7 @@ in each object at runtime. @@ -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 diff --git a/pmd-java/src/main/resources/category/java/documentation.xml b/pmd-java/src/main/resources/category/java/documentation.xml index 7b6d5cd81f..daee1d547d 100644 --- a/pmd-java/src/main/resources/category/java/documentation.xml +++ b/pmd-java/src/main/resources/category/java/documentation.xml @@ -94,8 +94,8 @@ and unintentional empty constructors. @@ -128,7 +128,7 @@ empty methods. diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 938ca51d55..3415522b1e 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -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." @@ -1013,7 +1013,7 @@ and count(NameList/Name[contains (@Image,'CloneNotSupportedException')]) = 0 ] [ -../../../../ClassOrInterfaceDeclaration[@Final = 'false'] +../../../../ClassOrInterfaceDeclaration[@Final = false()] ] ]]> @@ -1474,7 +1474,7 @@ or reported. /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. @@ -2199,7 +2199,7 @@ The suite() method in a JUnit test needs to be both public and static. @@ -2333,7 +2333,7 @@ Either the check is useless (the variable will never be "null") or it is incorre public class Foo { void bar() { if (a.equals(baz) && a != null) {} // a could be null, misplaced null check - + if (a != null && a.equals(baz)) {} // correct null check } } @@ -2344,7 +2344,7 @@ public class Foo { public class Foo { void bar() { if (a.equals(baz) || a == null) {} // a could be null, misplaced null check - + if (a == null || a.equals(baz)) {} // correct null check } } @@ -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 @@ -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] ]]> diff --git a/pmd-java/src/main/resources/category/java/multithreading.xml b/pmd-java/src/main/resources/category/java/multithreading.xml index c1ca1d5c2f..35a0d2ec5c 100644 --- a/pmd-java/src/main/resources/category/java/multithreading.xml +++ b/pmd-java/src/main/resources/category/java/multithreading.xml @@ -23,7 +23,7 @@ gets it. 3 - //MethodDeclaration[@Synchronized='true'] + //MethodDeclaration[@Synchronized= true()] @@ -102,7 +102,7 @@ the volatile keyword should not be used for maintenance purpose and portability. 2 - //FieldDeclaration[contains(@Volatile,'true')] + //FieldDeclaration[@Volatile = true()] @@ -379,7 +379,7 @@ one is chosen. The thread chosen is arbitrary; thus its usually safer to call n - \ No newline at end of file + diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index 7d0c75b226..7f1b0e4308 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -850,7 +850,7 @@ You must use new ArrayList<>(Arrays.asList(...)) if that is inconvenient for you (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 ] diff --git a/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml b/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml index 52cdac1822..a6ce322d0e 100644 --- a/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml +++ b/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml @@ -82,7 +82,7 @@ Global variables can lead to side-effects that are hard to debug. diff --git a/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml b/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml index 285262c59d..04d4e1abb2 100644 --- a/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml +++ b/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml @@ -25,17 +25,17 @@ indicative of the bug where the assignment operator '=' was used instead of the @@ -110,7 +110,7 @@ Avoid using if..else statements without using curly braces. @@ -149,7 +149,7 @@ Avoid using if statements without using curly braces. diff --git a/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml b/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml index 4b48e85dfe..a39190db2e 100644 --- a/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml +++ b/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml @@ -23,9 +23,9 @@ This rule helps improve code portability due to differences in browser treatment @@ -62,7 +62,7 @@ same type. The === operator avoids the casting.