ReplaceWithProcessor.java

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
/// @since 1.0.7
18
public class ReplaceWithProcessor
19
        extends CommentProcessor
20
        implements CommentProcessorFactory.IReplaceWithProcessor {
21
22
    /// Constructs a new [ReplaceWithProcessor] instance.
23
    ///
24
    /// @param processorContext the context in which this processor operates, providing access to document
25
    ///         manipulation and expression evaluation utilities.
26
    public ReplaceWithProcessor(ProcessorContext processorContext) {
27
        super(processorContext);
28
    }
29
30
    /// Replaces the content between the start and end of the comment with the given expression.
31
    ///
32
    /// @param expression The expression to replace the content with. Must not be null.
33
    /// @throws OfficeStamperException if the expression is null, or if the comment range start or end is null.
34
    @Override
35
    public void replaceWith(@Nullable String expression) {
36 1 1. replaceWith : negated conditional → KILLED
        if (expression == null) throw new OfficeStamperException("Cannot replace with null expression");
37
        var from = comment().getStartTagRun();
38
        var to = comment().getCommentRangeEnd();
39 1 1. replaceWith : removed call to pro/verron/officestamper/api/Paragraph::replace → KILLED
        paragraph().replace(from, to, new Insert(newRun(expression)));
40
    }
41
}

Mutations

36

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

39

1.1
Location : replaceWith
Killed by : pro.verron.officestamper.test.ProcessorReplaceWithTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorReplaceWithTest]/[method:notWorking1()]
removed call to pro/verron/officestamper/api/Paragraph::replace → KILLED

Active mutators

Tests examined


Report generated by PIT 1.25.5 support