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.

ForReplacer.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //package org.acmsl.pocs.lambdafor;
  2. import java.util.Arrays;
  3. public aspect ForReplacer
  4. {
  5. /**
  6. * Intercepting for loop constructs.
  7. */
  8. pointcut forLoopPointcut():
  9. // execution(* Sample.sampleCode(..)); // -> error
  10. execution(* forloop(..));
  11. // && args(Collect, ..);
  12. /**
  13. * Replacing the loop construct.
  14. */
  15. Object around() : forLoopPointcut()
  16. {
  17. // return proceed();
  18. // Collection<Integer> result = new ArrayList<>();
  19. // result.addAll(new ControlFlow().externallyDrivenForloop(new ControlFlowDriver(), Arrays.asList(4, 5, 6), (i) -> { System.out.println(i); return i;}));
  20. // return result;
  21. return new ControlFlow().externallyDrivenForloop(new ControlFlowDriver(), Arrays.asList(4, 5, 6), (i) -> { System.out.println(i); return i;});
  22. }
  23. /**
  24. * Intercepting for loop constructs.
  25. *
  26. pointcut forLoopPointcut(ControlFlow loop):
  27. call(* ControlFlow.forloop(..))
  28. && target(loop);
  29. // && args(items, ..);
  30. /**
  31. * Replacing the loop construct.
  32. *
  33. Collection around(ControlFlow loop) : forLoopPointcut(loop)
  34. {
  35. return loop.externallyDrivenForloop(new ControlFlowDriver(), Arrays.asList(4, 5, 6), (i) -> { System.out.println(i); return i;});
  36. // return new ControlFlow().externallyDrivenForloop(new ControlFlowDriver(), Arrays.asList(4, 5, 6), (i) -> { System.out.println(i); return i;});
  37. }
  38. */
  39. }