AspectJ的写作2个独立的切入点之一的onCreate()等的方法休息 [英] AspectJ writing 2 separate pointcuts one for onCreate() and other for rest of methods

查看:217
本文介绍了AspectJ的写作2个独立的切入点之一的onCreate()等的方法休息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的AspectJ Android和我有写2切入点其中一个做切入点执行为的onCreate()和其他用于在方法其余的要求Android应用程序排除的onCreate()

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().

目前我的方法,切入点也注入的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是我看点文件

Tester.aj is my Aspect file

推荐答案

假设你有2个切入点,一个是的onCreate()方法和 methodcalls (),您应该依靠切入点布尔前pression:

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();

然后添加()之前和/或后()仅用于 yourOnCreatePointcut() GIVE_IT_A_PROPER_NAME()切入点,而不是为 methodCalls()

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

这篇关于AspectJ的写作2个独立的切入点之一的onCreate()等的方法休息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆