MCPcopy Index your code
hub / github.com/asLody/VirtualApp / RefMethod

Method RefMethod

VirtualApp/lib/src/main/java/mirror/RefMethod.java:13–59  ·  view source on GitHub ↗
(Class<?> cls, Field field)

Source from the content-addressed store, hash-verified

11 private Method method;
12
13 public RefMethod(Class<?> cls, Field field) throws NoSuchMethodException {
14 if (field.isAnnotationPresent(MethodParams.class)) {
15 Class<?>[] types = field.getAnnotation(MethodParams.class).value();
16 for (int i = 0; i < types.length; i++) {
17 Class<?> clazz = types[i];
18 if (clazz.getClassLoader() == getClass().getClassLoader()) {
19 try {
20 Class.forName(clazz.getName());
21 Class<?> realClass = (Class<?>) clazz.getField("TYPE").get(null);
22 types[i] = realClass;
23 } catch (Throwable e) {
24 throw new RuntimeException(e);
25 }
26 }
27 }
28 this.method = cls.getDeclaredMethod(field.getName(), types);
29 this.method.setAccessible(true);
30 } else if (field.isAnnotationPresent(MethodReflectParams.class)) {
31 String[] typeNames = field.getAnnotation(MethodReflectParams.class).value();
32 Class<?>[] types = new Class<?>[typeNames.length];
33 for (int i = 0; i < typeNames.length; i++) {
34 Class<?> type = getProtoType(typeNames[i]);
35 if (type == null) {
36 try {
37 type = Class.forName(typeNames[i]);
38 } catch (ClassNotFoundException e) {
39 e.printStackTrace();
40 }
41 }
42 types[i] = type;
43 }
44 this.method = cls.getDeclaredMethod(field.getName(), types);
45 this.method.setAccessible(true);
46 }
47 else {
48 for (Method method : cls.getDeclaredMethods()) {
49 if (method.getName().equals(field.getName())) {
50 this.method = method;
51 this.method.setAccessible(true);
52 break;
53 }
54 }
55 }
56 if (this.method == null) {
57 throw new NoSuchMethodException(field.getName());
58 }
59 }
60
61 public T call(Object receiver, Object... args) {
62 try {

Callers

nothing calls this directly

Calls 7

getClassLoaderMethod · 0.80
forNameMethod · 0.80
getProtoTypeMethod · 0.80
printStackTraceMethod · 0.80
getNameMethod · 0.65
getMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected