【问题标题】:AspectJ writing 2 separate pointcuts one for onCreate() and other for rest of methodsAspectJ 编写 2 个单独的切入点,一个用于 onCreate(),另一个用于其余方法
【发布时间】:2015-12-23 14:29:35
【问题描述】:

我正在使用适用于 Android 的 AspectJ,并且我需要编写 2 个切入点,其中一个用于执行 onCreate() 的切入点,而另一个用于 Android 应用程序中不包括 onCreate() 的其余方法的切入点执行。

目前我的方法切入点也在注入我不想发生的 onCreate()。是这样的——

pointcut methodCalls():
          execution(* com.hello..*(..)) && !within(com.retro.Tester);

Tester.aj 是我的 Aspect 文件

【问题讨论】:

    标签: android aspectj


    【解决方案1】:

    假设您有 2 个切入点,一个用于 onCreate() 方法和 methodcalls(),您应该依赖切入点布尔表达式:

    pointcut yourOnCreatePointcut() : execution(INSERT_YOUR_CONDITIONS);
    pointcut methodCalls(): execution(* com.hello..*(..)) && !within(com.retro.Tester);
    pointcut GIVE_IT_A_PROPER_NAME() : methodCalls() && ! yourOnCreatePointcut();
    

    然后,仅为yourOnCreatePointcut()GIVE_IT_A_PROPER_NAME() 切入点添加before() 和/或after(),而不是methodCalls()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 2015-06-01
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多