[英]pointcut for inherited methods
How can I match all methods available for a specific class? 如何匹配特定类的所有可用方法?
For example I have following class hierarachy 例如我有以下课程等级
A
/ | \
B C D
/ | \
E F I
|
T
I need to match all methods that are available in T
, so these are methods defined in T
itself and also inherited methods from classes A
, C
, F
. 我需要匹配
T
中可用的所有方法,因此这些都是T
本身定义的方法,也是从类A
, C
, F
继承的方法。
I came to following pointcut, but not quite happy with that because it matches lots of other classes not related to T
: 我来到了以下切入点,但是对此并不满意,因为它匹配了许多与
T
不相关的其他类:
execution(* A+.*(..)) && this(T)
As I understand with such pointcut aspectj will modify each method defined in classes A
, B
, C
, D
, E
, F
, I
, T
. 据我所知,切入点AspectJ将修改类
A
, B
, C
, D
, E
, F
, I
, T
定义的每个方法。 I would like not to affect classes out of T
family. 我不想影响
T
族以外的学生。 It would be ideally if only T
is affected (inherited methods are overridden with aspectj code). 理想的情况是只影响
T
(继承的方法被Aspectj代码覆盖)。 There are lots of classes and I want to minimize impact on the rest of system, ie I need to modify behavior only of class T
and do not want these modification to affect other classes. 有很多类,我想最小化对系统其余部分的影响,即我只需要修改类
T
行为,而不希望这些修改影响其他类。
I could rewrite pointcut to following: (execution(* A.*(..)) || execution(* C.*(..)) || ... <all parent classes>) && this(T)
. 我可以将切入点重写为以下内容:
(execution(* A.*(..)) || execution(* C.*(..)) || ... <all parent classes>) && this(T)
。 But this makes me to make sure that hierarchy is correct and update it whenever actual hierarchy changes. 但这使我可以确保层次结构正确,并在实际层次结构发生更改时进行更新。
Thanks. 谢谢。
Your assumption is wrong, I just tried and investigated the byte code. 您的假设是错误的,我只是尝试并研究了字节码。 The advice will only be woven into A, C, F, T because
this()
can be determined statically during compile time. 由于只能在编译期间静态确定
this()
,因此建议仅被编织成A,C,F,T。
Update: I forgot to mention that your pointcut only matches methods derived from A and its subclasses. 更新:我忘了提到您的切入点仅匹配从A及其子类派生的方法。 If you, as you say in the headline, really want to match all inherited methods, use
execution(* *(..)) && this(T)
. 如您在标题中所述,如果您确实想匹配所有继承的方法,请使用
execution(* *(..)) && this(T)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.