diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-11-19 19:28:39 +0100 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-11-19 19:30:29 +0100 |
commit | a48f7ac3ae0f50594a59b2bda85a64e288414bfe (patch) | |
tree | dfc73d24824268ae36c22a8cb5b90482576f619d /sonar-duplications/src/main/java | |
parent | 9adcfb71589fb7d8b1520593fde26d0d5533d118 (diff) | |
download | sonarqube-a48f7ac3ae0f50594a59b2bda85a64e288414bfe.tar.gz sonarqube-a48f7ac3ae0f50594a59b2bda85a64e288414bfe.zip |
SONAR-3752 Improve detection of duplications
Take into account only first and last lines from multiple successive and identical lines.
Diffstat (limited to 'sonar-duplications/src/main/java')
3 files changed, 8 insertions, 15 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/block/BlockChunker.java b/sonar-duplications/src/main/java/org/sonar/duplications/block/BlockChunker.java index 40779fed35a..1a21a4a57ec 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/block/BlockChunker.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/block/BlockChunker.java @@ -63,11 +63,9 @@ public class BlockChunker { while (j < statements.size() && statements.get(j).getValue().equals(first.getValue())) { j++; } + filtered.add(statements.get(i)); if (i < j - 1) { - Statement last = statements.get(j - 1); - filtered.add(new Statement(first.getStartLine(), last.getEndLine(), first.getValue())); - } else { - filtered.add(statements.get(i)); + filtered.add(statements.get(j - 1)); } i = j; } diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java index 1c8e9624f13..1ce97191f59 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java @@ -57,11 +57,9 @@ public class PmdBlockChunker { while (j < fragments.size() && fragments.get(j).getValue().equals(first.getValue())) { j++; } + filtered.add(fragments.get(i)); if (i < j - 1) { - TokensLine last = fragments.get(j - 1); - filtered.add(new TokensLine(first.getStartUnit(), last.getEndUnit(), first.getStartLine(), last.getEndLine(), first.getValue())); - } else { - filtered.add(fragments.get(i)); + filtered.add(fragments.get(j - 1)); } i = j; } diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokensLine.java b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokensLine.java index 44fcaafb1c3..c4b5f63d348 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokensLine.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokensLine.java @@ -30,7 +30,6 @@ class TokensLine implements CodeFragment { private final String value; private final int startLine; - private final int endLine; private final int hashCode; private final int startUnit; @@ -38,14 +37,9 @@ class TokensLine implements CodeFragment { public TokensLine(int startUnit, int endUnit, int startLine, String value) { - this(startUnit, endUnit, startLine, startLine, value); - } - - public TokensLine(int startUnit, int endUnit, int startLine, int endLine, String value) { Preconditions.checkArgument(startLine > 0); // TODO do we have requirements for length and hashcode ? this.startLine = startLine; - this.endLine = endLine; this.value = value; this.hashCode = value.hashCode(); @@ -61,8 +55,11 @@ class TokensLine implements CodeFragment { return startLine; } + /** + * Same as {@link #getStartLine()} + */ public int getEndLine() { - return endLine; + return startLine; } public int getHashCode() { |