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.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.core.DocumentUtil.visitDocument; | |
17 | ||
18 | public class RemoveOrphanedFootnotesProcessor | |
19 | implements PostProcessor { | |
20 | @Override | |
21 | public void process(WordprocessingMLPackage document) { | |
22 | var visitor = new NoteRefsVisitor(); | |
23 |
1
1. process : removed call to pro/verron/officestamper/core/DocumentUtil::visitDocument → KILLED |
visitDocument(document, visitor); |
24 | var referencedNoteIds = visitor.referencedNoteIds(); | |
25 | var mainDocumentPart = document.getMainDocumentPart(); | |
26 | ||
27 | var ftnPart = mainDocumentPart.getFootnotesPart(); | |
28 | Optional.ofNullable(ftnPart) | |
29 | .stream() | |
30 | .map(throwing(FootnotesPart::getContents)) | |
31 | .map(CTFootnotes::getFootnote) | |
32 | .flatMap(Collection::stream) | |
33 | .filter(RemoveOrphanedFootnotesProcessor::normalNotes) | |
34 |
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())) |
35 | .toList() | |
36 |
1
1. process : removed call to java/util/List::forEach → KILLED |
.forEach(WmlUtils::remove); |
37 | } | |
38 | ||
39 | private static boolean normalNotes(CTFtnEdn note) { | |
40 |
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()) |
41 | .orElse(NORMAL) | |
42 | .equals(NORMAL); | |
43 | } | |
44 | } | |
Mutations | ||
23 |
1.1 |
|
34 |
1.1 2.2 |
|
36 |
1.1 |
|
40 |
1.1 2.2 |