1
|
|
package pro.verron.officestamper.preset.postprocessors.cleanendnotes; |
2
|
|
|
3
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage; |
4
|
|
import org.docx4j.openpackaging.parts.WordprocessingML.EndnotesPart; |
5
|
|
import org.docx4j.wml.CTEndnotes; |
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 RemoveOrphanedEndnotesProcessor |
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 ednPart = mainDocumentPart.getEndNotesPart(); |
28
|
|
Optional.ofNullable(ednPart) |
29
|
|
.stream() |
30
|
|
.map(throwing(EndnotesPart::getContents)) |
31
|
|
.map(CTEndnotes::getEndnote) |
32
|
|
.flatMap(Collection::stream) |
33
|
|
.filter(RemoveOrphanedEndnotesProcessor::normalNotes) |
34
|
2
1. lambda$process$0 : replaced boolean return with true for pro/verron/officestamper/preset/postprocessors/cleanendnotes/RemoveOrphanedEndnotesProcessor::lambda$process$0 → KILLED
2. lambda$process$0 : negated conditional → 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/cleanendnotes/RemoveOrphanedEndnotesProcessor::normalNotes → SURVIVED
2. normalNotes : replaced boolean return with false for pro/verron/officestamper/preset/postprocessors/cleanendnotes/RemoveOrphanedEndnotesProcessor::normalNotes → KILLED
|
return Optional.ofNullable(note.getType()) |
41
|
|
.orElse(NORMAL) |
42
|
|
.equals(NORMAL); |
43
|
|
} |
44
|
|
} |
| | Mutations |
23 |
|
1.1 Location : process Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfEndnotes(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1] removed call to pro/verron/officestamper/core/DocumentUtil::visitDocument → KILLED
|
34 |
|
1.1 Location : lambda$process$0 Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfEndnotes(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1] replaced boolean return with true for pro/verron/officestamper/preset/postprocessors/cleanendnotes/RemoveOrphanedEndnotesProcessor::lambda$process$0 → KILLED
2.2 Location : lambda$process$0 Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfEndnotes(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1] negated conditional → KILLED
|
36 |
|
1.1 Location : process Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfEndnotes(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1] removed call to java/util/List::forEach → KILLED
|
40 |
|
1.1 Location : normalNotes Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfEndnotes(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1] replaced boolean return with false for pro/verron/officestamper/preset/postprocessors/cleanendnotes/RemoveOrphanedEndnotesProcessor::normalNotes → KILLED
2.2 Location : normalNotes Killed by : none replaced boolean return with true for pro/verron/officestamper/preset/postprocessors/cleanendnotes/RemoveOrphanedEndnotesProcessor::normalNotes → SURVIVED
Covering tests
Covered by tests:
- pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfEndnotes(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1]
- pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfEndnotes(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
- pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfFootnotes(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
- pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfFootnotes(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1]
|