@@ -38,9 +38,10 @@ public class PainlessMethod {
38
38
public final org .objectweb .asm .commons .Method method ;
39
39
public final int modifiers ;
40
40
public final MethodHandle handle ;
41
+ public final MethodType methodType ;
41
42
42
43
public PainlessMethod (String name , Class <?> target , Class <?> augmentation , Class <?> rtn , List <Class <?>> arguments ,
43
- org .objectweb .asm .commons .Method method , int modifiers , MethodHandle handle ) {
44
+ org .objectweb .asm .commons .Method method , int modifiers , MethodHandle handle , MethodType methodType ) {
44
45
this .name = name ;
45
46
this .augmentation = augmentation ;
46
47
this .target = target ;
@@ -49,54 +50,7 @@ public PainlessMethod(String name, Class<?> target, Class<?> augmentation, Class
49
50
this .method = method ;
50
51
this .modifiers = modifiers ;
51
52
this .handle = handle ;
52
- }
53
-
54
- /**
55
- * Returns MethodType for this method.
56
- * <p>
57
- * This works even for user-defined Methods (where the MethodHandle is null).
58
- */
59
- public MethodType getMethodType () {
60
- // we have a methodhandle already (e.g. whitelisted class)
61
- // just return its type
62
- if (handle != null ) {
63
- return handle .type ();
64
- }
65
- // otherwise compute it
66
- final Class <?> params [];
67
- final Class <?> returnValue ;
68
- if (augmentation != null ) {
69
- // static method disguised as virtual/interface method
70
- params = new Class <?>[1 + arguments .size ()];
71
- params [0 ] = augmentation ;
72
- for (int i = 0 ; i < arguments .size (); i ++) {
73
- params [i + 1 ] = PainlessLookupUtility .typeToJavaType (arguments .get (i ));
74
- }
75
- returnValue = PainlessLookupUtility .typeToJavaType (rtn );
76
- } else if (Modifier .isStatic (modifiers )) {
77
- // static method: straightforward copy
78
- params = new Class <?>[arguments .size ()];
79
- for (int i = 0 ; i < arguments .size (); i ++) {
80
- params [i ] = PainlessLookupUtility .typeToJavaType (arguments .get (i ));
81
- }
82
- returnValue = PainlessLookupUtility .typeToJavaType (rtn );
83
- } else if ("<init>" .equals (name )) {
84
- // constructor: returns the owner class
85
- params = new Class <?>[arguments .size ()];
86
- for (int i = 0 ; i < arguments .size (); i ++) {
87
- params [i ] = PainlessLookupUtility .typeToJavaType (arguments .get (i ));
88
- }
89
- returnValue = target ;
90
- } else {
91
- // virtual/interface method: add receiver class
92
- params = new Class <?>[1 + arguments .size ()];
93
- params [0 ] = target ;
94
- for (int i = 0 ; i < arguments .size (); i ++) {
95
- params [i + 1 ] = PainlessLookupUtility .typeToJavaType (arguments .get (i ));
96
- }
97
- returnValue = PainlessLookupUtility .typeToJavaType (rtn );
98
- }
99
- return MethodType .methodType (returnValue , params );
53
+ this .methodType = methodType ;
100
54
}
101
55
102
56
public void write (MethodWriter writer ) {
@@ -118,7 +72,7 @@ public void write(MethodWriter writer) {
118
72
// method since java 8 did not check, but java 9 and 10 do
119
73
if (Modifier .isInterface (clazz .getModifiers ())) {
120
74
writer .visitMethodInsn (Opcodes .INVOKESTATIC ,
121
- type .getInternalName (), name , getMethodType () .toMethodDescriptorString (), true );
75
+ type .getInternalName (), name , methodType .toMethodDescriptorString (), true );
122
76
} else {
123
77
writer .invokeStatic (type , method );
124
78
}
0 commit comments