提交 6fada8e3 编写于 作者: 可期

清理不再使用的代码段——跳过带<pre>标签的注释, fixes #150

上级 d9792ef4
......@@ -44,6 +44,8 @@ public class RemoveCommentedCodeRule extends AbstractAliCommentRule {
private static final Pattern SUPPRESS_PATTERN = Pattern.compile("\\s*///.*", Pattern.DOTALL);
private static final Pattern PRE_TAG_PATTERN = Pattern.compile(".*<pre>.*", Pattern.DOTALL);
private static final Pattern IMPORT_PATTERN = Pattern.compile(".*import\\s(static\\s)?(\\w*\\.)*\\w*;.*",
Pattern.DOTALL);
......@@ -125,6 +127,11 @@ public class RemoveCommentedCodeRule extends AbstractAliCommentRule {
protected CommentPatternEnum scanCommentedCode(String content) {
CommentPatternEnum pattern = CommentPatternEnum.NONE;
// Skip comment which contains pre tag.
if (PRE_TAG_PATTERN.matcher(content).matches()) {
return pattern;
}
if (IMPORT_PATTERN.matcher(content).matches()) {
pattern = CommentPatternEnum.IMPORT;
} else if (FIELD_PATTERN.matcher(content).matches()) {
......
......@@ -103,4 +103,37 @@ public class Test {
<code-ref id="example-in-javadoc" />
</test-code>
<code-fragment id="code-without-pre-tag"><![CDATA[
/**
* import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
*/
public class Test {
}
]]>
</code-fragment>
<test-code>
<description>Code without pre tag</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>1</expected-linenumbers>
<code-ref id="code-without-pre-tag" />
</test-code>
<code-fragment id="code-in-pre-tag"><![CDATA[
/**
* <pre>
* import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
* </pre>
*/
public class Test {
}
]]>
</code-fragment>
<test-code>
<description>Code in pre tag</description>
<expected-problems>0</expected-problems>
<code-ref id="code-in-pre-tag" />
</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.
先完成此消息的编辑!
想要评论请 注册