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