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