DisplayIfProcessor.java

1
package pro.verron.officestamper.preset.processors.displayif;
2
3
import org.docx4j.wml.ContentAccessor;
4
import org.docx4j.wml.Tbl;
5
import org.docx4j.wml.Tr;
6
import org.jvnet.jaxb2_commons.ppp.Child;
7
import org.springframework.lang.Nullable;
8
import pro.verron.officestamper.api.*;
9
import pro.verron.officestamper.preset.CommentProcessorFactory;
10
import pro.verron.officestamper.utils.WmlUtils;
11
12
import java.util.ArrayList;
13
import java.util.List;
14
15
import static pro.verron.officestamper.api.OfficeStamperException.throwing;
16
17
/// Processor for the [CommentProcessorFactory.IDisplayIfProcessor] comment.
18
///
19
/// @author Joseph Verron
20
/// @author Tom Hombergs
21
/// @version ${version}
22
/// @since 1.0.0
23
public class DisplayIfProcessor
24
        extends AbstractCommentProcessor
25
        implements CommentProcessorFactory.IDisplayIfProcessor {
26
27
    private List<Paragraph> paragraphsToBeRemoved = new ArrayList<>();
28
    private List<Child> elementsToBeRemoved = new ArrayList<>();
29
30
    private DisplayIfProcessor(ParagraphPlaceholderReplacer placeholderReplacer) {
31
        super(placeholderReplacer);
32
    }
33
34
    /// Creates a new DisplayIfProcessor instance.
35
    ///
36
    /// @param pr the [ParagraphPlaceholderReplacer] used for replacing expressions.
37
    ///
38
    /// @return a new DisplayIfProcessor instance.
39
    public static CommentProcessor newInstance(ParagraphPlaceholderReplacer pr) {
40 1 1. newInstance : replaced return value with null for pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::newInstance → KILLED
        return new DisplayIfProcessor(pr);
41
    }
42
43
    @Override
44
    public void commitChanges(DocxPart source) {
45 1 1. commitChanges : removed call to java/util/List::forEach → KILLED
        paragraphsToBeRemoved.forEach(Paragraph::remove);
46 1 1. commitChanges : removed call to java/util/List::forEach → KILLED
        elementsToBeRemoved.forEach(WmlUtils::remove);
47
    }
48
49
50
    @Override
51
    public void reset() {
52
        paragraphsToBeRemoved = new ArrayList<>();
53
        elementsToBeRemoved = new ArrayList<>();
54
    }
55
56
    @Override
57
    public void displayParagraphIfAbsent(@Nullable Object condition) {
58 2 1. displayParagraphIfAbsent : negated conditional → KILLED
2. displayParagraphIfAbsent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayParagraphIf → KILLED
        displayParagraphIf(condition == null);
59
    }
60
61
    @Override
62
    public void displayParagraphIf(@Nullable Boolean condition) {
63 1 1. displayParagraphIf : negated conditional → KILLED
        if (Boolean.TRUE.equals(condition)) return;
64
        paragraphsToBeRemoved.add(this.getParagraph());
65
    }
66
67
    @Override
68
    public void displayParagraphIfPresent(@Nullable Object condition) {
69 2 1. displayParagraphIfPresent : negated conditional → KILLED
2. displayParagraphIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayParagraphIf → KILLED
        displayParagraphIf(condition != null);
70
    }
71
72
73
    @Override
74
    public void displayTableRowIf(@Nullable Boolean condition) {
75 1 1. displayTableRowIf : negated conditional → KILLED
        if (Boolean.TRUE.equals(condition)) return;
76
        var tr = this.getParagraph()
77
                     .parent(Tr.class)
78
                     .orElseThrow(throwing("Paragraph is not within a row!"));
79
        elementsToBeRemoved.add(tr);
80
    }
81
82
    @Override
83
    public void displayTableRowIfPresent(@Nullable Object condition) {
84 2 1. displayTableRowIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableRowIf → KILLED
2. displayTableRowIfPresent : negated conditional → KILLED
        displayTableRowIf(condition != null);
85
    }
86
87
    @Override
88
    public void displayTableRowIfAbsent(@Nullable Object condition) {
89 2 1. displayTableRowIfAbsent : negated conditional → KILLED
2. displayTableRowIfAbsent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableRowIf → KILLED
        displayTableRowIf(condition == null);
90
    }
91
92
    @Override
93
    public void displayTableIf(Boolean condition) {
94 1 1. displayTableIf : negated conditional → KILLED
        if (Boolean.TRUE.equals(condition)) return;
95
        var tbl = this.getParagraph()
96
                      .parent(Tbl.class)
97
                      .orElseThrow(throwing("Paragraph is not within a table!"));
98
        elementsToBeRemoved.add(tbl);
99
    }
100
101
    @Override
102
    public void displayTableIfPresent(@Nullable Object condition) {
103 2 1. displayTableIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableIf → KILLED
2. displayTableIfPresent : negated conditional → KILLED
        displayTableIf(condition != null);
104
    }
105
106
    @Override
107
    public void displayTableIfAbsent(@Nullable Object condition) {
108 2 1. displayTableIfAbsent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableIf → KILLED
2. displayTableIfAbsent : negated conditional → KILLED
        displayTableIf(condition == null);
109
    }
110
111
    @Override
112
    public void displayWordsIf(@Nullable Boolean condition) {
113 1 1. displayWordsIf : negated conditional → KILLED
        if (Boolean.TRUE.equals(condition)) return;
114
        var commentWrapper = getCurrentCommentWrapper();
115
        var start = commentWrapper.getCommentRangeStart();
116
        var end = commentWrapper.getCommentRangeEnd();
117
        var parent = (ContentAccessor) start.getParent();
118
        var startIndex = parent.getContent()
119
                               .indexOf(start);
120
        var iterator = parent.getContent()
121
                             .listIterator(startIndex);
122 1 1. displayWordsIf : negated conditional → KILLED
        while (iterator.hasNext()) {
123
            var it = iterator.next();
124
            elementsToBeRemoved.add((Child) it);
125 1 1. displayWordsIf : negated conditional → KILLED
            if (it.equals(end))
126
                break;
127
        }
128
    }
129
130
    @Override
131
    public void displayWordsIfPresent(@Nullable Object condition) {
132 2 1. displayWordsIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayWordsIf → KILLED
2. displayWordsIfPresent : negated conditional → KILLED
        displayWordsIf(condition != null);
133
    }
134
135
    @Override
136
    public void displayWordsIfAbsent(@Nullable Object condition) {
137 2 1. displayWordsIfAbsent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayWordsIf → KILLED
2. displayWordsIfAbsent : negated conditional → KILLED
        displayWordsIf(condition == null);
138
    }
139
140
    @Override
141
    public void displayDocPartIf(@Nullable Boolean condition) {
142 1 1. displayDocPartIf : negated conditional → KILLED
        if (Boolean.TRUE.equals(condition)) return;
143
        var commentWrapper = getCurrentCommentWrapper();
144
        commentWrapper.getParent()
145
                      .getContent()
146
                      .removeAll(commentWrapper.getElements());
147
    }
148
149
    @Override
150
    public void displayDocPartIfPresent(@Nullable Object condition) {
151 2 1. displayDocPartIfPresent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayDocPartIf → KILLED
2. displayDocPartIfPresent : negated conditional → KILLED
        displayDocPartIf(condition != null);
152
    }
153
154
    @Override
155
    public void displayDocPartIfAbsent(@Nullable Object condition) {
156 2 1. displayDocPartIfAbsent : removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayDocPartIf → KILLED
2. displayDocPartIfAbsent : negated conditional → KILLED
        displayDocPartIf(condition == null);
157
    }
158
}

Mutations

40

1.1
Location : newInstance
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testStaticResolution(java.lang.String, boolean, boolean, boolean, java.lang.String, java.lang.String)]/[test-template-invocation:#7]
replaced return value with null for pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::newInstance → KILLED

45

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

46

1.1
Location : commitChanges
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfTableRowsTest(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1]
removed call to java/util/List::forEach → KILLED

58

1.1
Location : displayParagraphIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

2.2
Location : displayParagraphIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayParagraphIf → KILLED

63

1.1
Location : displayParagraphIf
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfTableBug32Test(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

69

1.1
Location : displayParagraphIfPresent
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:#33]
negated conditional → KILLED

2.2
Location : displayParagraphIfPresent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfAbsentValue(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayParagraphIf → KILLED

75

1.1
Location : displayTableRowIf
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfTableRowsTest(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#1]
negated conditional → KILLED

84

1.1
Location : displayTableRowIfPresent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfAbsentValue(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableRowIf → KILLED

2.2
Location : displayTableRowIfPresent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

89

1.1
Location : displayTableRowIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

2.2
Location : displayTableRowIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableRowIf → KILLED

94

1.1
Location : displayTableIf
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfTableBug32Test(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

103

1.1
Location : displayTableIfPresent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfAbsentValue(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableIf → KILLED

2.2
Location : displayTableIfPresent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

108

1.1
Location : displayTableIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayTableIf → KILLED

2.2
Location : displayTableIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

113

1.1
Location : displayWordsIf
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

122

1.1
Location : displayWordsIf
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

125

1.1
Location : displayWordsIf
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

132

1.1
Location : displayWordsIfPresent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfAbsentValue(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayWordsIf → KILLED

2.2
Location : displayWordsIfPresent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

137

1.1
Location : displayWordsIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayWordsIf → KILLED

2.2
Location : displayWordsIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

142

1.1
Location : displayDocPartIf
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

151

1.1
Location : displayDocPartIfPresent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfAbsentValue(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayDocPartIf → KILLED

2.2
Location : displayDocPartIfPresent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

156

1.1
Location : displayDocPartIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
removed call to pro/verron/officestamper/preset/processors/displayif/DisplayIfProcessor::displayDocPartIf → KILLED

2.2
Location : displayDocPartIfAbsent
Killed by : pro.verron.officestamper.test.ConditionalDisplayTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ConditionalDisplayTest]/[test-template:conditionalDisplayOfHomer(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.20.0