Placeholders.java

1
package pro.verron.officestamper.core;
2
3
import pro.verron.officestamper.api.OfficeStamperException;
4
import pro.verron.officestamper.api.Paragraph;
5
import pro.verron.officestamper.api.Placeholder;
6
7
import java.util.List;
8
import java.util.regex.Pattern;
9
10
/// The Expressions class provides utility methods for finding variables and processors in a given text.
11
/// It contains multiple constant variables for different types of expressions, such as VAR_MATCHER for variable
12
/// expressions and PROC_MATCHER for processor expressions.
13
/// The findVariables() method uses VAR_FINDER to find variable expressions in a given text and returns a list of found
14
/// expressions.
15
/// The findProcessors() method uses PROC_FINDER to find processor expressions in a given text and returns a list of
16
/// found expressions.
17
/// The raw() method creates a new Expression object using the RAW_MATCHER and a specified text.
18
public class Placeholders {
19
    /// A regular expression pattern matching processor expression.
20
    /// The pattern search for expressions starting with '#{' and ending with '}'.
21
    private static final Pattern PROC_PATTERN = Pattern.compile("#\\{(.*?)}", Pattern.DOTALL);
22
    /// A Matcher matching processor expressions.
23
    /// The matcher checks for expressions starting with '#{' and ending with '}'.
24
    private static final Matcher PROC_MATCHER = new Matcher("#{", "}");
25
    /// An ExpressionFinder to find processor expressions.
26
    /// It is initialized with a specified pattern and matcher.
27
    private static final PlaceholderFinder PROC_FINDER = new PlaceholderFinder(PROC_PATTERN, PROC_MATCHER);
28
29
    /// A regular expression pattern matching processor expressions.
30
    /// The pattern search for expressions starting with '${' and ending with '}'.
31
    private static final Pattern VAR_PATTERN = Pattern.compile("\\$\\{(.*?)}", Pattern.DOTALL);
32
    /// A Matcher matching processor expressions.
33
    /// The matcher checks for expressions starting with '${' and ending with '}'.
34
    private static final Matcher VAR_MATCHER = new Matcher("${", "}");
35
    /// An ExpressionFinder to find variable expressions.
36
    /// It is initialized with a specified pattern and matcher.
37
    private static final PlaceholderFinder VAR_FINDER = new PlaceholderFinder(VAR_PATTERN, VAR_MATCHER);
38
    /// A Matcher matching raw expressions.
39
    /// It is typically used to wrap raw expressions that do not have a
40
    /// specific prefix or suffix.
41
    private static final Matcher RAW_MATCHER = new Matcher("", "");
42
43
    private Placeholders() {
44
        throw new OfficeStamperException("Utility classes should not be instantiated!");
45
    }
46
47
    /// Finds variable expressions in a given paragraph.
48
    ///
49
    /// @param paragraph the paragraph in which to search for variable expressions
50
    ///
51
    /// @return a list of found variable expressions as [Placeholder] objects
52
    public static List<Placeholder> findVariables(Paragraph paragraph) {
53 1 1. findVariables : replaced return value with Collections.emptyList for pro/verron/officestamper/core/Placeholders::findVariables → KILLED
        return findVariables(paragraph.asString());
54
    }
55
56
    /// Finds variable expressions in a given text.
57
    ///
58
    /// @param text the text to search for variable expressions
59
    ///
60
    /// @return a list of found variable expressions as [StandardPlaceholder] objects
61
    public static List<Placeholder> findVariables(String text) {
62 1 1. findVariables : replaced return value with Collections.emptyList for pro/verron/officestamper/core/Placeholders::findVariables → KILLED
        return VAR_FINDER.find(text);
63
    }
64
65
    /// Finds processors expressions in a given text.
66
    ///
67
    /// @param text the text to search for processor expressions
68
    ///
69
    /// @return a list of found processor expressions as [StandardPlaceholder]
70
    /// objects
71
    public static List<Placeholder> findProcessors(String text) {
72 1 1. findProcessors : replaced return value with Collections.emptyList for pro/verron/officestamper/core/Placeholders::findProcessors → KILLED
        return PROC_FINDER.find(text);
73
    }
74
75
    /// Creates a new raw placeholder with the given text.
76
    ///
77
    /// @param text the text to be used as the content of the placeholder
78
    ///
79
    /// @return a new raw placeholder
80
    public static Placeholder raw(String text) {
81 1 1. raw : replaced return value with null for pro/verron/officestamper/core/Placeholders::raw → KILLED
        return new StandardPlaceholder(RAW_MATCHER, text);
82
    }
83
}

Mutations

53

1.1
Location : findVariables
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#22]
replaced return value with Collections.emptyList for pro/verron/officestamper/core/Placeholders::findVariables → KILLED

62

1.1
Location : findVariables
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#22]
replaced return value with Collections.emptyList for pro/verron/officestamper/core/Placeholders::findVariables → KILLED

72

1.1
Location : findProcessors
Killed by : pro.verron.officestamper.test.ProcessorDisplayIfTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ProcessorDisplayIfTest]/[test-template:conditionalDisplayOfParagraphsTest_unresolvedInlineProcessorExpressionsAreRemoved(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
replaced return value with Collections.emptyList for pro/verron/officestamper/core/Placeholders::findProcessors → KILLED

81

1.1
Location : raw
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#13]
replaced return value with null for pro/verron/officestamper/core/Placeholders::raw → KILLED

Active mutators

Tests examined


Report generated by PIT 1.21.0