Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wangsun300
p3c
提交
d9792ef4
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,发现更多精彩内容 >>
提交
d9792ef4
编写于
10月 25, 2017
作者:
S
SeanCai
提交者:
GitHub
10月 25, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #138 from kerie/master
1.author标签不区分大小写,2.在有注解的情况下正确关联注释与节点
上级
2a24e024
fd58312d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
270 addition
and
148 deletion
+270
-148
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/AvoidCommentBehindStatementRule.java
...ng/java/rule/comment/AvoidCommentBehindStatementRule.java
+5
-5
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/ClassMustHaveAuthorRule.java
...c/pmd/lang/java/rule/comment/ClassMustHaveAuthorRule.java
+2
-1
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/CommentsMustBeJavadocFormatRule.java
...ng/java/rule/comment/CommentsMustBeJavadocFormatRule.java
+45
-11
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/EnumConstantsMustHaveCommentRule.java
...g/java/rule/comment/EnumConstantsMustHaveCommentRule.java
+4
-4
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java
...c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java
+8
-8
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/util/NodeSortUtils.java
...om/alibaba/p3c/pmd/lang/java/rule/util/NodeSortUtils.java
+11
-3
p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/ClassMustHaveAuthorRule.xml
...md/lang/java/rule/comment/xml/ClassMustHaveAuthorRule.xml
+88
-68
p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/CommentsMustBeJavadocFormatRule.xml
...java/rule/comment/xml/CommentsMustBeJavadocFormatRule.xml
+107
-48
未找到文件。
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/AvoidCommentBehindStatementRule.java
浏览文件 @
d9792ef4
...
...
@@ -21,7 +21,7 @@ import java.util.SortedMap;
import
java.util.TreeMap
;
import
com.alibaba.p3c.pmd.I18nResources
;
import
com.alibaba.p3c.pmd.lang.java.rule.util.
Commen
tUtils
;
import
com.alibaba.p3c.pmd.lang.java.rule.util.
NodeSor
tUtils
;
import
net.sourceforge.pmd.lang.ast.Node
;
import
net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit
;
...
...
@@ -75,19 +75,19 @@ public class AvoidCommentBehindStatementRule extends AbstractAliCommentRule {
// expression nodes
List
<
ASTExpression
>
expressionNodes
=
cUnit
.
findDescendantsOfType
(
ASTExpression
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
expressionNodes
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
expressionNodes
);
// filed declaration nodes
List
<
ASTFieldDeclaration
>
fieldNodes
=
cUnit
.
findDescendantsOfType
(
ASTFieldDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
fieldNodes
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
fieldNodes
);
// enum constant nodes
List
<
ASTEnumConstant
>
enumConstantNodes
=
cUnit
.
findDescendantsOfType
(
ASTEnumConstant
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
enumConstantNodes
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
enumConstantNodes
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
cUnit
.
getComments
());
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
cUnit
.
getComments
());
return
itemsByLineNumber
;
}
...
...
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/ClassMustHaveAuthorRule.java
浏览文件 @
d9792ef4
...
...
@@ -34,7 +34,8 @@ import net.sourceforge.pmd.lang.java.ast.Comment;
*/
public
class
ClassMustHaveAuthorRule
extends
AbstractAliCommentRule
{
private
static
final
Pattern
AUTHOR_PATTERN
=
Pattern
.
compile
(
".*@author.*"
,
Pattern
.
DOTALL
);
private
static
final
Pattern
AUTHOR_PATTERN
=
Pattern
.
compile
(
".*@author.*"
,
Pattern
.
DOTALL
|
Pattern
.
CASE_INSENSITIVE
);
private
static
final
String
MESSAGE_KEY_PREFIX
=
"java.comment.ClassMustHaveAuthorRule.violation.msg"
;
...
...
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/CommentsMustBeJavadocFormatRule.java
浏览文件 @
d9792ef4
...
...
@@ -16,15 +16,17 @@
package
com.alibaba.p3c.pmd.lang.java.rule.comment
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map.Entry
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
import
com.alibaba.p3c.pmd.I18nResources
;
import
com.alibaba.p3c.pmd.lang.java.rule.util.
Commen
tUtils
;
import
com.alibaba.p3c.pmd.lang.java.rule.util.
NodeSor
tUtils
;
import
net.sourceforge.pmd.lang.ast.Node
;
import
net.sourceforge.pmd.lang.java.ast.ASTAnnotation
;
import
net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration
;
import
net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration
;
import
net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit
;
...
...
@@ -43,7 +45,7 @@ import org.apache.commons.lang3.StringUtils;
/**
* [Mandatory] Javadoc should be used for classes, class variables and methods.
* The format should be '\/** comment *
*
\/', rather than '// xxx'.
* The format should be '\/** comment *\/', rather than '// xxx'.
*
* @author keriezhang
* @date 2016/12/14
...
...
@@ -155,8 +157,13 @@ public class CommentsMustBeJavadocFormatRule extends AbstractAliCommentRule {
if
(
value
instanceof
AbstractJavaNode
)
{
AbstractJavaNode
node
=
(
AbstractJavaNode
)
value
;
// skip annotation node, we will deal with it later.
if
(
node
instanceof
ASTAnnotation
)
{
continue
;
}
// Check if comment is one line above class, field, method.
if
(
lastComment
!=
null
&&
isCommentOneLineBefore
(
lastComment
,
lastNode
,
node
))
{
if
(
lastComment
!=
null
&&
isCommentOneLineBefore
(
itemsByLineNumber
,
lastComment
,
lastNode
,
node
))
{
node
.
comment
(
lastComment
);
lastComment
=
null
;
}
...
...
@@ -172,28 +179,31 @@ public class CommentsMustBeJavadocFormatRule extends AbstractAliCommentRule {
SortedMap
<
Integer
,
Node
>
itemsByLineNumber
=
new
TreeMap
<>();
CommentUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
cUnit
.
getComments
());
NodeSortUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
cUnit
.
getComments
());
List
<
ASTAnnotation
>
annotations
=
cUnit
.
findDescendantsOfType
(
ASTAnnotation
.
class
);
NodeSortUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
annotations
);
List
<
ASTClassOrInterfaceDeclaration
>
classDecl
=
cUnit
.
findDescendantsOfType
(
ASTClassOrInterfaceDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
classDecl
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
classDecl
);
List
<
ASTFieldDeclaration
>
fields
=
cUnit
.
findDescendantsOfType
(
ASTFieldDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
fields
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
fields
);
List
<
ASTMethodDeclaration
>
methods
=
cUnit
.
findDescendantsOfType
(
ASTMethodDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
methods
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
methods
);
List
<
ASTConstructorDeclaration
>
constructors
=
cUnit
.
findDescendantsOfType
(
ASTConstructorDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
constructors
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
constructors
);
List
<
ASTEnumDeclaration
>
enumDecl
=
cUnit
.
findDescendantsOfType
(
ASTEnumDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
enumDecl
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
enumDecl
);
return
itemsByLineNumber
;
}
private
boolean
isCommentOneLineBefore
(
Comment
lastComment
,
Node
lastNode
,
Node
node
)
{
private
boolean
isCommentOneLineBefore
(
SortedMap
<
Integer
,
Node
>
items
,
Comment
lastComment
,
Node
lastNode
,
Node
node
)
{
ASTClassOrInterfaceBodyDeclaration
parentClass
=
node
.
getFirstParentOfType
(
ASTClassOrInterfaceBodyDeclaration
.
class
);
...
...
@@ -207,7 +217,31 @@ public class CommentsMustBeJavadocFormatRule extends AbstractAliCommentRule {
return
false
;
}
return
lastComment
.
getEndLine
()
+
1
==
node
.
getBeginLine
();
// check if there is nothing in the middle except annotations.
SortedMap
<
Integer
,
Node
>
subMap
=
items
.
subMap
(
NodeSortUtils
.
generateIndex
(
lastComment
),
NodeSortUtils
.
generateIndex
(
node
));
Iterator
<
Entry
<
Integer
,
Node
>>
iter
=
subMap
.
entrySet
().
iterator
();
// skip the first comment node.
iter
.
next
();
int
lastEndLine
=
lastComment
.
getEndLine
();
while
(
iter
.
hasNext
())
{
Entry
<
Integer
,
Node
>
entry
=
iter
.
next
();
Node
value
=
entry
.
getValue
();
// only annotation node is allowed between comment and node.
if
(!(
value
instanceof
ASTAnnotation
))
{
return
false
;
}
// allow annotation node after comment.
if
(
lastEndLine
+
1
==
value
.
getBeginLine
())
{
lastEndLine
=
value
.
getEndLine
();
}
}
return
lastEndLine
+
1
==
node
.
getBeginLine
();
}
/**
...
...
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/EnumConstantsMustHaveCommentRule.java
浏览文件 @
d9792ef4
...
...
@@ -21,7 +21,7 @@ import java.util.SortedMap;
import
java.util.TreeMap
;
import
com.alibaba.p3c.pmd.I18nResources
;
import
com.alibaba.p3c.pmd.lang.java.rule.util.
Commen
tUtils
;
import
com.alibaba.p3c.pmd.lang.java.rule.util.
NodeSor
tUtils
;
import
net.sourceforge.pmd.lang.ast.Node
;
import
net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit
;
...
...
@@ -65,12 +65,12 @@ public class EnumConstantsMustHaveCommentRule extends AbstractAliCommentRule {
SortedMap
<
Integer
,
Node
>
itemsByLineNumber
=
new
TreeMap
<>();
List
<
ASTEnumDeclaration
>
enumDecl
=
cUnit
.
findDescendantsOfType
(
ASTEnumDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
enumDecl
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
enumDecl
);
List
<
ASTEnumConstant
>
contantDecl
=
cUnit
.
findDescendantsOfType
(
ASTEnumConstant
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
contantDecl
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
contantDecl
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
cUnit
.
getComments
());
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
cUnit
.
getComments
());
return
itemsByLineNumber
;
}
...
...
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java
浏览文件 @
d9792ef4
...
...
@@ -21,7 +21,7 @@ import java.util.SortedMap;
import
java.util.TreeMap
;
import
java.util.regex.Pattern
;
import
com.alibaba.p3c.pmd.lang.java.rule.util.
Commen
tUtils
;
import
com.alibaba.p3c.pmd.lang.java.rule.util.
NodeSor
tUtils
;
import
net.sourceforge.pmd.lang.ast.Node
;
import
net.sourceforge.pmd.lang.java.ast.ASTBlockStatement
;
...
...
@@ -144,25 +144,25 @@ public class RemoveCommentedCodeRule extends AbstractAliCommentRule {
List
<
ASTImportDeclaration
>
importDecl
=
cUnit
.
findDescendantsOfType
(
ASTImportDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
importDecl
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
importDecl
);
List
<
ASTClassOrInterfaceDeclaration
>
classDecl
=
cUnit
.
findDescendantsOfType
(
ASTClassOrInterfaceDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
classDecl
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
classDecl
);
List
<
ASTFieldDeclaration
>
fields
=
cUnit
.
findDescendantsOfType
(
ASTFieldDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
fields
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
fields
);
List
<
ASTMethodDeclaration
>
methods
=
cUnit
.
findDescendantsOfType
(
ASTMethodDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
methods
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
methods
);
List
<
ASTConstructorDeclaration
>
constructors
=
cUnit
.
findDescendantsOfType
(
ASTConstructorDeclaration
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
constructors
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
constructors
);
List
<
ASTBlockStatement
>
blockStatements
=
cUnit
.
findDescendantsOfType
(
ASTBlockStatement
.
class
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
blockStatements
);
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
blockStatements
);
Commen
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
cUnit
.
getComments
());
NodeSor
tUtils
.
addNodesToSortedMap
(
itemsByLineNumber
,
cUnit
.
getComments
());
return
itemsByLineNumber
;
}
...
...
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/util/
Commen
tUtils.java
→
p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/util/
NodeSor
tUtils.java
浏览文件 @
d9792ef4
...
...
@@ -26,7 +26,7 @@ import net.sourceforge.pmd.lang.ast.Node;
* @date 2016/11/21
*
*/
public
class
Commen
tUtils
{
public
class
NodeSor
tUtils
{
/**
* add node to SortedMap with sequence to determine comment location
...
...
@@ -36,8 +36,16 @@ public class CommentUtils {
*/
public
static
void
addNodesToSortedMap
(
SortedMap
<
Integer
,
Node
>
map
,
List
<?
extends
Node
>
nodes
)
{
for
(
Node
node
:
nodes
)
{
// sorted by line and column
map
.
put
((
node
.
getBeginLine
()
<<
16
)
+
node
.
getBeginColumn
(),
node
);
map
.
put
(
generateIndex
(
node
),
node
);
}
}
/**
* set order according to node begin line and begin column
* @param node node to sort
* @return generated index
*/
public
static
int
generateIndex
(
Node
node
)
{
return
(
node
.
getBeginLine
()
<<
16
)
+
node
.
getBeginColumn
();
}
}
p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/ClassMustHaveAuthorRule.xml
浏览文件 @
d9792ef4
<?xml version="1.0" encoding="UTF-8"?>
<test-data>
<code-fragment
id=
"class-without-author"
>
<![CDATA[
<code-fragment
id=
"class-without-author"
>
<![CDATA[
public class ClassMustHaveAuthorRule {}
]]>
</code-fragment>
</code-fragment>
<test-code>
<description>
Class without author.
</description>
<expected-problems>
1
</expected-problems>
<expected-linenumbers>
1
</expected-linenumbers>
<code-ref
id=
"class-without-author"
/>
</test-code>
<test-code>
<description>
Class without author.
</description>
<expected-problems>
1
</expected-problems>
<expected-linenumbers>
1
</expected-linenumbers>
<code-ref
id=
"class-without-author"
/>
</test-code>
<code-fragment
id=
"class-with-author"
>
<![CDATA[
<code-fragment
id=
"class-with-author"
>
<![CDATA[
/**
* @author keriezhang
* @date 2017/07/18
*/
public class ClassMustHaveAuthorRule {}
]]>
</code-fragment>
<test-code>
<description>
Class with author.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-with-author"
/>
</test-code>
<code-fragment
id=
"class-with-date"
>
<![CDATA[
</code-fragment>
<test-code>
<description>
Class with author.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-with-author"
/>
</test-code>
<code-fragment
id=
"class-with-date"
>
<![CDATA[
/**
* @date 2016/12/14
*/
public class ClassMustHaveAuthorRule {}
]]>
</code-fragment>
<test-code>
<description>
Class with date.
</description>
<expected-problems>
1
</expected-problems>
<expected-linenumbers>
4
</expected-linenumbers>
<code-ref
id=
"class-with-date"
/>
</test-code>
<code-fragment
id=
"class-with-author-and-date"
>
<![CDATA[
</code-fragment>
<test-code>
<description>
Class with date.
</description>
<expected-problems>
1
</expected-problems>
<expected-linenumbers>
4
</expected-linenumbers>
<code-ref
id=
"class-with-date"
/>
</test-code>
<code-fragment
id=
"class-with-author-and-date"
>
<![CDATA[
/**
* @author keriezhang
* @date 2016/12/14
*/
public class ClassMustHaveAuthorRule {}
]]>
</code-fragment>
<test-code>
<description>
Class with author and date.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-with-author-and-date"
/>
</test-code>
</code-fragment>
<test-code>
<description>
Class with author and date.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-with-author-and-date"
/>
</test-code>
<code-fragment
id=
"class-with-inner-class"
>
<![CDATA[
<code-fragment
id=
"class-with-inner-class"
>
<![CDATA[
/**
* @author keriezhang
* @date 2016/12/14
...
...
@@ -66,28 +66,28 @@ public class Outer_Demo {
}
}
]]>
</code-fragment>
<test-code>
<description>
Class with inner class.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-with-inner-class"
/>
</test-code>
</code-fragment>
<test-code>
<description>
Class with inner class.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-with-inner-class"
/>
</test-code>
<code-fragment
id=
"enum-without-author"
>
<![CDATA[
<code-fragment
id=
"enum-without-author"
>
<![CDATA[
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
]]>
</code-fragment>
<test-code>
<description>
Enum without author
</description>
<expected-problems>
1
</expected-problems>
<expected-linenumbers>
1
</expected-linenumbers>
<code-ref
id=
"enum-without-author"
/>
</test-code>
</code-fragment>
<test-code>
<description>
Enum without author
</description>
<expected-problems>
1
</expected-problems>
<expected-linenumbers>
1
</expected-linenumbers>
<code-ref
id=
"enum-without-author"
/>
</test-code>
<code-fragment
id=
"enum-with-author"
>
<![CDATA[
<code-fragment
id=
"enum-with-author"
>
<![CDATA[
/**
* @author keriezhang
* @date 2016/12/14
...
...
@@ -97,14 +97,14 @@ public enum Day {
THURSDAY, FRIDAY, SATURDAY
}
]]>
</code-fragment>
<test-code>
<description>
Enum with author
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"enum-with-author"
/>
</test-code>
</code-fragment>
<test-code>
<description>
Enum with author
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"enum-with-author"
/>
</test-code>
<code-fragment
id=
"enum-in-class"
>
<![CDATA[
<code-fragment
id=
"enum-in-class"
>
<![CDATA[
/**
* @author keriezhang
* @date 2016/12/14
...
...
@@ -117,14 +117,14 @@ public class Vehicle {
}
}
]]>
</code-fragment>
<test-code>
<description>
Enum in class
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"enum-in-class"
/>
</test-code>
</code-fragment>
<test-code>
<description>
Enum in class
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"enum-in-class"
/>
</test-code>
<code-fragment
id=
"enum-in-interface"
>
<![CDATA[
<code-fragment
id=
"enum-in-interface"
>
<![CDATA[
/**
* @author keriezhang
* @date 2016/12/14
...
...
@@ -137,11 +137,31 @@ public interface Vehicle {
}
}
]]>
</code-fragment>
<test-code>
<description>
Enum in interface
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"enum-in-interface"
/>
</test-code>
</code-fragment>
<test-code>
<description>
Enum in interface
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"enum-in-interface"
/>
</test-code>
<code-fragment
id=
"upper-case-author-annotation"
>
<![CDATA[
/**
* @Author keriezhang
* @date 2016/12/14
*/
public interface Vehicle {
public Number getNumber();
public void method2();
public enum color {
RED, GREEN, ANY;
}
}
]]>
</code-fragment>
<test-code>
<description>
Uppercase author annotation
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"upper-case-author-annotation"
/>
</test-code>
</test-data>
\ No newline at end of file
p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/CommentsMustBeJavadocFormatRule.xml
浏览文件 @
d9792ef4
<?xml version="1.0" encoding="UTF-8"?>
<test-data>
<code-fragment
id=
"class-without-comments"
>
<![CDATA[
<code-fragment
id=
"class-without-comments"
>
<![CDATA[
public class CommentsMustBeJavadocFormat {
private String name;
public void getName() {}
}
]]>
</code-fragment>
</code-fragment>
<test-code>
<description>
Class have no comment.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-without-comments"
/>
</test-code>
<test-code>
<description>
Class have no comment.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-without-comments"
/>
</test-code>
<code-fragment
id=
"class-with-non-javadoc-comments"
>
<![CDATA[
<code-fragment
id=
"class-with-non-javadoc-comments"
>
<![CDATA[
// a comment
// a comment
public class CommentsMustBeJavadocFormat {
...
...
@@ -26,17 +26,17 @@ public class CommentsMustBeJavadocFormat {
public void getName() {}
}
]]>
</code-fragment>
</code-fragment>
<test-code>
<description>
Class have non-javadoc comments.
</description>
<expected-problems>
3
</expected-problems>
<expected-linenumbers>
2,4,6
</expected-linenumbers>
<code-ref
id=
"class-with-non-javadoc-comments"
/>
</test-code>
<test-code>
<description>
Class have non-javadoc comments.
</description>
<expected-problems>
3
</expected-problems>
<expected-linenumbers>
2,4,6
</expected-linenumbers>
<code-ref
id=
"class-with-non-javadoc-comments"
/>
</test-code>
<code-fragment
id=
"class-with-javadoc-comments"
>
<![CDATA[
<code-fragment
id=
"class-with-javadoc-comments"
>
<![CDATA[
/**
* test
*/
...
...
@@ -52,15 +52,15 @@ public class CommentsMustBeJavadocFormat {
public void getName() {}
}
]]>
</code-fragment>
<test-code>
<description>
Class have javadoc comments.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-with-javadoc-comments"
/>
</test-code>
</code-fragment>
<test-code>
<description>
Class have javadoc comments.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"class-with-javadoc-comments"
/>
</test-code>
<code-fragment
id=
"anonymous-class-with-non-javadoc-comments"
>
<![CDATA[
<code-fragment
id=
"anonymous-class-with-non-javadoc-comments"
>
<![CDATA[
// comment of outer class
public class Outer_class {
// comment of method of outer class
...
...
@@ -76,17 +76,17 @@ public class Outer_class {
}
}
]]>
</code-fragment>
<test-code>
<description>
Anonymous Inner Class have non javadoc comments.
</description>
<expected-problems>
2
</expected-problems>
<expected-linenumbers>
1,3
</expected-linenumbers>
<code-ref
id=
"anonymous-class-with-non-javadoc-comments"
/>
</test-code>
</code-fragment>
<test-code>
<description>
Anonymous Inner Class have non javadoc comments.
</description>
<expected-problems>
2
</expected-problems>
<expected-linenumbers>
1,3
</expected-linenumbers>
<code-ref
id=
"anonymous-class-with-non-javadoc-comments"
/>
</test-code>
<code-fragment
id=
"non-javadoc-comments-before-package-and-import"
>
<![CDATA[
<code-fragment
id=
"non-javadoc-comments-before-package-and-import"
>
<![CDATA[
/*
* Created on 18 nov. 2004
*/
...
...
@@ -104,15 +104,15 @@ public class PMDProjectPropertyPage extends PropertyPage {
}
]]>
</code-fragment>
<test-code>
<description>
Non-javadoc comments before package and import
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"non-javadoc-comments-before-package-and-import"
/>
</test-code>
<code-fragment
id=
"ignore-comments-behind-statements"
>
<![CDATA[
</code-fragment>
<test-code>
<description>
Non-javadoc comments before package and import
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"non-javadoc-comments-before-package-and-import"
/>
</test-code>
<code-fragment
id=
"ignore-comments-behind-statements"
>
<![CDATA[
public class CommentsMustBeJavadocFormat {
private String name; //avoid two two violations in one line.
private Integer age;
...
...
@@ -120,12 +120,71 @@ public class CommentsMustBeJavadocFormat {
}
}
]]>
</code-fragment>
<test-code>
<description>
Ignore comments behind statements.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"ignore-comments-behind-statements"
/>
</test-code>
</code-fragment>
<test-code>
<description>
Ignore comments behind statements.
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"ignore-comments-behind-statements"
/>
</test-code>
<code-fragment
id=
"when-node-has-annotation-wrong-format"
>
<![CDATA[
// test when class has annotation
@Controller
@Rest
public class CommentsMustBeJavadocFormat {
// test when node has annotation
@Test
private String name;
// test when node has annotation2
@Hello(asdf="asdf")
@world
private Integer age;
// test when method has annotation
@Test
@Autowired
public void getName() {
}
}
]]>
</code-fragment>
<test-code>
<description>
When node has annotation and wrong comment format
</description>
<expected-problems>
4
</expected-problems>
<expected-linenumbers>
1,5,9,14
</expected-linenumbers>
<code-ref
id=
"when-node-has-annotation-wrong-format"
/>
</test-code>
<code-fragment
id=
"when-node-has-annotation-right-format"
>
<![CDATA[
/** test when class has annotation */
@Controller
@Rest
public class CommentsMustBeJavadocFormat {
/** test when node has annotation */
@Test
private String name;
/** test when node has annotation2 */
@Hello(asdf="asdf")
@world
private Integer age;
/** test when method has annotation */
@Test
@Autowired
public void getName() {
}
}
]]>
</code-fragment>
<test-code>
<description>
When node has annotation and right comment format
</description>
<expected-problems>
0
</expected-problems>
<code-ref
id=
"when-node-has-annotation-right-format"
/>
</test-code>
</test-data>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录