Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wangsun300
p3c
提交
68924e36
P
p3c
项目概览
wangsun300
/
p3c
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
p3c
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
68924e36
编写于
8月 22, 2020
作者:
C
caikang.ck
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
p3c-pmd 2.1.0
上级
87ba6081
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
7 deletion
+41
-7
p3c-pmd/pom.xml
p3c-pmd/pom.xml
+2
-2
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/oop/WrapperTypeEqualityRule.java
...a/p3c/pmd/lang/java/rule/oop/WrapperTypeEqualityRule.java
+7
-3
p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/oop/xml/WrapperTypeEqualityRule.xml
...3c/pmd/lang/java/rule/oop/xml/WrapperTypeEqualityRule.xml
+32
-2
未找到文件。
p3c-pmd/pom.xml
浏览文件 @
68924e36
...
...
@@ -9,7 +9,7 @@
</parent>
<groupId>
com.alibaba.p3c
</groupId>
<artifactId>
p3c-pmd
</artifactId>
<version>
2.
0.1
</version>
<version>
2.
1.0
</version>
<packaging>
jar
</packaging>
<name>
p3c-pmd
</name>
<properties>
...
...
@@ -17,7 +17,7 @@
<pmd.version>
6.15.0
</pmd.version>
<maven.compiler.target>
1.8
</maven.compiler.target>
<annotation.version>
1.3.2
</annotation.version>
<kotlin.version>
1.3.
50
</kotlin.version>
<kotlin.version>
1.3.
72
</kotlin.version>
</properties>
<description>
Alibaba Java Coding Guidelines PMD implementations
</description>
<url>
https://github.com/alibaba/p3c
</url>
...
...
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/oop/WrapperTypeEqualityRule.java
浏览文件 @
68924e36
...
...
@@ -38,7 +38,7 @@ public class WrapperTypeEqualityRule extends AbstractAliRule {
final
String
unaryExpression
=
"UnaryExpression"
;
// null presents in either side of "==" or "!=" means no violation
if
(
node
.
hasDescendantMatchingXPath
(
literalPrefix
)
||
node
.
hasDescendantMatchingXPath
(
unaryExpression
))
{
||
node
.
hasDescendantMatchingXPath
(
unaryExpression
))
{
return
super
.
visit
(
node
,
data
);
}
...
...
@@ -48,7 +48,10 @@ public class WrapperTypeEqualityRule extends AbstractAliRule {
// PMD can not resolve array length type, but only the
ASTPrimaryExpression
left
=
expressions
.
get
(
0
);
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
bothWrapperType
=
NodeUtils
.
isWrapperType
(
left
)
&&
NodeUtils
.
isWrapperType
(
right
);
...
...
@@ -61,7 +64,8 @@ public class WrapperTypeEqualityRule extends AbstractAliRule {
}
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
())
&&
"."
.
equals
(
expression
.
jjtGetFirstToken
().
getNext
().
getImage
());
}
...
...
p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/oop/xml/WrapperTypeEqualityRule.xml
浏览文件 @
68924e36
...
...
@@ -53,7 +53,7 @@
<description>
compare wrapper type objects without equals
</description>
<expected-problems>
4
</expected-problems>
<expected-linenumbers>
11,23,31,34
</expected-linenumbers>
<code-ref
id=
"wrap-type-not-use-equal"
/>
<code-ref
id=
"wrap-type-not-use-equal"
/>
</test-code>
<!-- ====================================================================== -->
...
...
@@ -148,7 +148,7 @@
<test-code>
<description>
bugfix
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"wrong-result-fix"
/>
<code-ref
id=
"wrong-result-fix"
/>
</test-code>
<!-- ====================================================================== -->
...
...
@@ -171,7 +171,37 @@
<expected-problems>
0
</expected-problems>
<code-ref
id=
"array-length-equals"
/>
</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>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录