1 | package pro.verron.officestamper.core; | |
2 | ||
3 | import org.springframework.expression.ExpressionParser; | |
4 | import org.springframework.expression.spel.support.StandardEvaluationContext; | |
5 | import org.springframework.lang.Nullable; | |
6 | import pro.verron.officestamper.api.Placeholder; | |
7 | ||
8 | /** | |
9 | * Resolves expressions against a given context object. Expressions can be either SpEL expressions or simple property | |
10 | * expressions. | |
11 | * | |
12 | * @author Joseph Verron | |
13 | * @author Tom Hombergs | |
14 | * @version ${version} | |
15 | * @since 1.0.0 | |
16 | */ | |
17 | public class ExpressionResolver { | |
18 | ||
19 | private final ExpressionParser parser; | |
20 | private final StandardEvaluationContext evaluationContext; | |
21 | ||
22 | /** | |
23 | * Creates a new ExpressionResolver with the given SpEL parser configuration. | |
24 | * | |
25 | * @param standardEvaluationContext a {@link StandardEvaluationContext} object | |
26 | */ | |
27 | public ExpressionResolver( | |
28 | StandardEvaluationContext standardEvaluationContext, | |
29 | ExpressionParser expressionParser | |
30 | ) { | |
31 | this.parser = expressionParser; | |
32 | this.evaluationContext = standardEvaluationContext; | |
33 | } | |
34 | ||
35 | ||
36 | /** | |
37 | * Resolves the content of a placeholder by evaluating the expression against the evaluation context. | |
38 | * | |
39 | * @param placeholder the placeholder to resolve | |
40 | * | |
41 | * @return the resolved value of the placeholder | |
42 | */ | |
43 | @Nullable public Object resolve(Placeholder placeholder) { | |
44 | var expressionString = placeholder.content(); | |
45 | var expression = parser.parseExpression(expressionString); | |
46 |
1
1. resolve : replaced return value with null for pro/verron/officestamper/core/ExpressionResolver::resolve → KILLED |
return expression.getValue(evaluationContext); |
47 | } | |
48 | ||
49 | /** | |
50 | * Sets the context object against which expressions will be resolved. | |
51 | * | |
52 | * @param contextRoot the context object to set as the root. | |
53 | */ | |
54 | public void setContext(Object contextRoot) { | |
55 |
1
1. setContext : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setRootObject → KILLED |
evaluationContext.setRootObject(contextRoot); |
56 | } | |
57 | } | |
Mutations | ||
46 |
1.1 |
|
55 |
1.1 |