Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Advising all calls to all methods within a certain package

2008/6/23 Raffi Takvor Khatchadourian <khatchad@xxxxxxxxxxxxxxxxxx>:
> On Mon 23.Jun'08 at 11:26:04 -0700, Andy Clement wrote:
>>>
>>> Thanks for the help but this seems odd that something that can be
>>> resolved statically would require a dynamic check.
>>
>> What about this:
>>
>> public class A { public static void main(String []argv) { callit(new
>> packageOne.P()); callit(new packageTwo.Q()); // where packageTwo.Q
>> extends packageOne.P }
>>
>>  public static void callit(P p) { p.m(); }
>> }
>>
>> and pointcut:
>>
>> call(* packageOne..*.*(..))
>
> But here packageOne is a type name and not a package name.

No, packageOne is a package name.  it reads any type in package
packageOne or any sub package of packageOne.

I think you want to use within() and execution() for your use case:

execution(* *(..)) && within(java.io..*)

> IMHO if you
> are looking for advise calls whose compile time target methods are
> contained within a certain package you should be able to do so w/o a
> dynamic check. Also, IMHO package containment shouldn't be considered
> transitive, i.e., when one type inherits from another type it does not
> take on its package. Does that make sense?

call() doesn't work how you would like it to when specifying declaring
type.  within() limits it to join points occurringly lexically within
the specified types will limit you to only join points in java.io and
sub packages.

Andy.


Back to the top