Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不同dert文件中不同类里面,相同名称的方法注入有错乱 #123

Open
lancexin opened this issue Jul 9, 2021 · 2 comments
Open

Comments

@lancexin
Copy link

lancexin commented Jul 9, 2021

比如 文件 a.dart 里面有 TestClassA 类里面有loadSuccess方法
文件b.dart里面有 TestClassB 类里面也有loadSuccess方法

我注入了a.dart 里面的loadSuccess方法,但是b.dart里面的方法却会触发

@lancexin
Copy link
Author

lancexin commented Jul 9, 2021

@execute("package:test/app/modules/test1_module/test1_controller.dart","Test1Controller","-onReady")
@pragma("vm:entry-point")
void onReady(PointCut pointcut) {
Log.d('Test1Controller onReady',tag: LOG_TAG_INJECT);
pointcut.proceed();
}

@execute("package:test/app/modules/test2_module/test2_controller.dart","Test2Controller","-onReady")
@pragma("vm:entry-point")
void onReady2(PointCut pointcut) {
Log.d('Test2Controller onReady',tag: LOG_TAG_INJECT);
pointcut.proceed();
}
}

发现注入了相同的方法,两个类中都有onReady方法,但是本来应该触发下面的,却出发了上面的.

@lancexin
Copy link
Author

lancexin commented Jul 9, 2021

修改了一下源码,解决了这个问题,在调用visitProcedure的时候添加了clsName的检测

@OverRide
void visitProcedure(Procedure node) {
String procedureName = node.name.name;
bool needCompareClass = false;
Class originalClass = null;
if(node.parent is Class){
needCompareClass = true;
originalClass = node.parent;
}
String clsName = null;
if(needCompareClass){
clsName = originalClass.name;
}

AopItemInfo matchedAopItemInfo;
int aopItemInfoListLen = _aopItemInfoList.length;
for (int i = 0; i < aopItemInfoListLen && matchedAopItemInfo == null; i++) {
  AopItemInfo aopItemInfo = _aopItemInfoList[i];
  if ((aopItemInfo.isRegex &&
          RegExp(aopItemInfo.methodName).hasMatch(procedureName)) ||
      (!aopItemInfo.isRegex && procedureName == aopItemInfo.methodName )) {
    if(needCompareClass){
      if(aopItemInfo.clsName == clsName){
        matchedAopItemInfo = aopItemInfo;
        break;
      }
    }else{
      matchedAopItemInfo = aopItemInfo;
      break;
    }
  }
}
if (matchedAopItemInfo == null) {
  return;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant