| 1 | package pro.verron.officestamper.preset.processors.replacewith; | |
| 2 | ||
| 3 | import org.jspecify.annotations.Nullable; | |
| 4 | import pro.verron.officestamper.api.CommentProcessor; | |
| 5 | import pro.verron.officestamper.api.Insert; | |
| 6 | import pro.verron.officestamper.api.OfficeStamperException; | |
| 7 | import pro.verron.officestamper.api.ProcessorContext; | |
| 8 | import pro.verron.officestamper.preset.CommentProcessorFactory; | |
| 9 | ||
| 10 | import static pro.verron.officestamper.utils.wml.WmlFactory.newRun; | |
| 11 | ||
| 12 | /// Processor that replaces the current run with the provided expression. This is useful for replacing an expression in | |
| 13 | /// a comment with the result of the expression. | |
| 14 | /// | |
| 15 | /// @author Joseph Verron | |
| 16 | /// @author Tom Hombergs | |
| 17 | /// @version ${version} | |
| 18 | /// @since 1.0.7 | |
| 19 | public class ReplaceWithProcessor | |
| 20 | extends CommentProcessor | |
| 21 | implements CommentProcessorFactory.IReplaceWithProcessor { | |
| 22 | ||
| 23 | /// Constructs a new [ReplaceWithProcessor] instance. | |
| 24 | /// | |
| 25 | /// @param processorContext the context in which this processor operates, providing access to document | |
| 26 | /// manipulation and expression evaluation utilities. | |
| 27 | public ReplaceWithProcessor(ProcessorContext processorContext) { | |
| 28 | super(processorContext); | |
| 29 | } | |
| 30 | ||
| 31 | /// Replaces the content between the start and end of the comment with the given expression. | |
| 32 | /// | |
| 33 | /// @param expression The expression to replace the content with. Must not be null. | |
| 34 | /// | |
| 35 | /// @throws OfficeStamperException if the expression is null, or if the comment range start or end is null. | |
| 36 | @Override | |
| 37 | public void replaceWith(@Nullable String expression) { | |
| 38 |
1
1. replaceWith : negated conditional → KILLED |
if (expression == null) throw new OfficeStamperException("Cannot replace with null expression"); |
| 39 | var from = comment().getStartTagRun(); | |
| 40 | var to = comment().getCommentRangeEnd(); | |
| 41 |
1
1. replaceWith : removed call to pro/verron/officestamper/api/Paragraph::replace → KILLED |
paragraph().replace(from, to, new Insert(newRun(expression))); |
| 42 | } | |
| 43 | } | |
Mutations | ||
| 38 |
1.1 |
|
| 41 |
1.1 |