[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] How to recognize the name of invoked classes&methods&fields in an aspect?
|
I am now doing some programming used to recognize the name of all classes,
methods, constructors and fields invoked from other classes in a given
aspect. This recognition is required automatical. Now I really have no idea
how to realize it. Can anyone please give me some suggestions how to
programme it?
Because weaving the aspect into classes happens in the compile time in
AspectJ, this implementation is expected to be done before the compile time
as all outer classes, methods(including woven methods and invoked methods),
constructors and fields in that given aspect don't exist in the first
place. In other words, all the information about the outer classes and
methods can only be found in that aspect.
Now I show you a specific example to make sure you understand my question.
From the following example, firstly I've no idea what outer
classes(incuding woven classes and any other outer invoked classes),
methods and fields are used in aspect "PointShadowProtocol". However, the
expected functionality of realization is to find out: 1, the name of two
used outer classes: Shadow, Point; 2, invoked constructor: Shadow s=new
Shadow(int x,int y); 3, invoked methods: Point.getX(), Point.getY(),
Point.printPosition(),Shadow.offset,Shadow.printPosition(); and 4,
invoked field: Point.x,Point.y,Shadow.x,Shadow.y
public aspect PointShadowProtocolAspect {
private int shadowCount=0;
public static Shadow getShadow(Point p){
Shadow s=new Shadow(p.x,p.y);
return s;
}
pointcut setting(Point p): target(p)&&call(Point.new(int,int));
pointcut settingX(Point p):target(p)&&call(void Point.setX(int));
pointcut settingY(Point p):target(p)&&call(void Point.setY(int));
after(Point p): setting(p){
Shadow s=new Shadow(p.x,p.y);
shadowCount++;
}
after(Point p):settingX(p){
Shadow s=getShadow(p);
s.x=p.getX()+Shadow.offset;
p.printPosition();
s.printPosition();
}
after(Point p):settingY(p){
Shadow s=getShadow(p);
s.y=p.getY()+Shadow.offset;
p.printPosition();
s.printPosition();
}
}
Actually, after realizing this functionality, I will use these results to
automatically generate the related class stub, method stub, field stub,
which can be used to execute and test the given aspect
"PointShadowProtocol", probably equivalent to unit test of the aspect
individually and seperately.
Any suggestions are welcome. Thank you in advance for your reply.
_________________________________________________________________
免费下载 MSN Explorer: http://explorer.msn.com/lccn