[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Using cflowbelow to detect cycles in the call graph - Not working
|
Hi, I'm trying out the following simple example whereby I have two classes, which contain an object of the other class's type in each. I then proceed to construct four objects in such a way that a cycle is created. When I call the equals method, I should get an infinite cycle. I tried to create a pointcut descriptor that detects this. Unfortunately, this only works when the nesting level in the call stack is less than 4. I need to create a PCD which detects cycles when the same equals method in the same object is called in the same call stack. Here is the code (which doesn't work as it should):
import java.util.*;
class Launcher {
public static void main(String[] args) {
Test1 t1=new Test1(1);
Test2 t2=new Test2(2);
Test1 t3=new Test1(3);
Test2 t4=new Test2(4);
t1.myObject=t2;
t2.myObject=t3;
t3.myObject=t4;
t4.myObject=t1;
assert t3.equals(t1);
System.out.println("haha, no more cycles!");
}
}
class Test1 {
public Test1(int c) { i=c; }
int i;
Test2 myObject;
public boolean equals(Object o) {
System.out.println(i);
return myObject.equals(((Test1)o).myObject);
}
}
class Test2 {
public Test2(int c) { i=c; }
int i;
Test1 myObject;
public boolean equals(Object o) {
System.out.println(i);
return myObject.equals(((Test2)o).myObject);
}
}
aspect A {
pointcut inTest1(Test1 i): call(boolean Test1.equals(Object)) && target(i);
pointcut inTest2(Test2 i): call(boolean Test2.equals(Object)) && target(i);
boolean around(Test1 up, Test1 now):
inTest1(now) && cflowbelow(inTest1(up)) && if(up==now){
return true;
}
boolean around(Test2 up, Test2 now):
if(up==now) && cflowbelow(inTest2(up)) && inTest2(now) {
return true;
}
}
--
Regards,
Neville Grech