1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.infra.expr.espresso;
19
20 import lombok.SneakyThrows;
21
22 import java.util.stream.Stream;
23
24
25
26
27
28 public class ReflectValue {
29
30 private static final String VALUE_CLASS_NAME = "org.graalvm.polyglot.Value";
31
32 private final Object valueInstance;
33
34 public ReflectValue(final Object valueInstance) {
35 this.valueInstance = valueInstance;
36 }
37
38
39
40
41
42
43 @SneakyThrows
44 public ReflectValue getMember(final String identifier) {
45 Object resultValueInstance = Class.forName(VALUE_CLASS_NAME)
46 .getMethod("getMember", String.class)
47 .invoke(valueInstance, identifier);
48 return new ReflectValue(resultValueInstance);
49 }
50
51
52
53
54
55
56 @SneakyThrows
57 public ReflectValue newInstance(final Object... arguments) {
58 Object resultValueInstance = Class.forName(VALUE_CLASS_NAME)
59 .getMethod("newInstance", Object[].class)
60 .invoke(valueInstance, new Object[]{Stream.of(arguments).toArray()});
61 return new ReflectValue(resultValueInstance);
62 }
63
64
65
66
67
68
69
70 @SneakyThrows
71 public ReflectValue invokeMember(final String identifier, final Object... arguments) {
72 Object resultValueInstance = Class.forName(VALUE_CLASS_NAME)
73 .getMethod("invokeMember", String.class, Object[].class)
74 .invoke(valueInstance, identifier, arguments);
75 return new ReflectValue(resultValueInstance);
76 }
77
78
79
80
81
82 @SneakyThrows
83 public boolean isString() {
84 return (boolean) Class.forName(VALUE_CLASS_NAME)
85 .getMethod("isString")
86 .invoke(valueInstance);
87 }
88
89
90
91
92
93
94
95 @SneakyThrows
96 @SuppressWarnings("unchecked")
97 public <T> T as(final Class<T> targetType) {
98 return (T) Class.forName(VALUE_CLASS_NAME)
99 .getMethod("as", Class.class)
100 .invoke(valueInstance, targetType);
101 }
102 }