diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-12-02 17:05:39 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-12-05 12:51:15 +0400 |
commit | 7faee383694f53a6baad3a1a88218c5f4f88578e (patch) | |
tree | c339165fffa429f232a092b3007c1aa4a036bdfa /sonar-squid/src | |
parent | ee09f485818f4808fa7aff7c02969c972931a180 (diff) | |
download | sonarqube-7faee383694f53a6baad3a1a88218c5f4f88578e.tar.gz sonarqube-7faee383694f53a6baad3a1a88218c5f4f88578e.zip |
SONAR-2018 Add rule to detect commented-out lines of code
Diffstat (limited to 'sonar-squid/src')
-rw-r--r-- | sonar-squid/src/main/java/org/sonar/squid/api/SourceFile.java | 15 | ||||
-rw-r--r-- | sonar-squid/src/main/java/org/sonar/squid/text/Source.java | 9 |
2 files changed, 24 insertions, 0 deletions
diff --git a/sonar-squid/src/main/java/org/sonar/squid/api/SourceFile.java b/sonar-squid/src/main/java/org/sonar/squid/api/SourceFile.java index b9355b88a48..922c5ca26b1 100644 --- a/sonar-squid/src/main/java/org/sonar/squid/api/SourceFile.java +++ b/sonar-squid/src/main/java/org/sonar/squid/api/SourceFile.java @@ -26,6 +26,7 @@ import java.util.Set; public class SourceFile extends SourceCode { private Set<Integer> noSonarTagLines = new HashSet<Integer>(); + private Set<Integer> commentedOutCodeLines = new HashSet<Integer>(); public SourceFile(String key) { super(key); @@ -52,4 +53,18 @@ public class SourceFile extends SourceCode { public void addNoSonarTagLine(int line) { noSonarTagLines.add(line); } + + /** + * @since 2.13 + */ + public Set<Integer> getCommentedOutCodeLines() { + return commentedOutCodeLines; + } + + /** + * @since 2.13 + */ + public void addCommentedOutCodeLines(Set<Integer> commentedOutCodeLines) { + this.commentedOutCodeLines.addAll(commentedOutCodeLines); + } } diff --git a/sonar-squid/src/main/java/org/sonar/squid/text/Source.java b/sonar-squid/src/main/java/org/sonar/squid/text/Source.java index 8e6b51b4714..7d4510f8db1 100644 --- a/sonar-squid/src/main/java/org/sonar/squid/text/Source.java +++ b/sonar-squid/src/main/java/org/sonar/squid/text/Source.java @@ -33,6 +33,7 @@ public class Source { private List<Line> lines = new ArrayList<Line>(); private CodeRecognizer codeRecognizer; private Set<Integer> noSonarTagLines = new HashSet<Integer>(); + private Set<Integer> commentedOutCodeLines = new HashSet<Integer>(); public Source(Reader reader, CodeRecognizer codeRecognizer, String... additionalSingleLineCommentFlag) { this.codeRecognizer = codeRecognizer; @@ -87,6 +88,7 @@ public class Source { line.setMeasure(Metric.COMMENT_LINES, 1); } else { line.setMeasure(Metric.COMMENTED_OUT_CODE_LINES, 1); + commentedOutCodeLines.add(line.getLineIndex()); } } } @@ -125,4 +127,11 @@ public class Source { public Set<Integer> getNoSonarTagLines() { return noSonarTagLines; } + + /** + * @since 2.13 + */ + public Set<Integer> getCommentedOutCodeLines() { + return commentedOutCodeLines; + } } |