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/
Mark Thomas - 23 Apr 2006 17:40 GMT
> I created two files:
> PreConditionExample.java
[quoted text clipped - 32 lines]
> Why?
> help/
There's nothing wrong with the code. When I run it, I get:
illegal parameter
sqrt -4 : NaN
sqrt 9 : 3.0
as expected. How are you compiling them?
Mark