A
applex
I created two files:
PreConditionExample.java
public class PreConditionExample {
public double sqrt(double p) {
return Math.sqrt(p);
}
public static void main(String[] args) {
PreConditionExample t = new PreConditionExample();
System.out.println("sqrt -4 : "+t.sqrt(-4));
System.out.println("sqrt 9 : "+t.sqrt(9));
}
}
PreconditionAspect.aj
public aspect PreconditionAspect
{
pointcut sqrtPc(double param) : call ( * Math.sqrt(double)) &&
args(param) ;
before(double param ) : sqrtPc(param)
{
if (param < 0)
{
System.out.println("illegal parameter");
//throw new RuntimeException();
}
}
}
but it doesn't work in this way. "illegal parameter " was not printed.
but I put them in the same file, it works.
Why?
help/
PreConditionExample.java
public class PreConditionExample {
public double sqrt(double p) {
return Math.sqrt(p);
}
public static void main(String[] args) {
PreConditionExample t = new PreConditionExample();
System.out.println("sqrt -4 : "+t.sqrt(-4));
System.out.println("sqrt 9 : "+t.sqrt(9));
}
}
PreconditionAspect.aj
public aspect PreconditionAspect
{
pointcut sqrtPc(double param) : call ( * Math.sqrt(double)) &&
args(param) ;
before(double param ) : sqrtPc(param)
{
if (param < 0)
{
System.out.println("illegal parameter");
//throw new RuntimeException();
}
}
}
but it doesn't work in this way. "illegal parameter " was not printed.
but I put them in the same file, it works.
Why?
help/