mirror of
https://github.com/alibaba/p3c.git
synced 2025-10-14 15:10:54 +00:00
p3c-pmd 2.1.0
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>com.alibaba.p3c</groupId>
|
<groupId>com.alibaba.p3c</groupId>
|
||||||
<artifactId>p3c-pmd</artifactId>
|
<artifactId>p3c-pmd</artifactId>
|
||||||
<version>2.0.1</version>
|
<version>2.1.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>p3c-pmd</name>
|
<name>p3c-pmd</name>
|
||||||
<properties>
|
<properties>
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<pmd.version>6.15.0</pmd.version>
|
<pmd.version>6.15.0</pmd.version>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<annotation.version>1.3.2</annotation.version>
|
<annotation.version>1.3.2</annotation.version>
|
||||||
<kotlin.version>1.3.50</kotlin.version>
|
<kotlin.version>1.3.72</kotlin.version>
|
||||||
</properties>
|
</properties>
|
||||||
<description>Alibaba Java Coding Guidelines PMD implementations</description>
|
<description>Alibaba Java Coding Guidelines PMD implementations</description>
|
||||||
<url>https://github.com/alibaba/p3c</url>
|
<url>https://github.com/alibaba/p3c</url>
|
||||||
|
@@ -48,7 +48,10 @@ public class WrapperTypeEqualityRule extends AbstractAliRule {
|
|||||||
// PMD can not resolve array length type, but only the
|
// PMD can not resolve array length type, but only the
|
||||||
ASTPrimaryExpression left = expressions.get(0);
|
ASTPrimaryExpression left = expressions.get(0);
|
||||||
ASTPrimaryExpression right = expressions.get(1);
|
ASTPrimaryExpression right = expressions.get(1);
|
||||||
|
// if left is complex expression, skip
|
||||||
|
if (left.jjtGetNumChildren() > 1) {
|
||||||
|
return super.visit(node, data);
|
||||||
|
}
|
||||||
boolean bothArrayLength = isArrayLength(left) && isArrayLength(right);
|
boolean bothArrayLength = isArrayLength(left) && isArrayLength(right);
|
||||||
boolean bothWrapperType = NodeUtils.isWrapperType(left) && NodeUtils.isWrapperType(right);
|
boolean bothWrapperType = NodeUtils.isWrapperType(left) && NodeUtils.isWrapperType(right);
|
||||||
|
|
||||||
@@ -61,7 +64,8 @@ public class WrapperTypeEqualityRule extends AbstractAliRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isArrayLength(ASTPrimaryExpression expression) {
|
private boolean isArrayLength(ASTPrimaryExpression expression) {
|
||||||
// assume expression like "x.length" is the length of array, field with name "length" may result in misrecognition
|
// assume expression like "x.length" is the length of array, field with name "length" may result in
|
||||||
|
// misrecognition
|
||||||
return "length".equals(expression.jjtGetLastToken().getImage())
|
return "length".equals(expression.jjtGetLastToken().getImage())
|
||||||
&& ".".equals(expression.jjtGetFirstToken().getNext().getImage());
|
&& ".".equals(expression.jjtGetFirstToken().getNext().getImage());
|
||||||
}
|
}
|
||||||
|
@@ -171,7 +171,37 @@
|
|||||||
<expected-problems>0</expected-problems>
|
<expected-problems>0</expected-problems>
|
||||||
<code-ref id="array-length-equals"/>
|
<code-ref id="array-length-equals"/>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
<code-fragment id="expression-primitive-equals">
|
||||||
|
<![CDATA[
|
||||||
|
public class Test {
|
||||||
|
public void foo(){
|
||||||
|
int a;
|
||||||
|
if (Integer.parseInt("0") == a) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (a == Integer.parseInt("0")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String s = "0";
|
||||||
|
if (Integer.parseInt("0") == Integer.parseInt(s)) {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
Integer b;
|
||||||
|
if (b == Integer.parseInt("0")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</code-fragment>
|
||||||
|
<test-code>
|
||||||
|
<description>expression is primitive type</description>
|
||||||
|
<expected-problems>1</expected-problems>
|
||||||
|
<expected-linenumbers>17</expected-linenumbers>
|
||||||
|
<code-ref id="expression-primitive-equals"/>
|
||||||
|
</test-code>
|
||||||
<!-- ====================================================================== -->
|
<!-- ====================================================================== -->
|
||||||
|
|
||||||
</test-data>
|
</test-data>
|
Reference in New Issue
Block a user