You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CircularAdvice.java 580B

123456789101112131415161718192021222324
  1. import org.aspectj.testing.Tester;
  2. public class CircularAdvice {
  3. public static void main(String[] args) {
  4. Tester.checkEqual(m(5), 5*4*3*2*1, "factorial with advice");
  5. }
  6. public static long m(long l) {
  7. return -1;
  8. }
  9. }
  10. aspect FactorialViaAround {
  11. // this advice uses recursive calls within its body to compute factorial
  12. // on an otherwise innocent method
  13. long around (long l): call(long m(long)) && args(l) {
  14. if (l == 0) {
  15. return 1;
  16. } else {
  17. return l * CircularAdvice.m(l - 1);
  18. }
  19. }
  20. }