DocumentWalker.java

1
package pro.verron.officestamper.core;
2
3
import org.docx4j.XmlUtils;
4
import org.docx4j.wml.*;
5
import org.docx4j.wml.R.CommentReference;
6
import pro.verron.officestamper.api.DocxPart;
7
8
/**
9
 * This class walks the document and calls abstract methods for each element it encounters.
10
 * The following elements are supported:
11
 * <ul>
12
 * <li>{@link P}</li>
13
 * <li>{@link R}</li>
14
 * <li>{@link Tbl}</li>
15
 * <li>{@link Tr}</li>
16
 * <li>{@link Tc}</li>
17
 * <li>{@link CommentRangeStart}</li>
18
 * <li>{@link CommentRangeEnd}</li>
19
 * <li>{@link CommentReference}</li>
20
 * </ul>
21
 * The following elements are not supported:
22
 * <ul>
23
 * <li>{@link SdtBlock}</li>
24
 * <li>{@link SdtRun}</li>
25
 * <li>{@link SdtElement}</li>
26
 * <li>{@link CTSimpleField}</li>
27
 * <li>{@link CTSdtCell}</li>
28
 * <li>{@link CTSdtContentCell}</li>
29
 * </ul>
30
 *
31
 * @author Joseph Verron
32
 * @author Tom Hombergs
33
 * @version ${version}
34
 * @since 1.0.0
35
 */
36
public abstract class DocumentWalker {
37
38
    private final DocxPart source;
39
40
    /**
41
     * Creates a new DocumentWalker that will traverse the given document.
42
     *
43
     * @param source the document to traverse.
44
     */
45
    protected DocumentWalker(DocxPart source) {
46
        this.source = source;
47
    }
48
49
    /**
50
     * Starts the traversal of the document.
51
     */
52
    public void walk() {
53
        for (Object content : source.content()) {
54
            Object ue = XmlUtils.unwrap(content);
55 2 1. walk : negated conditional → KILLED
2. walk : removed call to pro/verron/officestamper/core/DocumentWalker::walkParagraph → KILLED
            if (ue instanceof P o) walkParagraph(o);
56 2 1. walk : removed call to pro/verron/officestamper/core/DocumentWalker::walkRun → NO_COVERAGE
2. walk : negated conditional → KILLED
            else if (ue instanceof R o) walkRun(o);
57 2 1. walk : negated conditional → KILLED
2. walk : removed call to pro/verron/officestamper/core/DocumentWalker::walkTable → KILLED
            else if (ue instanceof Tbl o) walkTable(o);
58 2 1. walk : removed call to pro/verron/officestamper/core/DocumentWalker::walkTableRow → NO_COVERAGE
2. walk : negated conditional → KILLED
            else if (ue instanceof Tr o) walkTableRow(o);
59 2 1. walk : negated conditional → KILLED
2. walk : removed call to pro/verron/officestamper/core/DocumentWalker::walkTableCell → KILLED
            else if (ue instanceof Tc o) walkTableCell(o);
60 2 1. walk : removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeStart → NO_COVERAGE
2. walk : negated conditional → KILLED
            else if (ue instanceof CommentRangeStart o) onCommentRangeStart(o);
61 2 1. walk : removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeEnd → KILLED
2. walk : negated conditional → KILLED
            else if (ue instanceof CommentRangeEnd o) onCommentRangeEnd(o);
62 2 1. walk : removed call to pro/verron/officestamper/core/DocumentWalker::onCommentReference → NO_COVERAGE
2. walk : negated conditional → KILLED
            else if (ue instanceof CommentReference o) onCommentReference(o);
63
        }
64
    }
65
66
    private void walkTable(Tbl table) {
67 1 1. walkTable : removed call to pro/verron/officestamper/core/DocumentWalker::onTable → SURVIVED
        onTable(table);
68
        for (Object contentElement : table.getContent()) {
69
            Object unwrappedObject = XmlUtils.unwrap(contentElement);
70 1 1. walkTable : negated conditional → KILLED
            if (unwrappedObject instanceof Tr row) {
71 1 1. walkTable : removed call to pro/verron/officestamper/core/DocumentWalker::walkTableRow → KILLED
                walkTableRow(row);
72
            }
73
        }
74
    }
75
76
    private void walkTableRow(Tr row) {
77 1 1. walkTableRow : removed call to pro/verron/officestamper/core/DocumentWalker::onTableRow → SURVIVED
        onTableRow(row);
78
        for (Object rowContentElement : row.getContent()) {
79
            Object unwrappedObject = XmlUtils.unwrap(rowContentElement);
80 1 1. walkTableRow : negated conditional → KILLED
            if (unwrappedObject instanceof Tc cell) {
81 1 1. walkTableRow : removed call to pro/verron/officestamper/core/DocumentWalker::walkTableCell → KILLED
                walkTableCell(cell);
82
            }
83
        }
84
    }
85
86
    private void walkTableCell(Tc cell) {
87 1 1. walkTableCell : removed call to pro/verron/officestamper/core/DocumentWalker::onTableCell → SURVIVED
        onTableCell(cell);
88
        for (Object cellContentElement : cell.getContent()) {
89
            Object unwrappedObject = XmlUtils.unwrap(cellContentElement);
90 1 1. walkTableCell : negated conditional → KILLED
            if (unwrappedObject instanceof P) {
91
                P p = (P) cellContentElement;
92 1 1. walkTableCell : removed call to pro/verron/officestamper/core/DocumentWalker::walkParagraph → KILLED
                walkParagraph(p);
93
            }
94 1 1. walkTableCell : negated conditional → KILLED
            else if (unwrappedObject instanceof R) {
95
                R r = (R) cellContentElement;
96 1 1. walkTableCell : removed call to pro/verron/officestamper/core/DocumentWalker::walkRun → NO_COVERAGE
                walkRun(r);
97
            }
98 1 1. walkTableCell : negated conditional → KILLED
            else if (unwrappedObject instanceof Tbl nestedTable) {
99 1 1. walkTableCell : removed call to pro/verron/officestamper/core/DocumentWalker::walkTable → KILLED
                walkTable(nestedTable);
100
            }
101 1 1. walkTableCell : negated conditional → NO_COVERAGE
            else if (unwrappedObject instanceof CommentRangeStart commentRangeStart) {
102 1 1. walkTableCell : removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeStart → NO_COVERAGE
                onCommentRangeStart(commentRangeStart);
103
            }
104 1 1. walkTableCell : negated conditional → NO_COVERAGE
            else if (unwrappedObject instanceof CommentRangeEnd commentRangeEnd) {
105 1 1. walkTableCell : removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeEnd → NO_COVERAGE
                onCommentRangeEnd(commentRangeEnd);
106
            }
107
        }
108
    }
109
110
    private void walkParagraph(P p) {
111 1 1. walkParagraph : removed call to pro/verron/officestamper/core/DocumentWalker::onParagraph → KILLED
        onParagraph(p);
112
        for (Object element : p.getContent()) {
113
            Object unwrappedObject = XmlUtils.unwrap(element);
114 1 1. walkParagraph : negated conditional → KILLED
            if (unwrappedObject instanceof R r) {
115 1 1. walkParagraph : removed call to pro/verron/officestamper/core/DocumentWalker::walkRun → KILLED
                walkRun(r);
116
            }
117 1 1. walkParagraph : negated conditional → KILLED
            else if (unwrappedObject instanceof CommentRangeStart commentRangeStart) {
118 1 1. walkParagraph : removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeStart → KILLED
                onCommentRangeStart(commentRangeStart);
119
            }
120 1 1. walkParagraph : negated conditional → KILLED
            else if (unwrappedObject instanceof CommentRangeEnd commentRangeEnd) {
121 1 1. walkParagraph : removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeEnd → KILLED
                onCommentRangeEnd(commentRangeEnd);
122
            }
123
        }
124
    }
125
126
    private void walkRun(R r) {
127 1 1. walkRun : removed call to pro/verron/officestamper/core/DocumentWalker::onRun → SURVIVED
        onRun(r);
128
        for (Object element : r.getContent()) {
129
            Object unwrappedObject = XmlUtils.unwrap(element);
130 1 1. walkRun : negated conditional → KILLED
            if (unwrappedObject instanceof CommentReference commentReference) {
131 1 1. walkRun : removed call to pro/verron/officestamper/core/DocumentWalker::onCommentReference → KILLED
                onCommentReference(commentReference);
132
            }
133
        }
134
    }
135
136
    /**
137
     * This method is called for every {@link R} element in the document.
138
     *
139
     * @param run the {@link R} element to process.
140
     */
141
    protected abstract void onRun(R run);
142
143
    /**
144
     * This method is called for every {@link P} element in the document.
145
     *
146
     * @param paragraph the {@link P} element to process.
147
     */
148
    protected abstract void onParagraph(P paragraph);
149
150
    /**
151
     * This method is called for every {@link Tbl} element in the document.
152
     *
153
     * @param table the {@link Tbl} element to process.
154
     */
155
    protected abstract void onTable(Tbl table);
156
157
    /**
158
     * This method is called for every {@link Tc} element in the document.
159
     *
160
     * @param tableCell the {@link Tc} element to process.
161
     */
162
    protected abstract void onTableCell(Tc tableCell);
163
164
    /**
165
     * This method is called for every {@link Tr} element in the document.
166
     *
167
     * @param tableRow the {@link Tr} element to process.
168
     */
169
    protected abstract void onTableRow(Tr tableRow);
170
171
    /**
172
     * This method is called for every {@link CommentRangeStart} element in the document.
173
     *
174
     * @param commentRangeStart the {@link CommentRangeStart} element to process.
175
     */
176
    protected abstract void onCommentRangeStart(CommentRangeStart commentRangeStart);
177
178
    /**
179
     * This method is called for every {@link CommentRangeEnd} element in the document.
180
     *
181
     * @param commentRangeEnd the {@link CommentRangeEnd} element to process.
182
     */
183
    protected abstract void onCommentRangeEnd(CommentRangeEnd commentRangeEnd);
184
185
    /**
186
     * This method is called for every {@link CommentReference} element in the document.
187
     *
188
     * @param commentReference the {@link CommentReference} element to process.
189
     */
190
    protected abstract void onCommentReference(CommentReference commentReference);
191
}

Mutations

55

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

2.2
Location : walk
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[method:fails()]
removed call to pro/verron/officestamper/core/DocumentWalker::walkParagraph → KILLED

56

1.1
Location : walk
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::walkRun → NO_COVERAGE

2.2
Location : walk
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#27]
negated conditional → KILLED

57

1.1
Location : walk
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#39]
negated conditional → KILLED

2.2
Location : walk
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#22]
removed call to pro/verron/officestamper/core/DocumentWalker::walkTable → KILLED

58

1.1
Location : walk
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::walkTableRow → NO_COVERAGE

2.2
Location : walk
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#39]
negated conditional → KILLED

59

1.1
Location : walk
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#39]
negated conditional → KILLED

2.2
Location : walk
Killed by : pro.verron.officestamper.test.MultiStampTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.MultiStampTest]/[method:expressionsAreResolvedOnMultiStamp()]
removed call to pro/verron/officestamper/core/DocumentWalker::walkTableCell → KILLED

60

1.1
Location : walk
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#39]
negated conditional → KILLED

2.2
Location : walk
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeStart → NO_COVERAGE

61

1.1
Location : walk
Killed by : pro.verron.officestamper.test.RepeatDocPartBadPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RepeatDocPartBadPlaceholderTest]/[method:testBadExpressionShouldNotBlockCallerThread()]
removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeEnd → KILLED

2.2
Location : walk
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#39]
negated conditional → KILLED

62

1.1
Location : walk
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::onCommentReference → NO_COVERAGE

2.2
Location : walk
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#39]
negated conditional → KILLED

67

1.1
Location : walkTable
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::onTable → SURVIVED
Covering tests

70

1.1
Location : walkTable
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#22]
negated conditional → KILLED

71

1.1
Location : walkTable
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#22]
removed call to pro/verron/officestamper/core/DocumentWalker::walkTableRow → KILLED

77

1.1
Location : walkTableRow
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::onTableRow → SURVIVED
Covering tests

80

1.1
Location : walkTableRow
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#22]
negated conditional → KILLED

81

1.1
Location : walkTableRow
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#22]
removed call to pro/verron/officestamper/core/DocumentWalker::walkTableCell → KILLED

87

1.1
Location : walkTableCell
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::onTableCell → SURVIVED
Covering tests

90

1.1
Location : walkTableCell
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#27]
negated conditional → KILLED

92

1.1
Location : walkTableCell
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#22]
removed call to pro/verron/officestamper/core/DocumentWalker::walkParagraph → KILLED

94

1.1
Location : walkTableCell
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#27]
negated conditional → KILLED

96

1.1
Location : walkTableCell
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::walkRun → NO_COVERAGE

98

1.1
Location : walkTableCell
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#22]
negated conditional → KILLED

99

1.1
Location : walkTableCell
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#22]
removed call to pro/verron/officestamper/core/DocumentWalker::walkTable → KILLED

101

1.1
Location : walkTableCell
Killed by : none
negated conditional → NO_COVERAGE

102

1.1
Location : walkTableCell
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeStart → NO_COVERAGE

104

1.1
Location : walkTableCell
Killed by : none
negated conditional → NO_COVERAGE

105

1.1
Location : walkTableCell
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeEnd → NO_COVERAGE

111

1.1
Location : walkParagraph
Killed by : pro.verron.officestamper.test.MultiStampTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.MultiStampTest]/[method:expressionsAreResolvedOnMultiStamp()]
removed call to pro/verron/officestamper/core/DocumentWalker::onParagraph → KILLED

114

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

115

1.1
Location : walkParagraph
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#30]
removed call to pro/verron/officestamper/core/DocumentWalker::walkRun → KILLED

117

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

118

1.1
Location : walkParagraph
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[method:doesNotFail()]
removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeStart → KILLED

120

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

121

1.1
Location : walkParagraph
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[method:fails()]
removed call to pro/verron/officestamper/core/DocumentWalker::onCommentRangeEnd → KILLED

127

1.1
Location : walkRun
Killed by : none
removed call to pro/verron/officestamper/core/DocumentWalker::onRun → SURVIVED
Covering tests

130

1.1
Location : walkRun
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#17]
negated conditional → KILLED

131

1.1
Location : walkRun
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#30]
removed call to pro/verron/officestamper/core/DocumentWalker::onCommentReference → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0