RepeatRowProcessor.java

1
package pro.verron.officestamper.preset.processors.repeatrow;
2
3
import org.jspecify.annotations.Nullable;
4
import pro.verron.officestamper.api.CommentProcessor;
5
import pro.verron.officestamper.api.OfficeStamperException;
6
import pro.verron.officestamper.api.ProcessorContext;
7
import pro.verron.officestamper.preset.CommentProcessorFactory;
8
9
/// Repeats a table row for each element in a list.
10
///
11
/// @author Joseph Verron
12
/// @author Tom Hombergs
13
/// @since 1.0.0
14
public class RepeatRowProcessor
15
        extends CommentProcessor
16
        implements CommentProcessorFactory.IRepeatRowProcessor {
17
18
19
    /// Constructs a new RepeatRowProcessor with the given processor context.
20
    ///
21
    /// @param processorContext the context in which this processor operates, containing information about the
22
    ///         document and processing environment
23
    public RepeatRowProcessor(ProcessorContext processorContext) {
24
        super(processorContext);
25
    }
26
27
    @Override
28
    public void repeatTableRow(@Nullable Iterable<Object> items) {
29 1 1. repeatTableRow : negated conditional → KILLED
        if (items == null) return;
30
31
        var contextHolder = context().contextHolder();
32
        var row = context().paragraph()
33
                           .parentTableRow()
34
                           .orElseThrow(OfficeStamperException.throwing("This paragraph is not in a table row."));
35 1 1. repeatTableRow : removed call to pro/verron/officestamper/api/Table$Row::removeComment → KILLED
        row.removeComment(comment());
36
37
        var table = row.table();
38
        var index = table.indexOf(row);
39
        for (Object item : items) {
40
            var copy = row.copy();
41
            var contextKey = contextHolder.addBranch(item);
42
            copy.hooks()
43 2 1. lambda$repeatTableRow$0 : removed call to pro/verron/officestamper/api/Hook::setContextKey → KILLED
2. repeatTableRow : removed call to java/lang/Iterable::forEach → KILLED
                .forEach(hook -> hook.setContextKey(contextKey));
44 2 1. repeatTableRow : removed call to pro/verron/officestamper/api/Table::add → KILLED
2. repeatTableRow : Changed increment from 1 to -1 → KILLED
            table.add(index++, copy);
45
        }
46 1 1. repeatTableRow : removed call to pro/verron/officestamper/api/Table$Row::remove → KILLED
        row.remove();
47
    }
48
}

Mutations

29

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

35

1.1
Location : repeatTableRow
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test114()]
removed call to pro/verron/officestamper/api/Table$Row::removeComment → KILLED

43

1.1
Location : lambda$repeatTableRow$0
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test114()]
removed call to pro/verron/officestamper/api/Hook::setContextKey → KILLED

2.2
Location : repeatTableRow
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test114()]
removed call to java/lang/Iterable::forEach → KILLED

44

1.1
Location : repeatTableRow
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test114()]
removed call to pro/verron/officestamper/api/Table::add → KILLED

2.2
Location : repeatTableRow
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test114()]
Changed increment from 1 to -1 → KILLED

46

1.1
Location : repeatTableRow
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test114()]
removed call to pro/verron/officestamper/api/Table$Row::remove → KILLED

Active mutators

Tests examined


Report generated by PIT 1.25.5 support