[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
Re: [aspectj-users] MethodPattern for Methods with arguments without wildcard '..'
|
- From: Andy Clement <andrew.clement@xxxxxxxxx>
- Date: Fri, 11 Dec 2009 00:11:45 -0800
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=g/D/L8VkE/+PnaNT8uC/BZBRrnVjRqxkHySnOFDEZBU=; b=BlSvEkLhwCC1SM4JxwAoG3zrNF8/9cZeXr+aR7Ky6UmRyNnZJwQFgltcj24MfS6wwu JwcZV8QnRNfmB5AjFZlVi6qe27jPk4JQxPwZ7hObMkQEyHdiA/Yl3XPI7LSz+GOTcsCS Wun9Q4v+XznVKweWBYyjYsU30ept4L4/rNob8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=hbsRy9phzOWDZv1pKsLXiZct2iAfkQOaURJAMrUeZmcqJtLpletHX8orSU0XTERLgs V2FGGOlRi8Gu9T53A8OkBVi1g9EYIDhgOFgxsuSOQoKlhZsE+mMWnIGXxbh/Ek0wv3HY ukeAyWoDU9/9ierqShja8m2YReG9NcYmF3zi4=
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
>