Search in sources :

Example 1 with Duplication

use of org.sonar.ce.task.projectanalysis.duplication.Duplication in project sonarqube by SonarSource.

the class DuplicationLineReader method extractAllDuplicatedTextBlocks.

/**
 * Duplicated blocks in the current file are either {@link Duplication#getOriginal()} or {@link Duplication#getDuplicates()}
 * when the {@link Duplicate} is a {@link InnerDuplicate}.
 * <p>
 * The returned list is mutable on purpose because it will be sorted.
 * </p>
 *
 * @see {@link #createIndexOfDuplicatedTextBlocks(Iterable)}
 */
private static List<TextBlock> extractAllDuplicatedTextBlocks(Iterable<Duplication> duplications) {
    List<TextBlock> duplicatedBlock = new ArrayList<>(size(duplications));
    for (Duplication duplication : duplications) {
        duplicatedBlock.add(duplication.getOriginal());
        Arrays.stream(duplication.getDuplicates()).filter(InnerDuplicate.class::isInstance).forEach(duplicate -> duplicatedBlock.add(duplicate.getTextBlock()));
    }
    return duplicatedBlock;
}
Also used : Duplication(org.sonar.ce.task.projectanalysis.duplication.Duplication) ArrayList(java.util.ArrayList) TextBlock(org.sonar.ce.task.projectanalysis.duplication.TextBlock)

Aggregations

ArrayList (java.util.ArrayList)1 Duplication (org.sonar.ce.task.projectanalysis.duplication.Duplication)1 TextBlock (org.sonar.ce.task.projectanalysis.duplication.TextBlock)1