RemoveOrphanedFootnotesProcessor.java

1
package pro.verron.officestamper.preset.postprocessors.cleanfootnotes;
2
3
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
4
import org.docx4j.openpackaging.parts.WordprocessingML.FootnotesPart;
5
import org.docx4j.wml.CTFootnotes;
6
import org.docx4j.wml.CTFtnEdn;
7
import pro.verron.officestamper.api.PostProcessor;
8
import pro.verron.officestamper.preset.postprocessors.NoteRefsVisitor;
9
import pro.verron.officestamper.utils.wml.WmlUtils;
10
11
import java.util.Collection;
12
import java.util.Optional;
13
14
import static org.docx4j.wml.STFtnEdn.NORMAL;
15
import static pro.verron.officestamper.api.OfficeStamperException.throwing;
16
import static pro.verron.officestamper.utils.wml.WmlUtils.visitDocument;
17
18
/// A post-processor implementation that removes orphaned footnotes from a Word document.
19
///
20
/// This processor analyzes the document to find footnote references and removes any footnotes that are not referenced
21
/// in the document content. It only processes normal footnotes, ignoring special footnote types like endnotes.
22
///
23
/// @author Joseph Verron
24
public class RemoveOrphanedFootnotesProcessor
25
        implements PostProcessor {
26
    @Override
27
    public void process(WordprocessingMLPackage document) {
28
        var visitor = new NoteRefsVisitor();
29 1 1. process : removed call to pro/verron/officestamper/utils/wml/WmlUtils::visitDocument → KILLED
        visitDocument(document, visitor);
30
        var referencedNoteIds = visitor.referencedNoteIds();
31
        var mainDocumentPart = document.getMainDocumentPart();
32
33
        var ftnPart = mainDocumentPart.getFootnotesPart();
34
        Optional.ofNullable(ftnPart)
35
                .stream()
36
                .map(throwing(FootnotesPart::getContents))
37
                .map(CTFootnotes::getFootnote)
38
                .flatMap(Collection::stream)
39
                .filter(RemoveOrphanedFootnotesProcessor::normalNotes)
40 2 1. lambda$process$0 : negated conditional → KILLED
2. lambda$process$0 : replaced boolean return with true for pro/verron/officestamper/preset/postprocessors/cleanfootnotes/RemoveOrphanedFootnotesProcessor::lambda$process$0 → KILLED
                .filter(note -> !referencedNoteIds.contains(note.getId()))
41
                .toList()
42 1 1. process : removed call to java/util/List::forEach → KILLED
                .forEach(WmlUtils::remove);
43
    }
44
45
    private static boolean normalNotes(CTFtnEdn note) {
46 2 1. normalNotes : replaced boolean return with true for pro/verron/officestamper/preset/postprocessors/cleanfootnotes/RemoveOrphanedFootnotesProcessor::normalNotes → SURVIVED
2. normalNotes : replaced boolean return with false for pro/verron/officestamper/preset/postprocessors/cleanfootnotes/RemoveOrphanedFootnotesProcessor::normalNotes → KILLED
        return Optional.ofNullable(note.getType())
47
                       .orElse(NORMAL)
48
                       .equals(NORMAL);
49
    }
50
}

Mutations

29

1.1
Location : process
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfFootnotes(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/utils/wml/WmlUtils::visitDocument → KILLED

40

1.1
Location : lambda$process$0
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfFootnotes(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

2.2
Location : lambda$process$0
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfFootnotes(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced boolean return with true for pro/verron/officestamper/preset/postprocessors/cleanfootnotes/RemoveOrphanedFootnotesProcessor::lambda$process$0 → KILLED

42

1.1
Location : process
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfFootnotes(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
removed call to java/util/List::forEach → KILLED

46

1.1
Location : normalNotes
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfFootnotes(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced boolean return with false for pro/verron/officestamper/preset/postprocessors/cleanfootnotes/RemoveOrphanedFootnotesProcessor::normalNotes → KILLED

2.2
Location : normalNotes
Killed by : none
replaced boolean return with true for pro/verron/officestamper/preset/postprocessors/cleanfootnotes/RemoveOrphanedFootnotesProcessor::normalNotes → SURVIVED
Covering tests

Active mutators

Tests examined


Report generated by PIT 1.25.5 support