AspectJ writing 2 separate pointcuts one for onCreate() and other for rest of methods

混江龙づ霸主 提交于 2019-12-13 01:28:39

问题


I am using AspectJ for Android and I am having a requirement of writing 2 pointcuts one which does pointcut execution for onCreate() and other for rest of the methods in the Android app that excludes onCreate().

Currently my pointcut for methods is also injecting onCreate() which I dont want to happen. It is like this -

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

Tester.aj is my Aspect file


回答1:


Assuming you have 2 pointcuts, one for onCreate() method and methodcalls(), you should rely on pointcuts boolean expression:

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

Then, add before() and/or after() only for the yourOnCreatePointcut() and GIVE_IT_A_PROPER_NAME() pointcuts, not for methodCalls().



来源:https://stackoverflow.com/questions/34437847/aspectj-writing-2-separate-pointcuts-one-for-oncreate-and-other-for-rest-of-me

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!