]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2867 Standard copy-paste detection should happen within a project, not only...
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 23 Dec 2015 10:29:14 +0000 (11:29 +0100)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 23 Dec 2015 10:29:14 +0000 (11:29 +0100)
sonar-batch/src/main/java/org/sonar/batch/cpd/CpdExecutor.java

index 302035c3973ae5fc159e342ad3e74b253e3474be..31fac6c17a8a84cc36b2a6173da1ef8669418f80 100644 (file)
@@ -93,13 +93,25 @@ public class CpdExecutor {
     }
 
     InputFile inputFile = (InputFile) component.inputComponent();
-    Predicate<CloneGroup> minimumTokensPredicate = DuplicationPredicates.numberOfUnitsNotLessThan(getMinimumTokens(inputFile.language()));
-    List<CloneGroup> filtered = from(duplications).filter(minimumTokensPredicate).toList();
+
+    List<CloneGroup> filtered;
+    if (!"java".equalsIgnoreCase(inputFile.language())) {
+      Predicate<CloneGroup> minimumTokensPredicate = DuplicationPredicates.numberOfUnitsNotLessThan(getMinimumTokens(inputFile.language()));
+      filtered = from(duplications).filter(minimumTokensPredicate).toList();
+    } else {
+      filtered = duplications;
+    }
 
     saveDuplications(component, filtered);
   }
 
   @VisibleForTesting
+  /**
+   * Not applicable to Java, as the {@link BlockChunker} that it uses does not record start and end units of each block. 
+   * Also, it uses statements instead of tokens. 
+   * @param languageKey
+   * @return
+   */
   int getMinimumTokens(String languageKey) {
     int minimumTokens = settings.getInt("sonar.cpd." + languageKey + ".minimumTokens");
     if (minimumTokens == 0) {