aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-09-08 08:54:57 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-09-08 16:09:00 +0200
commit250b357941de75db87a2879090d554a355095bd9 (patch)
tree67eaca31198aa988248bd642add378b36ef41854 /sonar-duplications/src
parentbf9c3dfba11f91d17ebe9934549dfadbcab66846 (diff)
downloadsonarqube-250b357941de75db87a2879090d554a355095bd9.tar.gz
sonarqube-250b357941de75db87a2879090d554a355095bd9.zip
Fix Quality flaws
Diffstat (limited to 'sonar-duplications/src')
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java2
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java31
2 files changed, 15 insertions, 18 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java
index 05ba74e0eb2..9fcaf2ebf3d 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/BlocksGroup.java
@@ -22,6 +22,7 @@ package org.sonar.duplications.detector.original;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
+import javax.annotation.CheckForNull;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.utils.FastStringComparator;
@@ -72,6 +73,7 @@ final class BlocksGroup {
/**
* First block from this group with specified resource id.
*/
+ @CheckForNull
public Block first(String resourceId) {
for (Block block : blocks) {
if (resourceId.equals(block.getResourceId())) {
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
index 655bb1ccbb6..be93463a5e4 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
@@ -38,23 +38,8 @@ import org.sonar.duplications.index.ClonePart;
*/
public final class OriginalCloneDetectionAlgorithm {
- /**
- * Performs detection and returns list of clone groups between file (which represented as a collection of blocks) and index.
- * Note that this method ignores blocks for this file, that will be retrieved from index.
- */
- public static List<CloneGroup> detect(CloneIndex cloneIndex, Collection<Block> fileBlocks) {
- if (fileBlocks.isEmpty()) {
- return Collections.EMPTY_LIST;
- }
- OriginalCloneDetectionAlgorithm reporter = new OriginalCloneDetectionAlgorithm(cloneIndex);
- reporter.findClones(fileBlocks);
- return reporter.filter.getResult();
- }
-
private final CloneIndex cloneIndex;
-
private final Filter filter = new Filter();
-
private String originResourceId;
private OriginalCloneDetectionAlgorithm(CloneIndex cloneIndex) {
@@ -213,9 +198,7 @@ public final class OriginalCloneDetectionAlgorithm {
lastBlock.getEndLine());
if (originResourceId.equals(part.getResourceId())) {
- if (origin == null) {
- origin = part;
- } else if (part.getUnitStart() < origin.getUnitStart()) {
+ if (origin == null || part.getUnitStart() < origin.getUnitStart()) {
origin = part;
}
}
@@ -226,4 +209,16 @@ public final class OriginalCloneDetectionAlgorithm {
filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build());
}
+ /**
+ * Performs detection and returns list of clone groups between file (which represented as a collection of blocks) and index.
+ * Note that this method ignores blocks for this file, that will be retrieved from index.
+ */
+ public static List<CloneGroup> detect(CloneIndex cloneIndex, Collection<Block> fileBlocks) {
+ if (fileBlocks.isEmpty()) {
+ return Collections.emptyList();
+ }
+ OriginalCloneDetectionAlgorithm reporter = new OriginalCloneDetectionAlgorithm(cloneIndex);
+ reporter.findClones(fileBlocks);
+ return reporter.filter.getResult();
+ }
}