ProcessorContext.java

1
package pro.verron.officestamper.api;
2
3
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
4
import pro.verron.officestamper.utils.iterator.ResetableIterator;
5
import pro.verron.officestamper.utils.wml.DocxIterator;
6
7
import java.util.Optional;
8
9
/// Represents a context within a document processing operation.
10
///
11
/// This class encapsulates key elements involved in the processing of a specific part of a
12
/// [WordprocessingMLPackage]-based document, such as a part of the document, a specific paragraph, an associated
13
/// comment, and an expression being evaluated or processed.
14
///
15
/// The [ProcessorContext] provides structured access to these elements, enabling seamless document traversal,
16
/// manipulation, and analysis during processing workflows.
17
public final class ProcessorContext {
18
    private final DocxPart part;
19
    private final Paragraph paragraph;
20
    private final Comment comment;
21
    private final String expression;
22
    private final ContextTree contextTree;
23
24
    /// Constructs a ProcessorContext.
25
    ///
26
    /// @param part The [DocxPart] representing a specific part of the document being processed.
27
    /// @param paragraph The [Paragraph] associated with the processing context.
28
    /// @param comment The [Comment] that is relevant to the current processing context.
29
    /// @param expression A [String] containing the expression or directive being evaluated.
30
    /// @param contextTree The [ContextTree] managing the hierarchical scopes for this context.
31
    public ProcessorContext(
32
            DocxPart part,
33
            Paragraph paragraph,
34
            Comment comment,
35
            String expression,
36
            ContextTree contextTree
37
    ) {
38
        this.part = part;
39
        this.paragraph = paragraph;
40
        this.comment = comment;
41
        this.expression = expression;
42
        this.contextTree = contextTree;
43
    }
44
45
    /// Returns an iterator over the content associated with the current comment's range.
46
    ///
47
    /// @return a [ResetableIterator] of [Object] representing the content within the comment's scope.
48
    public ResetableIterator<Object> contentIterator() {
49
        var parent = comment.getParent();
50
        var crs = comment.getCommentRangeStart();
51
        var cre = comment.getCommentRangeEnd();
52 1 1. contentIterator : replaced return value with null for pro/verron/officestamper/api/ProcessorContext::contentIterator → KILLED
        return new DocxIterator(parent).slice(crs, cre);
53
    }
54
55
    /// Returns the comment associated with the current processing context.
56
    ///
57
    /// @return the [Comment] object.
58 1 1. comment : replaced return value with null for pro/verron/officestamper/api/ProcessorContext::comment → KILLED
    public Comment comment() {return comment;}
59
60
    /// Returns the table row containing the current paragraph, if any.
61
    ///
62
    /// @return an [Optional] containing the [Table.Row], or empty if the paragraph is not in a table row.
63
    public Optional<Table.Row> tableRow() {
64 1 1. tableRow : replaced return value with Optional.empty for pro/verron/officestamper/api/ProcessorContext::tableRow → KILLED
        return paragraph.parentTableRow();
65
    }
66
67
    /// Returns the table containing the current paragraph, if any.
68
    ///
69
    /// @return an [Optional] containing the [Table], or empty if the paragraph is not in a table.
70
    public Optional<Table> table() {
71 1 1. table : replaced return value with Optional.empty for pro/verron/officestamper/api/ProcessorContext::table → KILLED
        return paragraph.parentTable();
72
    }
73
74
    /// Returns the document part currently being processed.
75
    ///
76
    /// @return the [DocxPart] object.
77 1 1. part : replaced return value with null for pro/verron/officestamper/api/ProcessorContext::part → TIMED_OUT
    public DocxPart part() {return part;}
78
79
    /// Returns the paragraph currently being processed.
80
    ///
81
    /// @return the [Paragraph] object.
82 1 1. paragraph : replaced return value with null for pro/verron/officestamper/api/ProcessorContext::paragraph → KILLED
    public Paragraph paragraph() {return paragraph;}
83
84
    /// Returns the expression or directive currently being evaluated.
85
    ///
86
    /// @return the expression as a [String].
87 1 1. expression : replaced return value with "" for pro/verron/officestamper/api/ProcessorContext::expression → KILLED
    public String expression() {return expression;}
88
89
    /// Returns the context tree managing the hierarchical scopes for this context.
90
    ///
91
    /// @return the [ContextTree] object.
92 1 1. contextHolder : replaced return value with null for pro/verron/officestamper/api/ProcessorContext::contextHolder → KILLED
    public ContextTree contextHolder() {return contextTree;}
93
}

Mutations

52

1.1
Location : contentIterator
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfEndnotes(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#1]
replaced return value with null for pro/verron/officestamper/api/ProcessorContext::contentIterator → KILLED

58

1.1
Location : comment
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#1]
replaced return value with null for pro/verron/officestamper/api/ProcessorContext::comment → KILLED

64

1.1
Location : tableRow
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfTableRowsTest(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with Optional.empty for pro/verron/officestamper/api/ProcessorContext::tableRow → KILLED

71

1.1
Location : table
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfTableBug32Test(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with Optional.empty for pro/verron/officestamper/api/ProcessorContext::table → KILLED

77

1.1
Location : part
Killed by : none
replaced return value with null for pro/verron/officestamper/api/ProcessorContext::part → TIMED_OUT

82

1.1
Location : paragraph
Killed by : pro.verron.officestamper.test.CustomProcessorTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.CustomProcessorTests]/[test-template:should_allow_custom_processors_injection(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#1]
replaced return value with null for pro/verron/officestamper/api/ProcessorContext::paragraph → KILLED

87

1.1
Location : expression
Killed by : pro.verron.officestamper.test.SpelInjectionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.SpelInjectionTest]/[test-template:spelInjectionTest(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with "" for pro/verron/officestamper/api/ProcessorContext::expression → KILLED

92

1.1
Location : contextHolder
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#3]
replaced return value with null for pro/verron/officestamper/api/ProcessorContext::contextHolder → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.0