Search in sources :

Example 16 with GroupedFile

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile in project Artemis by ls1intum.

the class CreateSolutionEntries method executeAction.

@Override
public boolean executeAction() {
    var solutionEntries = new ArrayList<ProgrammingExerciseSolutionEntry>();
    for (GroupedFile groupedFile : blackboard.getGroupedFiles()) {
        for (GroupedFile.ChangeBlock changeBlock : groupedFile.getCommonChanges()) {
            if (!changeBlock.isPotential()) {
                solutionEntries.add(createSolutionEntry(groupedFile, changeBlock));
            }
        }
    }
    if (solutionEntries.equals(blackboard.getSolutionEntries())) {
        return false;
    }
    blackboard.setSolutionEntries(solutionEntries);
    return !blackboard.getSolutionEntries().isEmpty();
}
Also used : GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) ArrayList(java.util.ArrayList)

Example 17 with GroupedFile

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile in project Artemis by ls1intum.

the class FindCommonLines method executeAction.

@Override
public boolean executeAction() {
    for (GroupedFile groupedFile : blackboard.getGroupedFiles()) {
        List<Integer> commonLines = new ArrayList<>(groupedFile.getCoveredLines());
        commonLines.retainAll(groupedFile.getChangedLines());
        groupedFile.setCommonLines(commonLines);
    }
    return !blackboard.getGroupedFiles().stream().allMatch(groupedFile -> groupedFile.getCommonLines().isEmpty());
}
Also used : List(java.util.List) GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) BehavioralBlackboard(de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralBlackboard) ArrayList(java.util.ArrayList) GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) ArrayList(java.util.ArrayList)

Example 18 with GroupedFile

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile in project ArTEMiS by ls1intum.

the class AddUncoveredLinesAsPotentialCodeBlocks method executeAction.

@Override
public boolean executeAction() {
    boolean didChanges = false;
    for (GroupedFile groupedFile : blackboard.getGroupedFiles()) {
        var newChangeBlocks = new TreeSet<ChangeBlock>();
        for (ChangeBlock commonChange : groupedFile.getCommonChanges()) {
            var firstLine = commonChange.getLines().first();
            var potentialPrefix = getPotentialPrefix(firstLine, groupedFile.getFileContent());
            if (potentialPrefix != null) {
                newChangeBlocks.add(potentialPrefix);
            }
            var lastLine = commonChange.getLines().last();
            var potentialPostfix = getPotentialPostfix(lastLine, groupedFile.getFileContent());
            if (potentialPostfix != null) {
                newChangeBlocks.add(potentialPostfix);
            }
        }
        if (!newChangeBlocks.isEmpty()) {
            groupedFile.getCommonChanges().addAll(newChangeBlocks);
            didChanges = true;
        }
    }
    return didChanges;
}
Also used : TreeSet(java.util.TreeSet) GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) ChangeBlock(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock)

Example 19 with GroupedFile

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile in project ArTEMiS by ls1intum.

the class CombineChangeBlocks method executeAction.

@Override
public boolean executeAction() throws BehavioralSolutionEntryGenerationException {
    boolean didChanges = false;
    for (GroupedFile groupedFile : blackboard.getGroupedFiles()) {
        while (true) {
            var currentChangeBlocks = new ArrayList<>(groupedFile.getCommonChanges());
            var newChangeBlocks = new ArrayList<GroupedFile.ChangeBlock>();
            for (int i = 0; i < currentChangeBlocks.size(); i++) {
                var currentChangeBlock = currentChangeBlocks.get(i);
                // If this is not the last change block check if it can be merged with the next change block
                if (i < currentChangeBlocks.size() - 1) {
                    var nextChangeBlock = currentChangeBlocks.get(i + 1);
                    if (currentChangeBlock.intersectsOrTouches(nextChangeBlock)) {
                        var lines = new TreeSet<>(currentChangeBlock.getLines());
                        lines.addAll(nextChangeBlock.getLines());
                        newChangeBlocks.add(new GroupedFile.ChangeBlock(lines));
                        // Skip the next change block, as it has already been processed
                        i++;
                        continue;
                    }
                }
                newChangeBlocks.add(currentChangeBlock);
            }
            if (!newChangeBlocks.equals(currentChangeBlocks)) {
                groupedFile.setCommonChanges(newChangeBlocks);
                didChanges = true;
            } else {
                break;
            }
        }
    }
    return didChanges;
}
Also used : TreeSet(java.util.TreeSet) GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) ArrayList(java.util.ArrayList)

Example 20 with GroupedFile

use of de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile in project ArTEMiS by ls1intum.

the class CreateSolutionEntries method executeAction.

@Override
public boolean executeAction() {
    var solutionEntries = new ArrayList<ProgrammingExerciseSolutionEntry>();
    for (GroupedFile groupedFile : blackboard.getGroupedFiles()) {
        for (GroupedFile.ChangeBlock changeBlock : groupedFile.getCommonChanges()) {
            if (!changeBlock.isPotential()) {
                solutionEntries.add(createSolutionEntry(groupedFile, changeBlock));
            }
        }
    }
    if (solutionEntries.equals(blackboard.getSolutionEntries())) {
        return false;
    }
    blackboard.setSolutionEntries(solutionEntries);
    return !blackboard.getSolutionEntries().isEmpty();
}
Also used : GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) ArrayList(java.util.ArrayList)

Aggregations

GroupedFile (de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile)32 ArrayList (java.util.ArrayList)20 BehavioralBlackboard (de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralBlackboard)16 BeforeEach (org.junit.jupiter.api.BeforeEach)14 ProgrammingExerciseTestCase (de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase)8 TreeSet (java.util.TreeSet)6 Test (org.junit.jupiter.api.Test)6 BehavioralSolutionEntryGenerationException (de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralSolutionEntryGenerationException)2 ChangeBlock (de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile.ChangeBlock)2 CombineChangeBlocks (de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.CombineChangeBlocks)2 CreateCommonChangeBlocks (de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.CreateCommonChangeBlocks)2 CreateSolutionEntries (de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.CreateSolutionEntries)2 ExtractChangedLines (de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.ExtractChangedLines)2 ExtractCoveredLines (de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.ExtractCoveredLines)2 FindCommonLines (de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.FindCommonLines)2 InsertFileContents (de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.InsertFileContents)2 List (java.util.List)2