]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3752 Improve detection of duplications
authorEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 19 Nov 2012 18:28:39 +0000 (19:28 +0100)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Mon, 19 Nov 2012 18:30:29 +0000 (19:30 +0100)
Take into account only first and last lines from multiple successive and identical lines.

sonar-duplications/src/main/java/org/sonar/duplications/block/BlockChunker.java
sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java
sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokensLine.java

index 40779fed35a391ac41f872151a1c976c89b98e8e..1a21a4a57ecfeeef49d5f2908c65b71243aa23f7 100644 (file)
@@ -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;
     }
index 1c8e9624f13a0a4f1dcf74b131feb6ae1f1ab1c3..1ce97191f5988402df9c9cea7ab855552b16596a 100644 (file)
@@ -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;
     }
index 44fcaafb1c3a9c2c643650d22c2e5fe492eb884d..c4b5f63d348e5fc8a0e261f8d898c87cd6212f20 100644 (file)
@@ -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() {