DocxHook.java

1
package pro.verron.officestamper.core;
2
3
import org.docx4j.wml.CTSmartTagRun;
4
import org.docx4j.wml.CommentRangeStart;
5
import org.docx4j.wml.ContentAccessor;
6
import pro.verron.officestamper.api.DocxPart;
7
import pro.verron.officestamper.api.Hook;
8
import pro.verron.officestamper.utils.iterator.ResetableIterator;
9
import pro.verron.officestamper.utils.wml.DocxIterator;
10
11
import static pro.verron.officestamper.utils.wml.WmlUtils.isTagElement;
12
13
/// Interface for hooks that process specific parts of a DOCX document.
14
public interface DocxHook
15
        extends Hook {
16
17
    /// Creates an iterator over the hooks in the given content accessor.
18
    ///
19
    /// @param contentAccessor the content accessor to search for hooks.
20
    /// @param part the document part.
21
    /// @return an iterator over the found hooks.
22
    static ResetableIterator<DocxHook> ofHooks(ContentAccessor contentAccessor, DocxPart part) {
23 1 1. ofHooks : replaced return value with null for pro/verron/officestamper/core/DocxHook::ofHooks → KILLED
        return new DocxIterator(contentAccessor).filter(DocxHook::isPotentialHook)
24 1 1. lambda$ofHooks$0 : replaced return value with null for pro/verron/officestamper/core/DocxHook::lambda$ofHooks$0 → KILLED
                                                .map(o -> asHook(part, o));
25
    }
26
27
    /// Checks if the given object is a potential hook.
28
    ///
29
    /// @param o the object to check.
30
    /// @return `true` if it is a potential hook.
31
    static boolean isPotentialHook(Object o) {
32 3 1. isPotentialHook : replaced boolean return with true for pro/verron/officestamper/core/DocxHook::isPotentialHook → KILLED
2. isPotentialHook : negated conditional → KILLED
3. isPotentialHook : negated conditional → KILLED
        return o instanceof CTSmartTagRun tag && isTagElement(tag, "officestamper");
33
    }
34
35
    /// Converts an object to a hook.
36
    ///
37
    /// @param part the document part.
38
    /// @param o the object to convert.
39
    /// @return the hook.
40
    static DocxHook asHook(DocxPart part, Object o) {
41 1 1. asHook : replaced return value with null for pro/verron/officestamper/core/DocxHook::asHook → KILLED
        return switch (o) {
42 1 1. asHook : negated conditional → KILLED
            case CTSmartTagRun tag when isType(tag, "processor", "type") -> newCommentHook(part, tag);
43
            case CTSmartTagRun tag -> new TagHook(part, new Tag(part, tag));
44
            default -> throw new IllegalArgumentException("Unexpected value: " + o);
45
        };
46
    }
47
48
    /// Checks if the given tag is of the specified type.
49
    ///
50
    /// @param tag the tag to check.
51
    /// @param type the expected type value.
52
    /// @param typeKey the attribute name for the type.
53
    /// @return `true` if the tag matches the type.
54
    static boolean isType(CTSmartTagRun tag, String type, String typeKey) {
55 2 1. isType : replaced boolean return with true for pro/verron/officestamper/core/DocxHook::isType → KILLED
2. isType : replaced boolean return with false for pro/verron/officestamper/core/DocxHook::isType → KILLED
        return tag.getSmartTagPr()
56
                  .getAttr()
57
                  .stream()
58 3 1. lambda$isType$0 : negated conditional → KILLED
2. lambda$isType$0 : negated conditional → KILLED
3. lambda$isType$0 : replaced boolean return with true for pro/verron/officestamper/core/DocxHook::lambda$isType$0 → KILLED
                  .anyMatch(attr -> typeKey.equals(attr.getName()) && type.equals(attr.getVal()));
59
    }
60
61
    /// Creates a new comment hook.
62
    ///
63
    /// @param part the document part.
64
    /// @param tag the tag.
65
    /// @return the comment hook.
66
    static DocxHook newCommentHook(DocxPart part, CTSmartTagRun tag) {
67
        var tagContent = tag.getContent();
68
        var commentRangeStart = (CommentRangeStart) tagContent.getFirst();
69
        var myTag = new Tag(part, tag);
70
        var comment = CommentUtil.comment(part, commentRangeStart, part.document(), part::content);
71 1 1. newCommentHook : replaced return value with null for pro/verron/officestamper/core/DocxHook::newCommentHook → KILLED
        return new CommentHook(part, myTag, comment);
72
    }
73
74
    /// Executes the hook's logic within the context of a document processing flow.
75
    ///
76
    /// @param engineFactory a factory responsible for creating instances of the [Engine] class, which may be
77
    ///         used during the execution of the hook's logic
78
    /// @param contextTree the root of the context tree, representing the hierarchical structure of context
79
    ///         branches available during document processing
80
    /// @param officeStamperContextFactory a factory for creating evaluation contexts, which are used to
81
    ///         evaluate expressions and handle dynamic behavior during the document processing flow
82
    ///
83
    /// @return `true` if the execution of the hook was successful, otherwise `false`
84
    boolean run(
85
            EngineFactory engineFactory,
86
            ContextRoot contextTree,
87
            OfficeStamperEvaluationContextFactory officeStamperContextFactory
88
    );
89
}

Mutations

23

1.1
Location : ofHooks
Killed by : pro.verron.officestamper.test.DateFormatTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DateFormatTests]/[test-template:features(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/core/DocxHook::ofHooks → KILLED

24

1.1
Location : lambda$ofHooks$0
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/core/DocxHook::lambda$ofHooks$0 → KILLED

32

1.1
Location : isPotentialHook
Killed by : pro.verron.officestamper.test.DateFormatTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DateFormatTests]/[test-template:features(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced boolean return with true for pro/verron/officestamper/core/DocxHook::isPotentialHook → KILLED

2.2
Location : isPotentialHook
Killed by : pro.verron.officestamper.test.DateFormatTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DateFormatTests]/[test-template:features(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

3.3
Location : isPotentialHook
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

41

1.1
Location : asHook
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/core/DocxHook::asHook → KILLED

42

1.1
Location : asHook
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

55

1.1
Location : isType
Killed by : pro.verron.officestamper.test.CustomFunctionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.CustomFunctionTests]/[test-template:trifunctions(pro.verron.officestamper.test.utils.ContextFactory, java.lang.String, java.lang.String)]/[test-template-invocation:#12]
replaced boolean return with true for pro/verron/officestamper/core/DocxHook::isType → KILLED

2.2
Location : isType
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced boolean return with false for pro/verron/officestamper/core/DocxHook::isType → KILLED

58

1.1
Location : lambda$isType$0
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

2.2
Location : lambda$isType$0
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
negated conditional → KILLED

3.3
Location : lambda$isType$0
Killed by : pro.verron.officestamper.test.CustomFunctionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.CustomFunctionTests]/[test-template:trifunctions(pro.verron.officestamper.test.utils.ContextFactory, java.lang.String, java.lang.String)]/[test-template-invocation:#12]
replaced boolean return with true for pro/verron/officestamper/core/DocxHook::lambda$isType$0 → KILLED

71

1.1
Location : newCommentHook
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/core/DocxHook::newCommentHook → KILLED

Active mutators

Tests examined


Report generated by PIT 1.25.5 support