MergeSameStyleRuns.java

1
package pro.verron.officestamper.preset.preprocessors.similarrun;
2
3
import org.docx4j.TraversalUtil;
4
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
5
import org.docx4j.wml.ContentAccessor;
6
import org.docx4j.wml.R;
7
import pro.verron.officestamper.api.PreProcessor;
8
9
import java.util.LinkedHashSet;
10
import java.util.List;
11
12
public class MergeSameStyleRuns
13
        implements PreProcessor {
14
15
    /**
16
     * {@inheritDoc}
17
     */
18
    @Override
19
    public void process(WordprocessingMLPackage document) {
20
        var mainDocumentPart = document.getMainDocumentPart();
21
        var visitor = new SimilarRunVisitor();
22 1 1. process : removed call to org/docx4j/TraversalUtil::visit → SURVIVED
        TraversalUtil.visit(mainDocumentPart, visitor);
23
        for (List<R> similarStyleRuns : visitor.getSimilarStyleRuns()) {
24
            R firstRun = similarStyleRuns.getFirst();
25
            var runContent = firstRun.getContent();
26
            var firstRunContent = new LinkedHashSet<>(runContent);
27
            var firstRunParentContent = ((ContentAccessor) firstRun.getParent()).getContent();
28
            for (R r : similarStyleRuns.subList(1, similarStyleRuns.size())) {
29
                firstRunParentContent.remove(r);
30
                firstRunContent.addAll(r.getContent());
31
            }
32 1 1. process : removed call to java/util/List::clear → KILLED
            runContent.clear();
33
            runContent.addAll(firstRunContent);
34
        }
35
    }
36
}

Mutations

22

1.1
Location : process
Killed by : none
removed call to org/docx4j/TraversalUtil::visit → SURVIVED
Covering tests

32

1.1
Location : process
Killed by : pro.verron.officestamper.test.SpelInstantiationTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.SpelInstantiationTest]/[method:testDateInstantiationAndResolution()]
removed call to java/util/List::clear → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1