[java] Fix more deprecated attribute usages
This commit is contained in:
@ -229,7 +229,7 @@ public class ForLoopCanBeForeachRule extends AbstractJavaRule {
|
||||
+ "/Name[matches(@Image,'\\w+\\.(size|length)')]"
|
||||
+ "|"
|
||||
+ "./RelationalExpression[@Image='<=']/AdditiveExpression[count(*)=2 and "
|
||||
+ "@Image='-' and PrimaryExpression/PrimaryPrefix/Literal[@Image='1']]"
|
||||
+ "@Operator='-' and PrimaryExpression/PrimaryPrefix/Literal[@Image='1']]"
|
||||
+ "/PrimaryExpression/PrimaryPrefix/Name[matches(@Image,'\\w+\\.(size|length)')]");
|
||||
|
||||
if (left.isEmpty()) {
|
||||
|
@ -164,7 +164,7 @@ by the more general rule {% rule java/codestyle/FormalParameterNamingConventions
|
||||
<value>
|
||||
<![CDATA[
|
||||
//MethodDeclaration/MethodDeclarator/FormalParameters/FormalParameter/VariableDeclaratorId[
|
||||
pmd:matches(@VariableName,'^in[A-Z].*','^out[A-Z].*','^in$','^out$')
|
||||
pmd:matches(@Name,'^in[A-Z].*','^out[A-Z].*','^in$','^out$')
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
@ -1364,7 +1364,7 @@ by the more general rule
|
||||
<value>
|
||||
<![CDATA[
|
||||
//VariableDeclaratorId
|
||||
[starts-with(@Image, 'm_')]
|
||||
[starts-with(@Name, 'm_')]
|
||||
[not (../../../FieldDeclaration)]
|
||||
]]>
|
||||
</value>
|
||||
@ -1758,7 +1758,7 @@ by the more general rule {% rule java/codestyle/FieldNamingConventions %}.
|
||||
//ClassOrInterfaceDeclaration[@Interface= false()]
|
||||
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
|
||||
[@Final= false()]
|
||||
[VariableDeclarator/VariableDeclaratorId[upper-case(@Image)=@Image]]
|
||||
[VariableDeclarator/VariableDeclaratorId[upper-case(@Name)=@Name]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
@ -2067,7 +2067,7 @@ List<String> stringsWithDiamond = new ArrayList<>(); // using the diamond operat
|
||||
/PrimaryExpression[1]/PrimaryPrefix/Expression[
|
||||
count(*)=1 and
|
||||
not(./CastExpression) and
|
||||
not(./AdditiveExpression[@Image = '-']) and
|
||||
not(./AdditiveExpression[@Operator = '-']) and
|
||||
not(./ShiftExpression) and
|
||||
not(./RelationalExpression) and
|
||||
not(./InstanceOfExpression) and
|
||||
|
@ -133,7 +133,7 @@ Catch blocks that merely rethrow a caught exception only add to code size and ru
|
||||
<value>
|
||||
<![CDATA[
|
||||
//CatchStatement[FormalParameter
|
||||
/VariableDeclaratorId/@Image = Block/BlockStatement/Statement
|
||||
/VariableDeclaratorId/@Name = Block/BlockStatement/Statement
|
||||
/ThrowStatement/Expression/PrimaryExpression[count(PrimarySuffix)=0]/PrimaryPrefix/Name/@Image
|
||||
and count(Block/BlockStatement/Statement) =1]
|
||||
]]>
|
||||
|
@ -422,7 +422,7 @@ Each caught exception type should be handled in its own catch clause.
|
||||
/following-sibling::Block//InstanceOfExpression/PrimaryExpression/PrimaryPrefix
|
||||
/Name[
|
||||
@Image = ./ancestor::Block/preceding-sibling::FormalParameter
|
||||
/VariableDeclaratorId/@Image
|
||||
/VariableDeclaratorId/@Name
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
@ -2414,7 +2414,7 @@ chain needs an own serialVersionUID field. See also [Should an abstract class ha
|
||||
//ClassOrInterfaceDeclaration
|
||||
[@Interface = false()]
|
||||
[count(ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
|
||||
/FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Image='serialVersionUID']) = 0]
|
||||
/FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Name='serialVersionUID']) = 0]
|
||||
[(ImplementsList | ExtendsList)/ClassOrInterfaceType[pmd-java:typeIs('java.io.Serializable')]]
|
||||
]]>
|
||||
</value>
|
||||
@ -3362,11 +3362,11 @@ To make sure the full stacktrace is printed out, use the logging statement with
|
||||
[starts-with(@Image,
|
||||
concat((ancestor::ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
|
||||
[Type//ClassOrInterfaceType[@Image='Log']]
|
||||
/VariableDeclarator/VariableDeclaratorId/@Image)[1], '.'))
|
||||
/VariableDeclarator/VariableDeclaratorId/@Name)[1], '.'))
|
||||
]
|
||||
]
|
||||
[PrimarySuffix/Arguments[@Size= 1]]
|
||||
[PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Image]
|
||||
[PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Name]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -40,7 +40,7 @@ public class ReportTest extends RuleTst {
|
||||
public void testExclusionsInReportWithRuleViolationSuppressXPath() {
|
||||
Report rpt = new Report();
|
||||
Rule rule = new FooRule();
|
||||
rule.setProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR, ".[@Image = 'Foo']");
|
||||
rule.setProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR, ".[@SimpleName = 'Foo']");
|
||||
runTestFromString(TEST1, rule, rpt, defaultLanguage);
|
||||
assertTrue(rpt.isEmpty());
|
||||
assertEquals(1, rpt.getSuppressedRuleViolations().size());
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
@ -53,7 +53,7 @@ public class XPathRuleTest extends RuleTst {
|
||||
|
||||
@Test
|
||||
public void testPluginname() throws Exception {
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[string-length(@Image) < 3]");
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[string-length(@Name) < 3]");
|
||||
rule.setMessage("{0}");
|
||||
Report report = getReportForTestString(rule, TEST1);
|
||||
RuleViolation rv = report.iterator().next();
|
||||
@ -63,7 +63,7 @@ public class XPathRuleTest extends RuleTst {
|
||||
|
||||
@Test
|
||||
public void testXPathMultiProperty() throws Exception {
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[@Image=$forbiddenNames]");
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[@Name=$forbiddenNames]");
|
||||
rule.setMessage("Avoid vars");
|
||||
PropertyDescriptor<List<String>> varDescriptor
|
||||
= PropertyFactory.stringListProperty("forbiddenNames")
|
||||
@ -86,7 +86,7 @@ public class XPathRuleTest extends RuleTst {
|
||||
|
||||
@Test
|
||||
public void testVariables() throws Exception {
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[@Image=$var]");
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[@Name=$var]");
|
||||
rule.setMessage("Avoid vars");
|
||||
PropertyDescriptor<String> varDescriptor =
|
||||
PropertyFactory.stringProperty("var").desc("Test var").defaultValue("").build();
|
||||
@ -99,7 +99,7 @@ public class XPathRuleTest extends RuleTst {
|
||||
|
||||
@Test
|
||||
public void testFnPrefixOnSaxon() throws Exception {
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[fn:matches(@Image, 'fiddle')]");
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[fn:matches(@Name, 'fiddle')]");
|
||||
Report report = getReportForTestString(rule, TEST2);
|
||||
RuleViolation rv = report.iterator().next();
|
||||
assertEquals(3, rv.getBeginLine());
|
||||
@ -107,7 +107,7 @@ public class XPathRuleTest extends RuleTst {
|
||||
|
||||
@Test
|
||||
public void testNoFnPrefixOnSaxon() throws Exception {
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[matches(@Image, 'fiddle')]");
|
||||
XPathRule rule = makeXPath("//VariableDeclaratorId[matches(@Name, 'fiddle')]");
|
||||
Report report = getReportForTestString(rule, TEST2);
|
||||
RuleViolation rv = report.iterator().next();
|
||||
assertEquals(3, rv.getBeginLine());
|
||||
|
@ -452,8 +452,7 @@ public class ClassTypeResolverTest {
|
||||
ASTCompilationUnit acu = java5.parseClass(Promotion.class);
|
||||
List<ASTExpression> expressions = convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = "
|
||||
+ "'unaryNumericPromotion']]//Expression[UnaryExpression]"),
|
||||
"//MethodDeclaration[@Name = 'unaryNumericPromotion']/Block//Expression[UnaryExpression]"),
|
||||
ASTExpression.class);
|
||||
int index = 0;
|
||||
|
||||
@ -474,8 +473,7 @@ public class ClassTypeResolverTest {
|
||||
ASTCompilationUnit acu = java5.parseClass(Promotion.class);
|
||||
List<ASTExpression> expressions = convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = "
|
||||
+ "'binaryNumericPromotion']]//Expression[AdditiveExpression]"),
|
||||
"//MethodDeclaration[@Name = 'binaryNumericPromotion']/Block//Expression[AdditiveExpression]"),
|
||||
ASTExpression.class);
|
||||
int index = 0;
|
||||
|
||||
@ -545,7 +543,7 @@ public class ClassTypeResolverTest {
|
||||
ASTCompilationUnit acu = java5.parseClass(Promotion.class);
|
||||
List<ASTExpression> expressions = convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryStringPromotion']]//Expression"),
|
||||
"//MethodDeclaration[@Name = 'binaryStringPromotion']/Block//Expression"),
|
||||
ASTExpression.class);
|
||||
int index = 0;
|
||||
|
||||
@ -564,7 +562,7 @@ public class ClassTypeResolverTest {
|
||||
ASTCompilationUnit acu = java5.parseClass(Operators.class);
|
||||
List<ASTExpression> expressions = convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryLogicalOperators']]//Expression"),
|
||||
"//MethodDeclaration[@Name = 'unaryLogicalOperators']/Block//Expression"),
|
||||
ASTExpression.class);
|
||||
int index = 0;
|
||||
|
||||
@ -580,7 +578,7 @@ public class ClassTypeResolverTest {
|
||||
ASTCompilationUnit acu = java5.parseClass(Operators.class);
|
||||
List<ASTExpression> expressions = convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryLogicalOperators']]//Expression"),
|
||||
"//MethodDeclaration[@Name = 'binaryLogicalOperators']/Block//Expression"),
|
||||
ASTExpression.class);
|
||||
int index = 0;
|
||||
|
||||
@ -606,24 +604,22 @@ public class ClassTypeResolverTest {
|
||||
public void testUnaryNumericOperators() throws JaxenException {
|
||||
ASTCompilationUnit acu = java5.parseClass(Operators.class);
|
||||
List<TypeNode> expressions = new ArrayList<>();
|
||||
final String baseXPath = "//MethodDeclaration[@Name = 'unaryNumericOperators']/Block";
|
||||
expressions.addAll(convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericOperators']]//Expression"),
|
||||
baseXPath + "//Expression"),
|
||||
TypeNode.class));
|
||||
expressions.addAll(convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = "
|
||||
+ "'unaryNumericOperators']]//PostfixExpression"),
|
||||
baseXPath + "//PostfixExpression"),
|
||||
TypeNode.class));
|
||||
expressions.addAll(convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = "
|
||||
+ "'unaryNumericOperators']]//PreIncrementExpression"),
|
||||
baseXPath + "//PreIncrementExpression"),
|
||||
TypeNode.class));
|
||||
expressions.addAll(convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = "
|
||||
+ "'unaryNumericOperators']]//PreDecrementExpression"),
|
||||
baseXPath + "//PreDecrementExpression"),
|
||||
TypeNode.class));
|
||||
|
||||
int index = 0;
|
||||
@ -643,7 +639,7 @@ public class ClassTypeResolverTest {
|
||||
ASTCompilationUnit acu = java5.parseClass(Operators.class);
|
||||
List<ASTExpression> expressions = convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryNumericOperators']]//Expression"),
|
||||
"//MethodDeclaration[@Name = 'binaryNumericOperators']/Block//Expression"),
|
||||
ASTExpression.class);
|
||||
int index = 0;
|
||||
|
||||
@ -665,8 +661,7 @@ public class ClassTypeResolverTest {
|
||||
ASTCompilationUnit acu = java5.parseClass(Operators.class);
|
||||
List<ASTStatementExpression> expressions = convertList(
|
||||
acu.findChildNodesWithXPath(
|
||||
"//Block[preceding-sibling::MethodDeclarator[@Image = "
|
||||
+ "'assignmentOperators']]//StatementExpression"),
|
||||
"//MethodDeclaration[@Name = 'assignmentOperators']/Block//StatementExpression"),
|
||||
ASTStatementExpression.class);
|
||||
int index = 0;
|
||||
|
||||
|
@ -217,7 +217,7 @@ class Foo {
|
||||
violation suppression xpath works, by name
|
||||
]]>
|
||||
</description>
|
||||
<rule-property name="violationSuppressXPath">.[@Image = 'paramB']</rule-property>
|
||||
<rule-property name="violationSuppressXPath">.[@Name = 'paramB']</rule-property>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code>
|
||||
<![CDATA[
|
||||
|
Reference in New Issue
Block a user