[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
Re: [aspectj-users] AspectJ advising with generic pointcuts
|
- From: Andy Clement <andrew.clement@xxxxxxxxx>
- Date: Tue, 4 Jan 2011 16:05:49 -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:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=OB7sL5iJrfF2mSh7GjzNrTiNix5oiiKaVWgAS6Gc5p4=; b=SBRQubcOQFTm9e2ZviITxVIBjPM1OWBHgHVV79xH58f7WyDJAEHuhAgq9pYmfZWUre 59FkL4GJgkgWETTULZyOl0FLrEoJcxzjGWOZTAgm8Rg/M/9PZ7edJKZymGo1ZAzcg9St BeNEwJnkhDcBkfm7CDaAtzV9gBlKDMOqIggcM=
- 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; b=CRKZJfKqKaitrzt2V0c2EQbHIaGaf72rZfE+lO/LSXhP7FTiZZHBtWqESoxCH+9Y3U k3N6ZBv+rn3onyMQYV3uLfMm1H3shpVA17NgoMfbXrRayNRgfTJL0SGTY2N7/YbIs4m5 oNYqaQ3yzKUIbMrJTMbIxuH2VhARnwjK+Y5Iw=
On 4 January 2011 15:51, Srinivas <tssrinivas@xxxxxxxxx> wrote:
> This however does not seem to work if the argument type is a "grandchild" of
> Vehicle. That is , if Toyota-->Car-->Vehicle, then this does not seem to
> match Toyota. Will it only match Car, and not Toyota ?
Not quite sure what you mean, it should work for all subtypes of
Vehicle (Car and Toyota). Are you sure your Toyota extends Car? Here
is a test program:
import org.aspectj.lang.*;
import org.aspectj.lang.annotation.*;
public class Code {
public static void main(String argv[]) {
new Code().run();
}
public void run() {
Vehicle v = new Vehicle();
Car c = new Car();
Toyota t = new Toyota();
a(v);
a(c);
a(t);
b(c);
b(t);
c(t);
}
public void a(Vehicle v) {}
public void b(Car c) {}
public void c(Toyota t) {}
}
@Aspect
class Azpect {
@Before("execution(public * *(Vehicle+, ..)) && args(myarg, ..) ")
public void m(Vehicle myarg,JoinPoint.StaticPart jpsp) {
System.out.println("Vehicle is "+myarg.getClass().getName()+" at "+jpsp);
}
}
class Vehicle {
}
class Car extends Vehicle {
}
class Toyota extends Car {
}
and produces the expected 6 lines of output:
Vehicle is Vehicle at execution(void Code.a(Vehicle))
Vehicle is Car at execution(void Code.a(Vehicle))
Vehicle is Toyota at execution(void Code.a(Vehicle))
Vehicle is Car at execution(void Code.b(Car))
Vehicle is Toyota at execution(void Code.b(Car))
Vehicle is Toyota at execution(void Code.c(Toyota))
cheers
Andy