public void analyze()

in codeanalyzer/src/main/java/nl/obren/sokrates/sourcecode/analysis/files/DuplicationAnalyzer.java [42:109]


    public void analyze(ProgressFeedback progressFeedback) {
        if (codeConfiguration.getAnalysis().isSkipDuplication()) {
            return;
        }

        this.progressFeedback = progressFeedback;
        progressFeedback.start();
        progressFeedback.setDetailedText("");
        AnalysisUtils.info(textSummary, progressFeedback, "Extracting duplication...", start);
        List<DuplicationInstance> duplicates = new DuplicationEngine().findDuplicates(main.getSourceFiles(), new ProgressFeedback());

        analysisResults.setAllDuplicates(duplicates);

        int numberOfDuplicates = duplicates.size();
        int numberOfDuplicatedLines = DuplicationUtils.getNumberOfDuplicatedLines(duplicates);
        int totalNumberOfCleanedLines = DuplicationUtils.getTotalNumberOfCleanedLines(main.getSourceFiles());
        int numberOfFilesWithDuplicates = DuplicationAggregator.getDuplicationPerSourceFile(duplicates).size();

        analysisResults.getOverallDuplication().setNumberOfDuplicates(numberOfDuplicates);
        analysisResults.getOverallDuplication().setCleanedLinesOfCode(totalNumberOfCleanedLines);
        analysisResults.getOverallDuplication().setDuplicatedLinesOfCode(numberOfDuplicatedLines);
        analysisResults.getOverallDuplication().setNumberOfFilesWithDuplicates(numberOfFilesWithDuplicates);

        addSystemDuplicationMetrics(numberOfDuplicates, numberOfDuplicatedLines, totalNumberOfCleanedLines, numberOfFilesWithDuplicates);

        List<SourceFileDuplication> duplicationPerSourceFile = DuplicationAggregator.getDuplicationPerSourceFile(duplicates);
        List<AspectDuplication> duplicationPerLogicalComponent = DuplicationAggregator.getDuplicationPerLogicalComponent(codeConfiguration.getLogicalDecompositions(), main.getSourceFiles(),
                duplicationPerSourceFile);

        codeConfiguration.getLogicalDecompositions().forEach(logicalDecomposition -> {
            AnalysisUtils.detailedInfo(textSummary, progressFeedback, "  - per component:" + logicalDecomposition.getName(), start);
            ArrayList<DuplicationMetric> duplicationPerComponent = new ArrayList<>();
            analysisResults.getDuplicationPerComponent().add(duplicationPerComponent);
            duplicationPerLogicalComponent.stream()
                    .filter(componentDuplication -> componentDuplication.getAspect().getFiltering().equalsIgnoreCase(logicalDecomposition.getName()))
                    .forEach(componentDuplication -> {
                        String group = componentDuplication.getAspect().getFiltering();
                        String displayName = componentDuplication.getAspect().getName();
                        String key = displayName;
                        duplicationPerComponent.add(new DuplicationMetric(key,
                                componentDuplication.getCleanedLinesOfCode(), componentDuplication.getDuplicatedLinesOfCode()));

                        addComponentDuplicationMetrics(logicalDecomposition, componentDuplication, displayName);
                    });
        });

        List<ExtensionDuplication> duplicationPerExtension = DuplicationAggregator.getDuplicationPerExtension(main.getSourceFiles(), duplicationPerSourceFile);
        AnalysisUtils.detailedInfo(textSummary, progressFeedback, "  - per extension:", start);
        duplicationPerExtension.forEach(extensionDuplication -> {
            String displayName = extensionDuplication.getExtension();
            analysisResults.getDuplicationPerExtension().add(new DuplicationMetric(displayName,
                    extensionDuplication.getCleanedLinesOfCode(), extensionDuplication.getDuplicatedLinesOfCode()));
            addExtensionDuplicationMetrics(extensionDuplication);
        });

        Collections.sort(duplicates, (o1, o2) -> -new Integer(o1.getDuplicatedFileBlocks().size()).compareTo(o2.getDuplicatedFileBlocks().size()));
        for (int i = 0; i < Math.min(20, duplicates.size()); i++) {
            DuplicationInstance duplicate = duplicates.get(i);
            if (duplicate.getDuplicatedFileBlocks().size() > 2) {
                analysisResults.getMostFrequentDuplicates().add(duplicate);
            }
        }

        Collections.sort(duplicates, (o1, o2) -> -new Integer(o1.getBlockSize()).compareTo(o2.getBlockSize()));
        for (int i = 0; i < Math.min(20, duplicates.size()); i++) {
            analysisResults.getLongestDuplicates().add(duplicates.get(i));
        }
    }