Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] MethodPattern for Methods with arguments without wildcard '..'

Hi,

The call pointcut takes a declared signature.  You have to specify the
pattern that would match the declared method.  The contains method
takes an Object , so "call(* Collection.contains(Object))" will match
it.  Both these work for me:

before(Collection c, String s): target(c) && args(s) && call(*
Collection.contains(Object)) {}

before(Collection c, String s): target(c) && args(s) && call(*
Collection.contains(Object+)) {}

Of course the original method was declared generically but the erasure
of the declaration is Object (as you can see with javap on
Collection).

You did mention Object+ didn't work for you, which confuses me - did
you have exactly what I show above?

You also say how do you test the runtime type without exposing it:

before(Collection c): target(c) && args(String) && call(*
Collection.contains(Object)) {}

this/target/args check runtime type information.

Andy

2009/12/10  <jbresson@xxxxxxxxxx>:
> Hi,
>
> I am looking for the point-cut for contains method (line 9) in the following
> Java code:
>
>   Collection<String> c;
>   c = new ArrayList<String>();
>   c.add("x");
>   c.add("y");
>
>   String s;
>   s = "z";
>
>   if(!c.contains(s)) {
>        c.add(s);
>   }
>
>
> This Pointcut works:
>
>   public aspect DequeAspect {
>
>      pointcut test(Collection c, String s): target(c) &&
>                                             args(s) &&
>                                             call(* Collection.contains(..));
>
>      after(Collection c, String s): test(c, s) {
>         System.err.println("AFTER: "+c.toString()+" CONTAINS "+s);
>      }
>   }
>
>
> After a look at the page <Appendix B. Language Semantics>
> http://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html
>
> It seems to be that the wildcard '..' in the contains Method can also be a
> TypePattern.
>
> But I tested :
>   pointcut test(Collection c, String s): target(c) && args(s) &&
>                                          call(*
> Collection.contains(String));
>
> and that is not working (I also tried Object+ or String+).
>
>
> In this example, using the wildcard is not big deal, but what if you just
> want to test the Type of the argument (without exposing this values) :
>   pointcut test(Collection c): target(c) &&
>                                call(* Collection.contains(String));
>
> produce a AdviceDidNotUsed warning (on the Advice using this pointcut)
>
>
> How do you define correctly the MethodPattern (especially the TypePattern)
> without the wildcard '..'? Is that possible?
>
>
> Regards,
>
> Jérémie
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top