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.

IfPCDExprVisibility.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. aspect AspectForIfPCDExprVisibility {
  2. // See IfPCDExprJoinPoint* for join-point error cases
  3. pointcut stringLArgs(String[] args)
  4. : args (args);
  5. pointcut targetTarget(IfPCDExprVisibility target)
  6. : target(target);
  7. pointcut thisItem(IfPCDExprVisibility thisItem)
  8. : this(thisItem);
  9. pointcut callDo()
  10. : call(void IfPCDExprVisibility());
  11. pointcut callMain(String[] args)
  12. : args(args) && call(static void *..main(String[])) ;
  13. // ok: anonymous pointcut
  14. /**
  15. *@testTarget ifpcd.compile.visibility.tjp
  16. *@testTarget ifpcd.compile.visibility.tjpsp
  17. */
  18. before ()
  19. : if (thisJoinPoint != null)
  20. && if (thisJoinPointStaticPart != null)
  21. && call(void IfPCDExprJoinPointVisibleCE.main(..)) {
  22. System.err.println("before main + " + thisJoinPoint);
  23. }
  24. // ok: anonymous pointcut, name composition, arg state
  25. /**
  26. */
  27. before (String[] args)
  28. : if (thisJoinPointStaticPart != null)
  29. && if (null != args)
  30. && callMain (args){
  31. String m = "before main"
  32. + " join point: " + thisJoinPoint
  33. + " args: " + args ;
  34. System.err.println(m);
  35. if (null == thisJoinPointStaticPart)
  36. throw new Error("impossible null thisJoinPointStaticPart");
  37. // actually, it is possible to directly invoke main with null args...
  38. if (null == args) throw new Error("null args");
  39. }
  40. /**
  41. *@testTarget ifpcd.compile.visibility.args.named
  42. *@testTarget ifpcd.compile.visibility.this.named
  43. *@testTarget ifpcd.compile.visibility.target.named
  44. */
  45. Object around (String[] _args
  46. , IfPCDExprVisibility _target
  47. , IfPCDExprVisibility _thisItem)
  48. : targetTarget(_target)
  49. && thisItem(_thisItem)
  50. && call(* IfPCDExprVisibility.exec(..))
  51. && args(_args)
  52. && if(null != _args)
  53. && if(null != _target)
  54. && if(null != _thisItem)
  55. {
  56. String m = "around main - start "
  57. + " join point: " + thisJoinPoint
  58. + " static join point: " + thisJoinPointStaticPart
  59. + " this: " + _thisItem
  60. + " target: " + _target
  61. + " args: " + _args
  62. ;
  63. System.err.println(m);
  64. // note: no compile error unless around is actually woven in
  65. proceed(_args, _target, _thisItem);
  66. m = "around main - end "
  67. + " join point: " + thisJoinPoint
  68. + " static join point: " + thisJoinPointStaticPart
  69. + " this: " + _thisItem
  70. + " target: " + _target
  71. + " args: " + _args
  72. ;
  73. System.err.println(m);
  74. return null;
  75. }
  76. }
  77. /**
  78. * @author wes
  79. */
  80. public class IfPCDExprVisibility {
  81. void exec(String[] args) {
  82. if (null == args) {
  83. System.err.println("exec running with null args");
  84. } else {
  85. System.err.println("exec running with args: " + args);
  86. System.err.println("exec calling itself with null args: " + args);
  87. // only this call is captured by around - from/to this object
  88. exec(null);
  89. }
  90. }
  91. public static void main(String[] args) {
  92. if (null != args) {
  93. System.err.println("main calling itself with null args");
  94. new IfPCDExprVisibility().main(null); // self-call
  95. System.err.println("main done calling itself with null args");
  96. new IfPCDExprVisibility().exec(args);
  97. } else {
  98. System.err.println("ok - main running with null args");
  99. }
  100. }
  101. }