Search in sources :

Example 11 with GroupedFile

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

the class CreateCommonChangeBlocksTest method initBlackboard.

@BeforeEach
public void initBlackboard() {
    BehavioralBlackboard blackboard = new BehavioralBlackboard(null, null, null);
    var groupedFiles = new ArrayList<GroupedFile>();
    blackboard.setGroupedFiles(groupedFiles);
    groupedFile = new GroupedFile("test.java", null, null, null);
    groupedFiles.add(groupedFile);
    createCommonChangeBlocks = new CreateCommonChangeBlocks(blackboard);
}
Also used : BehavioralBlackboard(de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralBlackboard) CreateCommonChangeBlocks(de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.CreateCommonChangeBlocks) GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) ArrayList(java.util.ArrayList) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with GroupedFile

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

the class CreateSolutionEntriesTest method initBlackboard.

@BeforeEach
public void initBlackboard() {
    blackboard = new BehavioralBlackboard(null, null, null);
    var groupedFiles = new ArrayList<GroupedFile>();
    blackboard.setGroupedFiles(groupedFiles);
    groupedFile = new GroupedFile("test.java", new ProgrammingExerciseTestCase(), null, null);
    groupedFiles.add(groupedFile);
    createSolutionEntries = new CreateSolutionEntries(blackboard);
}
Also used : BehavioralBlackboard(de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralBlackboard) GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) CreateSolutionEntries(de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.CreateSolutionEntries) ArrayList(java.util.ArrayList) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with GroupedFile

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

the class ExtractChangedLinesTest method initBlackboard.

@BeforeEach
public void initBlackboard() {
    BehavioralBlackboard blackboard = new BehavioralBlackboard(null, null, null);
    var groupedFiles = new ArrayList<GroupedFile>();
    blackboard.setGroupedFiles(groupedFiles);
    gitDiffEntries = new HashSet<>();
    groupedFile = new GroupedFile("test.java", null, gitDiffEntries, null);
    groupedFiles.add(groupedFile);
    extractChangedLines = new ExtractChangedLines(blackboard);
}
Also used : BehavioralBlackboard(de.tum.in.www1.artemis.service.hestia.behavioral.BehavioralBlackboard) ExtractChangedLines(de.tum.in.www1.artemis.service.hestia.behavioral.knowledgesource.ExtractChangedLines) GroupedFile(de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile) ArrayList(java.util.ArrayList) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 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 15 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)

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