aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/InnerClassNaming.java
blob: bf0ec54e74a8639347e7897a87bb499a74230080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.awt.*;
import java.awt.event.*;
import org.aspectj.testing.Tester;

/*
 * I would like to listen to events fired by a whiteboard swing widget.
 * When I listen to method invocations from the widget itself in 
 * an aspect,
 * there
 * is no problem (like say getPreferredSize()).
 * 
 * But, when I want to listen to events fired by a mouse adapter 
 * from which
 * I derived
 * an inner class in the whiteboard like this :
 *
 * SOLUTION: Replace all super.inner to super$inner.
 */

public class InnerClassNaming {
  public static void main(String[] args) {
    new InnerClassNaming();
  }

  InnerClassNaming() {
    MouseListener listener = new MyListener();
    addMouseListener(listener);
  }

  void addMouseListener(MouseListener listener) {}
  
  class MyListener extends MouseAdapter {
    public void mousePressed(MouseEvent e) {
      System.out.println("mousPressed: " + e);
    }
  }  
}

aspect MyAspect /*of eachobject(instanceof(InnerClassNaming.MyListener))*/ {
  
  pointcut pressed(InnerClassNaming.MyListener ls):
      //instanceof(ls) && executions(* mousePressed(..));
      this(InnerClassNaming.MyListener) &&
      target(ls) &&
      execution(* mousePressed(..));
  
  before(InnerClassNaming.MyListener ls): pressed(ls) {
    System.out.println(thisJoinPoint);
  }
}