CommentRemover.java

1
package pro.verron.officestamper.api;
2
3
import org.docx4j.TraversalUtil;
4
import org.docx4j.finders.CommentFinder;
5
import org.docx4j.openpackaging.exceptions.Docx4JException;
6
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
7
import org.docx4j.wml.Comments;
8
import org.docx4j.wml.ContentAccessor;
9
import org.jvnet.jaxb2_commons.ppp.Child;
10
11
public class CommentRemover
12
        implements PostProcessor {
13
    @Override
14
    public void process(WordprocessingMLPackage document) {
15
        var visitor = new CommentFinder();
16 1 1. process : removed call to org/docx4j/TraversalUtil::visit → TIMED_OUT
        TraversalUtil.visit(document.getMainDocumentPart(), visitor);
17
18
        // Replaces tags with their content in parent
19
        for (Child commentElement : visitor.getCommentElements()) {
20
            var parent = (ContentAccessor) commentElement.getParent();
21
            var siblings = parent.getContent();
22
            siblings.remove(commentElement);
23
        }
24
25
        var mainDocumentPart = document.getMainDocumentPart();
26 1 1. process : negated conditional → TIMED_OUT
        if (mainDocumentPart == null) return;
27
28
        var commentsPart = mainDocumentPart.getCommentsPart();
29 1 1. process : negated conditional → KILLED
        if (commentsPart == null) return;
30
31
        Comments commentsPartContents;
32
        try {
33
            commentsPartContents = commentsPart.getContents();
34
        } catch (Docx4JException e) {
35
            throw new OfficeStamperException(e);
36
        }
37
38 1 1. process : negated conditional → TIMED_OUT
        if (commentsPartContents == null) return;
39
        var comments = commentsPartContents.getComment();
40
41 1 1. process : negated conditional → TIMED_OUT
        if (comments == null) return;
42 1 1. process : removed call to java/util/List::clear → TIMED_OUT
        comments.clear();
43
    }
44
}

Mutations

16

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

26

1.1
Location : process
Killed by : none
negated conditional → TIMED_OUT

29

1.1
Location : process
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:testTableOfContent()]
negated conditional → KILLED

38

1.1
Location : process
Killed by : none
negated conditional → TIMED_OUT

41

1.1
Location : process
Killed by : none
negated conditional → TIMED_OUT

42

1.1
Location : process
Killed by : none
removed call to java/util/List::clear → TIMED_OUT

Active mutators

Tests examined


Report generated by PIT 1.22.0