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.

Driver.java 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import org.aspectj.testing.Tester;
  2. // PR#140
  3. public class Driver {
  4. public static void main(String[] args) { test(); }
  5. public static void test() {
  6. Tester.checkEqual(new Foo().doIt(), 5, "min of 5 and 6");
  7. Tester.checkEqual(new Bar().doIt(), 1, "min of 5 and 2");
  8. }
  9. }
  10. class Foo {
  11. public static int doIt() {
  12. return new Foo().bar(1, 2, 3);
  13. }
  14. int bar(int a, int b, int c) {
  15. return a * b * c;
  16. }
  17. }
  18. aspect FooAspect {
  19. pointcut cut() : target(Foo) && call(int bar(int, int, int));
  20. int around(): cut() {
  21. int originalResult = proceed();
  22. return Math.max(0, Math.min(originalResult, 5));
  23. }
  24. }
  25. class Bar {
  26. public static int doIt() {
  27. return new Bar().bar(1, 2, 1);
  28. }
  29. int bar(int a, int b, int c) {
  30. return a * b * c;
  31. }
  32. }
  33. aspect BarAspect {
  34. pointcut cut(Bar b) : target(b) && call(int bar(int, int, int));
  35. int around(Bar b): cut(b) {
  36. int originalResult = proceed(b);
  37. return Math.max(0, Math.min(originalResult, 1));
  38. }
  39. }