2424import net .tascalate .asmx .ClassVisitor ;
2525import net .tascalate .asmx .FieldVisitor ;
2626import net .tascalate .asmx .MethodVisitor ;
27- import net .tascalate .asmx .Type ;
28- import net .tascalate .asmx .Opcodes ;
2927
28+ import org .apache .commons .javaflow .instrumentation .cdi .owb .OwbProxyClassProcessor ;
29+ import org .apache .commons .javaflow .instrumentation .cdi .spring .SpringProxyClassProcessor ;
30+ import org .apache .commons .javaflow .instrumentation .cdi .weld .WeldProxyClassProcessor ;
3031import org .apache .commons .javaflow .spi .ContinuableClassInfo ;
3132import org .apache .commons .javaflow .spi .ContinuableClassInfoResolver ;
3233import org .apache .commons .javaflow .spi .StopException ;
3334
34- class CdiProxyClassAdapter extends ClassVisitor {
35+ class CdiProxyClassAdapter extends ExtendedClassVisitor {
3536
36- static enum CdiEnvironmentType {
37+ static enum ContainerType {
3738 WELD ("org/jboss/weld/bean/proxy/ProxyObject" ) {
3839
3940 @ Override
@@ -44,68 +45,58 @@ boolean accept(String className, String interfaceName) {
4445 }
4546
4647 @ Override
47- MethodVisitor createAdviceAdapter (CdiProxyClassAdapter ca , MethodVisitor mv , int acc , String name , String desc ) {
48- return new AroundWeldProxyInvocationAdvice (ca .api , mv , acc , ca .className , name , desc );
49- }
48+ ProxyClassProcessor createProcessor (int api , String className , ContinuableClassInfo classInfo ) {
49+ return new WeldProxyClassProcessor (api , className , classInfo );
50+ }
51+
5052 },
5153 SPRING ("org/springframework/aop/framework/Advised" ) {
5254
5355 @ Override
54- MethodVisitor createAdviceAdapter ( CdiProxyClassAdapter ca , MethodVisitor mv , int acc , String name , String desc ) {
55- return new AroundSpringProxyInvocationAdvice ( ca . api , mv , acc , ca . className , name , desc );
56+ ProxyClassProcessor createProcessor ( int api , String className , ContinuableClassInfo classInfo ) {
57+ return new SpringProxyClassProcessor ( api , className , classInfo );
5658 }
59+
5760 },
5861 OWB (
5962 "org/apache/webbeans/proxy/OwbInterceptorProxy" ,
6063 "org/apache/webbeans/proxy/OwbNormalScopeProxy"
6164 ) {
6265
6366 @ Override
64- MethodVisitor createAdviceAdapter (CdiProxyClassAdapter ca , MethodVisitor mv , int acc , String name , String desc ) {
65- if (null != ca .owbProxiedInstanceType ) {
66- return new AroundOwbInterceptorProxyAdvice (ca .api , mv , acc , ca .className , name , desc , ca .owbProxiedInstanceType );
67- } else if (null != ca .owbProxiedInstanceProviderType ) {
68- return new AroundOwbScopeProxyAdvice (ca .api , mv , acc , ca .className , name , desc , ca .owbProxiedInstanceProviderType );
69- } else {
70- return mv ;
71- }
72- }
67+ ProxyClassProcessor createProcessor (int api , String className , ContinuableClassInfo classInfo ) {
68+ return new OwbProxyClassProcessor (api , className , classInfo );
69+ }
70+
7371 }
7472 ;
7573
7674 private Set <String > markerInterfaces ;
7775
78- private CdiEnvironmentType (String ... markerInterfaces ) {
76+ private ContainerType (String ... markerInterfaces ) {
7977 this .markerInterfaces =
8078 Collections .unmodifiableSet ( new HashSet <String >(Arrays .asList (markerInterfaces )) );
8179 }
8280
83- abstract MethodVisitor createAdviceAdapter (CdiProxyClassAdapter ca , MethodVisitor mv , int acc , String name , String desc );
8481 boolean accept (String className , String interfaceName ) {
8582 return markerInterfaces .contains (interfaceName );
8683 }
84+
85+ abstract ProxyClassProcessor createProcessor (int api , String className , ContinuableClassInfo classInfo );
8786 }
8887
89- String className ;
90- Type owbProxiedInstanceType ;
91- Type owbProxiedInstanceProviderType ;
92-
93- private CdiEnvironmentType cdiEnvironmentType ;
94- private ContinuableClassInfo classInfo ;
95-
9688 private final ContinuableClassInfoResolver cciResolver ;
89+ private ProxyClassProcessor processor ;
9790
9891 CdiProxyClassAdapter (ClassVisitor delegate , ContinuableClassInfoResolver cciResolver ) {
99- super (Opcodes . ASM7 , delegate );
92+ super (delegate );
10093 this .cciResolver = cciResolver ;
10194 }
10295
103-
10496 @ Override
10597 public void visit (int version , int access , String name , String signature , String superName , String [] interfaces ) {
106- className = name ;
107- CdiEnvironmentType selectedType = null ;
108- CdiEnvironmentType [] cdiEnvironmentTypes = CdiEnvironmentType .values ();
98+ ContainerType selectedType = null ;
99+ ContainerType [] cdiEnvironmentTypes = ContainerType .values ();
109100 outerLoop :
110101 for (final String interfaze : interfaces ) {
111102 for (int i = cdiEnvironmentTypes .length - 1 ; i >= 0 ; i --) {
@@ -123,8 +114,7 @@ public void visit(int version, int access, String name, String signature, String
123114 throw StopException .INSTANCE ;
124115 }
125116
126- cdiEnvironmentType = selectedType ;
127-
117+ ContinuableClassInfo classInfo ;
128118 try {
129119 classInfo = cciResolver .resolve (superName );
130120 if (null == classInfo ) {
@@ -133,34 +123,23 @@ public void visit(int version, int access, String name, String signature, String
133123 } catch (IOException e ) {
134124 throw new RuntimeException (e );
135125 }
126+
127+ processor = selectedType .createProcessor (api , name , classInfo );
136128 super .visit (version , access , name , signature , superName , interfaces );
137129 }
138130
139131 @ Override
140- public FieldVisitor visitField (int access , String name , String desc , String signature , Object value ) {
141- if (AroundOwbInterceptorProxyAdvice .FIELD_PROXIED_INSTANCE .equals (name )) {
142- owbProxiedInstanceType = Type .getType (desc );
143- }
144- if (AroundOwbScopeProxyAdvice .FIELD_INSTANCE_PROVIDER .equals (name )) {
145- owbProxiedInstanceProviderType = Type .getType (desc );
146- }
147- return super .visitField (access , name , desc , signature , value );
132+ public FieldVisitor visitField (int access , String name , String descriptor , String signature , Object value ) {
133+ return processor .visitField (this , access , name , descriptor , signature , value );
148134 }
149-
135+
150136 @ Override
151- public MethodVisitor visitMethod (int acc , String name , String desc , String signature , String [] exceptions ) {
152- MethodVisitor mv = cv .visitMethod (acc , name , desc , signature , exceptions );
153- if (isContinuableMethodProxy (acc , name , desc , signature , exceptions ) && null != cdiEnvironmentType ) {
154- mv = cdiEnvironmentType .createAdviceAdapter (this , mv , acc , name , desc );
155- }
156- return mv ;
137+ public void visitEnd () {
138+ processor .visitEnd (this );
157139 }
158-
159- private boolean isContinuableMethodProxy (int acc , String name , String desc , String signature , String [] exceptions ) {
160- int idx = name .lastIndexOf ("$$super" );
161- if (idx > 0 ) {
162- name = name .substring (0 , idx );
163- }
164- return ! "<init>" .equals (name ) && classInfo .isContinuableMethod (acc , name , desc , signature );
140+
141+ @ Override
142+ public MethodVisitor visitMethod (int access , String name , String descriptor , String signature , String [] exceptions ) {
143+ return processor .visitMethod (this , access , name , descriptor , signature , exceptions );
165144 }
166145}
0 commit comments