1 | package pro.verron.officestamper.core; | |
2 | ||
3 | import org.springframework.expression.AccessException; | |
4 | import org.springframework.expression.EvaluationContext; | |
5 | import org.springframework.expression.MethodExecutor; | |
6 | import org.springframework.expression.TypedValue; | |
7 | import org.springframework.lang.NonNull; | |
8 | ||
9 | import java.lang.reflect.InvocationTargetException; | |
10 | import java.lang.reflect.Method; | |
11 | import java.util.Arrays; | |
12 | ||
13 | /** | |
14 | * A record encapsulating an object and a method, and providing functionality to execute the method on the given | |
15 | * object using reflection. | |
16 | * This record implements the {@link MethodExecutor} interface and serves as a mechanism to invoke methods dynamically. | |
17 | */ | |
18 | public record ReflectionExecutor(Object object, Method method) | |
19 | implements MethodExecutor { | |
20 | ||
21 | @Override | |
22 | @NonNull | |
23 | public TypedValue execute(@NonNull EvaluationContext context, @NonNull Object target, @NonNull Object... arguments) | |
24 | throws AccessException { | |
25 | try { | |
26 | var value = method.invoke(object, arguments); | |
27 |
1
1. execute : replaced return value with null for pro/verron/officestamper/core/ReflectionExecutor::execute → KILLED |
return new TypedValue(value); |
28 | } catch (InvocationTargetException | IllegalAccessException e) { | |
29 | var message = "Failed to invoke method %s with arguments [%s] from object %s".formatted(method, | |
30 | Arrays.toString(arguments), | |
31 | object); | |
32 | throw new AccessException(message, e); | |
33 | } | |
34 | } | |
35 | } | |
Mutations | ||
27 |
1.1 |