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.

MatchingArgumentsInCflow.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import org.aspectj.testing.*;
  2. import java.util.*;
  3. /**
  4. * PR#479
  5. * Variant of Hunter Kelly's bug report PR#479.
  6. * Hunter tried to bind two arguments using withincode(..)
  7. * and call(..), but received an error. This does it the right
  8. * way and is working as of 1.0alpha1.
  9. *
  10. * @since 2001.08.06
  11. * @author Jeff Palm
  12. * @report 479
  13. */
  14. public class MatchingArgumentsInCflow {
  15. public static void main(String[] args) {
  16. new MethodParam().someMethod("arg");
  17. }
  18. }
  19. class MethodParam
  20. {
  21. public void someMethod(String arg)
  22. {
  23. List list = new LinkedList();
  24. list.add(new String(arg+":"+arg));
  25. }
  26. }
  27. aspect MethodParamAspect
  28. {
  29. /*
  30. * Match the top of the call and bind argument
  31. */
  32. pointcut flow(String s):
  33. cflow(execution(void someMethod(String)) && args(s));
  34. /*
  35. * Bind o to the argument to the list
  36. */
  37. pointcut some(Object o):
  38. call(* List.add(Object)) && args(o);
  39. /*
  40. * Make sure these arguments are different
  41. * and assert the values.
  42. */
  43. before (String s, Object o): flow(s) && some(o) {
  44. Tester.checkEqual(s, "arg");
  45. Tester.checkEqual(o, "arg:arg");
  46. Tester.checkNotEqual(s, o);
  47. }
  48. }