@Test public void testNumberOfUnitsNotLessThan() { Predicate<CloneGroup> predicate = DuplicationPredicates.numberOfUnitsNotLessThan(5); assertThat(predicate.test(CloneGroup.builder().setLengthInUnits(6).build())).isTrue(); assertThat(predicate.test(CloneGroup.builder().setLengthInUnits(5).build())).isTrue(); assertThat(predicate.test(CloneGroup.builder().setLengthInUnits(4).build())).isFalse(); }
private void reportClones(BlocksGroup beginGroup, BlocksGroup endGroup, int cloneLength) { List<Block[]> pairs = beginGroup.pairs(endGroup, cloneLength); ClonePart origin = null; List<ClonePart> parts = new ArrayList<>(); for (int i = 0; i < pairs.size(); i++) { Block[] pair = pairs.get(i); Block firstBlock = pair[0]; Block lastBlock = pair[1]; ClonePart part = new ClonePart(firstBlock.getResourceId(), firstBlock.getIndexInFile(), firstBlock.getStartLine(), lastBlock.getEndLine()); if (originResourceId.equals(part.getResourceId())) { if (origin == null || part.getUnitStart() < origin.getUnitStart()) { origin = part; } } parts.add(part); } filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build()); }
/** * Creates new group from list of parts, origin - is a first part from list. */ private CloneGroup newCloneGroup(int len, ClonePart... parts) { return CloneGroup.builder().setLength(len).setOrigin(parts[0]).setParts(Arrays.asList(parts)).build(); }
private CloneGroup newCloneGroup(ClonePart... parts) { return CloneGroup.builder().setLength(0).setOrigin(parts[0]).setParts(Arrays.asList(parts)).build(); } }
@Test public void should_limit_number_of_references() { // 1 origin part + 101 duplicates = 102 List<ClonePart> parts = new ArrayList<>(CpdExecutor.MAX_CLONE_PART_PER_GROUP + 2); for (int i = 0; i < CpdExecutor.MAX_CLONE_PART_PER_GROUP + 2; i++) { parts.add(new ClonePart(batchComponent1.key(), i, i, i + 1)); } List<CloneGroup> groups = Collections.singletonList(CloneGroup.builder().setLength(0).setOrigin(parts.get(0)).setParts(parts).build()); executor.saveDuplications(batchComponent1, groups); Duplication[] dups = readDuplications(1); assertThat(dups[0].getDuplicateList()).hasSize(CpdExecutor.MAX_CLONE_PART_PER_GROUP); assertThat(logTester.logs(LoggerLevel.WARN)) .contains("Too many duplication references on file " + batchComponent1 + " for block at line 0. Keep only the first " + CpdExecutor.MAX_CLONE_PART_PER_GROUP + " references."); }
ClonePart origin = null; CloneGroup.Builder builder = CloneGroup.builder().setLength(length);
private void reportClones(BlocksGroup beginGroup, BlocksGroup endGroup, int cloneLength) { List<Block[]> pairs = beginGroup.pairs(endGroup, cloneLength); ClonePart origin = null; List<ClonePart> parts = Lists.newArrayList(); for (int i = 0; i < pairs.size(); i++) { Block[] pair = pairs.get(i); Block firstBlock = pair[0]; Block lastBlock = pair[1]; ClonePart part = new ClonePart(firstBlock.getResourceId(), firstBlock.getIndexInFile(), firstBlock.getStartLine(), lastBlock.getEndLine()); if (originResourceId.equals(part.getResourceId())) { if (origin == null) { origin = part; } else if (part.getUnitStart() < origin.getUnitStart()) { origin = part; } } parts.add(part); } filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build()); }
ClonePart origin = null; CloneGroup.Builder builder = CloneGroup.builder().setLength(length);