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