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.

AspectX.aj 912B

123456789101112131415161718192021222324252627282930313233
  1. import java.util.*;
  2. public aspect AspectX {
  3. static Set matchedJps = new HashSet();
  4. before(): call(* compareTo(..)) {
  5. matchedJps.add(new String("call() matched on "+thisJoinPoint.toString()));
  6. }
  7. before(): execution(* compareTo(..)) {
  8. matchedJps.add(new String("execution() matched on "+thisJoinPoint.toString()));
  9. }
  10. public static void main(String []argv) {
  11. Number n1 = new Number(5);
  12. Number n2 = new Number(7);
  13. n1.compareTo(n2);
  14. n1.compareTo("abc"); // A Java5 compiler would *not* allow this, a call to a bridge method: error should be:
  15. /**
  16. AspectX.java:19: compareTo(Number) in Number cannot be applied to (java.lang.String)
  17. n1.compareTo("abc");
  18. ^
  19. 1 error
  20. */
  21. Iterator i = matchedJps.iterator();
  22. while (i.hasNext()) {
  23. String s = (String)i.next();
  24. System.err.println(s);
  25. }
  26. }
  27. }