From 6fada8e380a59aaac2ce5ae56aafad8c74f088ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AF=E6=9C=9F?= Date: Tue, 31 Oct 2017 17:35:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E4=B8=8D=E5=86=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E4=BB=A3=E7=A0=81=E6=AE=B5=E2=80=94=E2=80=94?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E5=B8=A6
=E6=A0=87=E7=AD=BE=E7=9A=84?=
 =?UTF-8?q?=E6=B3=A8=E9=87=8A,=20fixes=20#150?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../rule/comment/RemoveCommentedCodeRule.java |  7 ++++
 .../comment/xml/RemoveCommentedCodeRule.xml   | 33 +++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java
index ed39855..a880be6 100644
--- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java
+++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java
@@ -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(".*
.*", 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()) {
diff --git a/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/RemoveCommentedCodeRule.xml b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/RemoveCommentedCodeRule.xml
index 8e3669f..a8293e1 100644
--- a/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/RemoveCommentedCodeRule.xml
+++ b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/RemoveCommentedCodeRule.xml
@@ -103,4 +103,37 @@ public class Test {
         
     
 
+    
+    
+
+    
+        Code without pre tag
+        1
+        1
+        
+    
+
+    
+ * import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
+ * 
+ */ +public class Test { +} + ]]> + + + + Code in pre tag + 0 + + + \ No newline at end of file