File tree Expand file tree Collapse file tree
android-aop-annotation/src/main/java/com/flyjingfish/android_aop_annotation
android-aop-plugin/src/main/kotlin/com/flyjingfish/android_aop_plugin/scanner_visitor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -300,11 +300,17 @@ private void getTargetMethod(){
300300 try {
301301 originalMethod = tClass .getDeclaredMethod (originalMethodName , classes );
302302 } catch (NoSuchMethodException exc ) {
303- String realMethodName = getRealMethodName (originalMethodName );
304- if (realMethodName == null ){
303+ // String realMethodName = getRealMethodName(originalMethodName);
304+ // if (realMethodName == null){
305+ // throw new RuntimeException(exc);
306+ // }
307+ // originalMethod = tClass.getDeclaredMethod(realMethodName, classes);
308+ System .out .println ("=======>" +originalMethodName );
309+ originalMethod = Utils .INSTANCE .findMethodWithKeepName (tClass ,originalMethodName ,classes );
310+ if (originalMethod == null ){
305311 throw new RuntimeException (exc );
306312 }
307- originalMethod = tClass . getDeclaredMethod ( realMethodName , classes );
313+ System . out . println ( "=======>" + originalMethodName + "<==Success=" + originalMethod . getName () );
308314 }
309315 targetMethod .setAccessible (true );
310316 originalMethod .setAccessible (true );
Original file line number Diff line number Diff line change 11package com.flyjingfish.android_aop_annotation.aop_anno
22
33
4- @Retention(AnnotationRetention .BINARY )
4+ @Retention(AnnotationRetention .RUNTIME )
55@Target(
66 AnnotationTarget .TYPE ,
77 AnnotationTarget .ANNOTATION_CLASS ,
@@ -11,4 +11,4 @@ package com.flyjingfish.android_aop_annotation.aop_anno
1111 AnnotationTarget .PROPERTY_GETTER ,
1212 AnnotationTarget .FIELD
1313)
14- annotation class AopKeep
14+ annotation class AopKeep ( val keepName : String = " " )
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package com.flyjingfish.android_aop_annotation.utils
22
33import com.flyjingfish.android_aop_annotation.AndroidAopJoinPoint
44import com.flyjingfish.android_aop_annotation.ProceedReturn
5+ import com.flyjingfish.android_aop_annotation.aop_anno.AopKeep
56import com.flyjingfish.android_aop_annotation.base.OnBaseSuspendReturnListener
67import com.flyjingfish.android_aop_annotation.base.OnSuspendReturnListener
78import com.flyjingfish.android_aop_annotation.base.OnSuspendReturnListener2
@@ -154,4 +155,22 @@ internal object Utils {
154155 val matcher: Matcher = InvokeStaticClassPattern .matcher(className)
155156 return matcher.find()
156157 }
158+
159+ fun findMethodWithKeepName (
160+ clazz : Class <* >,
161+ keepName : String ,
162+ parameterTypes : Array <Class <* >>
163+ ): Method ? {
164+ return clazz.declaredMethods.firstOrNull { method ->
165+ // 1. 参数列表必须完全匹配
166+ if (! method.parameterTypes.contentEquals(parameterTypes)) {
167+ return @firstOrNull false
168+ }
169+ // 2. 注解必须存在并且 keepName 一致
170+ val annotation = method.getAnnotation(AopKeep ::class .java)
171+ annotation?.keepName == keepName
172+ }
173+ }
174+
175+
157176}
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ import javassist.bytecode.AnnotationsAttribute
3838import javassist.bytecode.AttributeInfo
3939import javassist.bytecode.ConstPool
4040import javassist.bytecode.annotation.Annotation
41+ import javassist.bytecode.annotation.StringMemberValue
4142import kotlinx.coroutines.Deferred
4243import kotlinx.coroutines.Dispatchers
4344import kotlinx.coroutines.async
@@ -954,6 +955,14 @@ object WovenIntoCode {
954955 val ctMethodNoneHasKeep = annotationsAttribute.getAnnotation(KEEP_CLASS ) == null
955956 if (ctMethodNoneHasKeep){
956957 val annotation = Annotation (KEEP_CLASS , constPool)
958+
959+ // 给注解添加参数 keepName = 方法名
960+ val methodName = this .name
961+ annotation.addMemberValue(
962+ " keepName" ,
963+ StringMemberValue (methodName, constPool)
964+ )
965+
957966 annotationsAttribute.addAnnotation(annotation)
958967 if (visibleTagAttribute == null ){
959968 methodInfo.addAttribute(annotationsAttribute)
You can’t perform that action at this time.
0 commit comments