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

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

Should the call p.m() be advised - clearly it should, but what about
when Q is passed in?  Only at runtime do we really know what types are
flowing around the system, so a dynamic check in the advice or if()
upon what is being called at the join point is entirely reasonable.

Andy.

2008/6/23 Raffi Takvor Khatchadourian <khatchad@xxxxxxxxxxxxxxxxxx>:
> Hi Andy,
>
> On 23 Jun 2008, at 18:15, Andy Clement wrote:
>>
>> See the section on declaring types and joinpoint signatures in the
>> documentation:
>>
>>
>> http://www.eclipse.org/aspectj/doc/released/adk15notebook/join-point-signatures.html#method-call-join-point-signatures
>
> Thanks for the link!
>
>> You are advising calls through subtypes of java.io as well.  Are you
>> sure you do not want to do this?
>
> Yes, I am sure. The intent is to advise all calls to methods pertaining
> to standard I/O; thus why I chose the java.io package. For instance, the
> advice applies to calls to System.out.println(..) which is what I
> desire, however, it also advises calls to StringBuilder.toString() which
> does not pertain directly to I/O. I see now that the reason this call is
> being advised is because StringBuilder implements the
> java.io.Serializable interface.
>>
>> This will work, although introduces a dynamic test:
>>
>>  pointcut p(): call(* java.io..*.*(..)) &&
>>
>>  if(thisJoinPointStaticPart.getSignature().getDeclaringType().getName().startsWith("java.io."));
>
> Thanks for the help but this seems odd that something that can be
> resolved statically would require a dynamic check.
>
> Raffi
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top