@@ -38,9 +38,10 @@ public class PainlessMethod {
3838 public final org .objectweb .asm .commons .Method method ;
3939 public final int modifiers ;
4040 public final MethodHandle handle ;
41+ public final MethodType methodType ;
4142
4243 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 ) {
4445 this .name = name ;
4546 this .augmentation = augmentation ;
4647 this .target = target ;
@@ -49,54 +50,7 @@ public PainlessMethod(String name, Class<?> target, Class<?> augmentation, Class
4950 this .method = method ;
5051 this .modifiers = modifiers ;
5152 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 ;
10054 }
10155
10256 public void write (MethodWriter writer ) {
@@ -118,7 +72,7 @@ public void write(MethodWriter writer) {
11872 // method since java 8 did not check, but java 9 and 10 do
11973 if (Modifier .isInterface (clazz .getModifiers ())) {
12074 writer .visitMethodInsn (Opcodes .INVOKESTATIC ,
121- type .getInternalName (), name , getMethodType () .toMethodDescriptorString (), true );
75+ type .getInternalName (), name , methodType .toMethodDescriptorString (), true );
12276 } else {
12377 writer .invokeStatic (type , method );
12478 }
0 commit comments