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.

AroundDoubleAssignmentC.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import org.aspectj.testing.*;
  2. /**
  3. * with -usejavac: cannot resolve symbol
  4. * without -usejavac: VerifyError
  5. */
  6. public aspect AroundDoubleAssignmentC {
  7. public static void main( String[] args ){
  8. //---------- passing tests
  9. // field init
  10. Tester.expectEvent("proceed-fieldinit");
  11. new FieldInit();
  12. // field set
  13. Tester.expectEvent("fieldset");
  14. Tester.expectEvent("proceed-fieldset");
  15. new FieldSet().test();
  16. //---------- failing tests
  17. // static method, field set
  18. Tester.expectEvent("staticfieldset-test");
  19. Tester.expectEvent("proceed-staticset");
  20. StaticSet.staticTest();
  21. // static initializer
  22. Tester.expectEvent("staticinit");
  23. Tester.expectEvent("proceed-staticinit");
  24. Class c2 = StaticInit.class.getClass();
  25. Tester.check("test".equals(StaticInit.string),
  26. "\"test\".equals(StaticInit.string)");
  27. // instance initializer
  28. Tester.expectEvent("init");
  29. //XXX see below
  30. //Tester.expectEvent("proceed-init");
  31. String s = new Init().string;
  32. Tester.check("test".equals(s),
  33. "\"test\".equals(new Init().string)");
  34. Tester.checkAllEvents();
  35. } // main
  36. Object around() : within(FieldInit) && execution( * *() ) {
  37. Tester.event("proceed-fieldinit");
  38. return proceed();
  39. }
  40. Object around() : execution( * FieldSet.*() ) {
  41. Tester.event("proceed-fieldset");
  42. return proceed();
  43. }
  44. // static method
  45. Object around() : execution( * StaticSet.*() ) {
  46. Tester.event("proceed-staticset");
  47. return proceed();
  48. }
  49. // static initializer
  50. Object around() : staticinitialization(StaticInit) {
  51. Tester.event("proceed-staticinit");
  52. return proceed();
  53. }
  54. // instance initializer
  55. //XXX not implemented in 1.1
  56. // Object around() : initialization(Init.new(..)) {
  57. // Tester.event("proceed-init");
  58. // return proceed();
  59. // }
  60. }
  61. class FieldInit {
  62. /** @testcase PR#687 around all execution with double assignment in initializer (fieldinit) */
  63. String s = getString();
  64. { s = s; }
  65. String getString() { return "test".toString(); }
  66. }
  67. class FieldSet {
  68. /** @testcase PR#687 around all execution with double assignment in initializer (fieldset) */
  69. String s;
  70. public void test(){
  71. s = s = "test"; // not initializer, so...
  72. Tester.event("fieldset");
  73. }
  74. }
  75. class StaticSet {
  76. /** @testcase PR#687 around all execution with double assignment in initializer (staticfieldset) */
  77. static String string;
  78. public static void staticTest(){
  79. String s = s = "test";
  80. string = s;
  81. Tester.event("staticfieldset-" + string);
  82. }
  83. }
  84. /** @testcase PR#687 around all execution with double assignment in initializer (staticinitialization) */
  85. class StaticInit {
  86. static String string;
  87. static {
  88. String s = s = getString();
  89. Tester.event("staticinit");
  90. string = s;
  91. }
  92. static String getString() { return "test"; }
  93. }
  94. /** @testcase PR#687 around all execution with double assignment in initializer (instance initialization) */
  95. class Init {
  96. String string;
  97. Init() {
  98. String s = s = "test";
  99. Tester.event("init");
  100. string = s;
  101. }
  102. }