Placeholders.java

1
package pro.verron.officestamper.experimental;
2
3
import pro.verron.officestamper.api.OfficeStamperException;
4
import pro.verron.officestamper.api.Paragraph;
5
import pro.verron.officestamper.core.Matcher;
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
    /// @return a list of found variable expressions as [Placeholder] objects
51
    public static List<Placeholder> findVariables(Paragraph paragraph) {
52 1 1. findVariables : replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/Placeholders::findVariables → NO_COVERAGE
        return findVariables(paragraph.asString());
53
    }
54
55
    /// Finds variable expressions in a given text.
56
    /// @param text the text to search for variable expressions
57
    /// @return a list of found variable expressions as [StandardPlaceholder] objects
58
    public static List<Placeholder> findVariables(String text) {
59 1 1. findVariables : replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/Placeholders::findVariables → KILLED
        return VAR_FINDER.find(text);
60
    }
61
62
    /// Finds processors expressions in a given text.
63
    /// @param text the text to search for processor expressions
64
    /// @return a list of found processor expressions as [StandardPlaceholder] objects
65
    public static List<Placeholder> findProcessors(String text) {
66 1 1. findProcessors : replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/Placeholders::findProcessors → NO_COVERAGE
        return PROC_FINDER.find(text);
67
    }
68
69
    /// Creates a new raw placeholder with the given text.
70
    ///
71
    /// @param text the text to be used as the content of the placeholder
72
    /// @return a new raw placeholder
73
    public static Placeholder raw(String text) {
74 1 1. raw : replaced return value with null for pro/verron/officestamper/experimental/Placeholders::raw → NO_COVERAGE
        return new StandardPlaceholder(RAW_MATCHER, text);
75
    }
76
}

Mutations

52

1.1
Location : findVariables
Killed by : none
replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/Placeholders::findVariables → NO_COVERAGE

59

1.1
Location : findVariables
Killed by : pro.verron.officestamper.test.PptxImageTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.PptxImageTest]/[method:testImageStamping()]
replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/Placeholders::findVariables → KILLED

66

1.1
Location : findProcessors
Killed by : none
replaced return value with Collections.emptyList for pro/verron/officestamper/experimental/Placeholders::findProcessors → NO_COVERAGE

74

1.1
Location : raw
Killed by : none
replaced return value with null for pro/verron/officestamper/experimental/Placeholders::raw → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.25.5 support