| 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 | /// @version ${version} | |
| 14 | /// @since 1.0.0 | |
| 15 | public class RepeatRowProcessor | |
| 16 | extends CommentProcessor | |
| 17 | implements CommentProcessorFactory.IRepeatRowProcessor { | |
| 18 | ||
| 19 | ||
| 20 | /// Constructs a new RepeatRowProcessor with the given processor context. | |
| 21 | /// | |
| 22 | /// @param processorContext the context in which this processor operates, containing information about the | |
| 23 | /// document and processing environment | |
| 24 | public RepeatRowProcessor(ProcessorContext processorContext) { | |
| 25 | super(processorContext); | |
| 26 | } | |
| 27 | ||
| 28 | @Override | |
| 29 | public void repeatTableRow(@Nullable Iterable<Object> items) { | |
| 30 |
1
1. repeatTableRow : negated conditional → KILLED |
if (items == null) return; |
| 31 | ||
| 32 | var contextHolder = context().contextHolder(); | |
| 33 | var row = context().paragraph() | |
| 34 | .parentTableRow() | |
| 35 | .orElseThrow(OfficeStamperException.throwing("This paragraph is not in a table row.")); | |
| 36 |
1
1. repeatTableRow : removed call to pro/verron/officestamper/api/Table$Row::removeComment → TIMED_OUT |
row.removeComment(comment()); |
| 37 | ||
| 38 | var table = row.table(); | |
| 39 | var index = table.indexOf(row); | |
| 40 | for (Object item : items) { | |
| 41 | var copy = row.copy(); | |
| 42 | var contextKey = contextHolder.addBranch(item); | |
| 43 | copy.hooks() | |
| 44 |
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)); |
| 45 |
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); |
| 46 | } | |
| 47 |
1
1. repeatTableRow : removed call to pro/verron/officestamper/api/Table$Row::remove → KILLED |
row.remove(); |
| 48 | } | |
| 49 | } | |
Mutations | ||
| 30 |
1.1 |
|
| 36 |
1.1 |
|
| 44 |
1.1 2.2 |
|
| 45 |
1.1 2.2 |
|
| 47 |
1.1 |