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.

pr104229.aj 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import java.lang.annotation.*;
  2. import javax.swing.*;
  3. import javax.swing.event.*;
  4. import java.awt.*;
  5. interface GoalSelectedNotice {
  6. public void goalSelected(Object goal);
  7. }
  8. @Retention(RetentionPolicy.RUNTIME)
  9. @interface DefaultImplementation {}
  10. aspect X {
  11. /**
  12. * Watch for goalSelected(..) method being called when
  13. * not within this aspect.
  14. */
  15. pointcut goalSelectedPointcut(GoalSelectedNotice _this, Object goal):
  16. call(void GoalSelectedNotice.goalSelected(Object))
  17. && target(_this) && args(goal) && !cflow(adviceexecution());
  18. declare warning : call(void GoalSelectedNotice.goalSelected(Object)) : "bingo";
  19. after(Object caller, Object o) returning : call(void GoalSelectedNotice.goalSelected(Object)) && args(o) && target(caller){
  20. System.out.println("call match " + caller.getClass());
  21. }
  22. after(GoalSelectedNotice _this, Object goal) returning:
  23. goalSelectedPointcut(_this, goal){
  24. System.out.println("OK it worked!");
  25. }
  26. /**
  27. * Empty body, can be overriden by classes implementing
  28. * {@link GoalSelectedNotice}.
  29. */
  30. @DefaultImplementation
  31. public void GoalSelectedNotice.goalSelected(Object goal){
  32. }
  33. }
  34. public class pr104229 implements GoalSelectedNotice {
  35. interface CallMe { void doIt(); }
  36. public static void main(String[] args) {
  37. pr104229 pr = new pr104229();
  38. pr.callInner();
  39. }
  40. public void callInner() {
  41. CallMe callMe = new CallMe() {
  42. public void doIt() {
  43. pr104229.this.goalSelected("MyGoal");
  44. }
  45. };
  46. callMe.doIt();
  47. }
  48. }
  49. class ListPanel extends JPanel implements GoalSelectedNotice{
  50. private JComboBox jComboBox = null;
  51. private JList jList = null;
  52. /**
  53. * This is the default constructor
  54. */
  55. public ListPanel() {
  56. super();
  57. initialize();
  58. }
  59. /**
  60. * This method initializes this
  61. *
  62. * @return void
  63. */
  64. private void initialize() {
  65. this.setLayout(new BorderLayout());
  66. this.setSize(300,200);
  67. this.add(getJComboBox(), java.awt.BorderLayout.NORTH);
  68. this.add(getJList(), java.awt.BorderLayout.CENTER);
  69. }
  70. /**
  71. * This method initializes jComboBox
  72. *
  73. * @return javax.swing.JComboBox
  74. */
  75. private JComboBox getJComboBox() {
  76. if (jComboBox == null) {
  77. jComboBox = new JComboBox((ComboBoxModel)null);
  78. }
  79. return jComboBox;
  80. }
  81. /**
  82. * This method initializes jList
  83. *
  84. * @return javax.swing.JList
  85. */
  86. private JList getJList() {
  87. if (jList == null) {
  88. jList = new JList((ListModel)null);
  89. jList.addListSelectionListener(
  90. new ListSelectionListener(){
  91. public void valueChanged(ListSelectionEvent e){
  92. if(!e.getValueIsAdjusting()){
  93. JList list = (JList)e.getSource();
  94. Object goal = list.getSelectedValue();
  95. System.out.println(goal);
  96. // If I replace the line below with...
  97. ListPanel.this.goalSelected(goal); //the join point is not seen!;
  98. // This was working before a switched to source level 5!
  99. ListPanel.this.sendGoalSelectedNotice(goal); // this is workaround!
  100. }
  101. }
  102. }
  103. );
  104. }
  105. return jList;
  106. }
  107. // this is part of workaround
  108. protected void sendGoalSelectedNotice(Object goal){
  109. // join point is found by pointcut here! This is ok!
  110. goalSelected(goal);
  111. }
  112. }