|
1 | | -package org.nutz.aop.asm; |
2 | | - |
3 | | -import java.lang.reflect.Method; |
4 | | - |
5 | | -import org.nutz.repo.org.objectweb.asm.Label; |
6 | | -import org.nutz.repo.org.objectweb.asm.MethodVisitor; |
7 | | -import org.nutz.repo.org.objectweb.asm.Type; |
8 | | - |
9 | | -/** |
10 | | - * |
11 | | - * @author wendal(wendal1985@gmail.com) |
12 | | - * |
13 | | - */ |
14 | | -class AopInvokeAdpter extends AopMethodAdapter { |
15 | | - |
16 | | - Method[] methodArray; |
17 | | - |
18 | | - AopInvokeAdpter( Method[] methodArray, |
19 | | - MethodVisitor mv, |
20 | | - int access, |
21 | | - String methodName, |
22 | | - String desc, |
23 | | - int methodIndex, |
24 | | - String myName, |
25 | | - String enhancedSuperName) { |
26 | | - super(mv, access, methodName, desc, methodIndex, myName, enhancedSuperName); |
27 | | - this.methodArray = methodArray; |
28 | | - } |
29 | | - |
30 | | - void visitCode() { |
31 | | - mv.visitCode(); |
32 | | - |
33 | | - for (int i = 0; i < methodArray.length; i++) { |
34 | | - Method method = methodArray[i]; |
35 | | - mv.visitVarInsn(ILOAD, 1); |
36 | | - visitX(i); |
37 | | - Label l0 = new Label(); |
38 | | - mv.visitJumpInsn(IF_ICMPNE, l0); |
39 | | - mv.visitVarInsn(ALOAD, 0); |
40 | | - Type[] args = Type.getArgumentTypes(method); |
41 | | - for (int j = 0; j < args.length; j++) { |
42 | | - mv.visitVarInsn(ALOAD, 2); |
43 | | - visitX(j); |
44 | | - mv.visitInsn(AALOAD); |
45 | | - returnType = args[j]; |
46 | | - AsmHelper.checkCast(returnType,mv); |
47 | | - } |
48 | | - mv.visitMethodInsn( INVOKESPECIAL, |
49 | | - enhancedSuperName, |
50 | | - method.getName(), |
51 | | - Type.getMethodDescriptor(method)); |
52 | | - { |
53 | | - returnType = Type.getReturnType(method); |
54 | | - if (returnType.equals(Type.VOID_TYPE)) |
55 | | - mv.visitInsn(ACONST_NULL); |
56 | | - else if (returnType.getOpcode(IRETURN) != ARETURN) |
57 | | - AsmHelper.packagePrivateData(returnType,mv); |
58 | | - mv.visitInsn(ARETURN); |
59 | | - } |
60 | | - mv.visitLabel(l0); |
61 | | - } |
62 | | - |
63 | | - mv.visitInsn(ACONST_NULL); |
64 | | - mv.visitInsn(ARETURN); |
65 | | - mv.visitMaxs(4, 3); |
66 | | - mv.visitEnd(); |
67 | | - } |
68 | | - |
69 | | -} |
| 1 | +package org.nutz.aop.asm; |
| 2 | + |
| 3 | +import java.lang.reflect.Method; |
| 4 | + |
| 5 | +import org.nutz.repo.org.objectweb.asm.Label; |
| 6 | +import org.nutz.repo.org.objectweb.asm.MethodVisitor; |
| 7 | +import org.nutz.repo.org.objectweb.asm.Type; |
| 8 | + |
| 9 | +/** |
| 10 | + * |
| 11 | + * @author wendal(wendal1985@gmail.com) |
| 12 | + * |
| 13 | + */ |
| 14 | +class AopInvokeAdpter extends AopMethodAdapter { |
| 15 | + |
| 16 | + Method[] methodArray; |
| 17 | + |
| 18 | + AopInvokeAdpter( Method[] methodArray, |
| 19 | + MethodVisitor mv, |
| 20 | + int access, |
| 21 | + String methodName, |
| 22 | + String desc, |
| 23 | + int methodIndex, |
| 24 | + String myName, |
| 25 | + String enhancedSuperName) { |
| 26 | + super(mv, access, methodName, desc, methodIndex, myName, enhancedSuperName); |
| 27 | + this.methodArray = methodArray; |
| 28 | + } |
| 29 | + |
| 30 | + void visitCode() { |
| 31 | + mv.visitCode(); |
| 32 | + |
| 33 | + for (int i = 0; i < methodArray.length; i++) { |
| 34 | + // start of fuck linenumber |
| 35 | + Label tmp = new Label(); |
| 36 | + mv.visitLabel(tmp); |
| 37 | + mv.visitLineNumber(1, tmp); |
| 38 | + // end of Linenumber |
| 39 | + Method method = methodArray[i]; |
| 40 | + mv.visitVarInsn(ILOAD, 1); |
| 41 | + visitX(i); |
| 42 | + Label l0 = new Label(); |
| 43 | + mv.visitJumpInsn(IF_ICMPNE, l0); |
| 44 | + mv.visitVarInsn(ALOAD, 0); |
| 45 | + Type[] args = Type.getArgumentTypes(method); |
| 46 | + for (int j = 0; j < args.length; j++) { |
| 47 | + mv.visitVarInsn(ALOAD, 2); |
| 48 | + visitX(j); |
| 49 | + mv.visitInsn(AALOAD); |
| 50 | + returnType = args[j]; |
| 51 | + AsmHelper.checkCast(returnType,mv); |
| 52 | + } |
| 53 | + mv.visitMethodInsn( INVOKESPECIAL, |
| 54 | + enhancedSuperName, |
| 55 | + method.getName(), |
| 56 | + Type.getMethodDescriptor(method)); |
| 57 | + { |
| 58 | + returnType = Type.getReturnType(method); |
| 59 | + if (returnType.equals(Type.VOID_TYPE)) |
| 60 | + mv.visitInsn(ACONST_NULL); |
| 61 | + else if (returnType.getOpcode(IRETURN) != ARETURN) |
| 62 | + AsmHelper.packagePrivateData(returnType,mv); |
| 63 | + mv.visitInsn(ARETURN); |
| 64 | + } |
| 65 | + mv.visitLabel(l0); |
| 66 | + } |
| 67 | + |
| 68 | + mv.visitInsn(ACONST_NULL); |
| 69 | + mv.visitInsn(ARETURN); |
| 70 | + mv.visitMaxs(4, 3); |
| 71 | + mv.visitEnd(); |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments