Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

InnerClassNaming.java 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import org.aspectj.testing.Tester;
  4. /*
  5. * I would like to listen to events fired by a whiteboard swing widget.
  6. * When I listen to method invocations from the widget itself in
  7. * an aspect,
  8. * there
  9. * is no problem (like say getPreferredSize()).
  10. *
  11. * But, when I want to listen to events fired by a mouse adapter
  12. * from which
  13. * I derived
  14. * an inner class in the whiteboard like this :
  15. *
  16. * SOLUTION: Replace all super.inner to super$inner.
  17. */
  18. public class InnerClassNaming {
  19. public static void main(String[] args) {
  20. new InnerClassNaming();
  21. }
  22. InnerClassNaming() {
  23. MouseListener listener = new MyListener();
  24. addMouseListener(listener);
  25. }
  26. void addMouseListener(MouseListener listener) {}
  27. class MyListener extends MouseAdapter {
  28. public void mousePressed(MouseEvent e) {
  29. System.out.println("mousPressed: " + e);
  30. }
  31. }
  32. }
  33. aspect MyAspect /*of eachobject(instanceof(InnerClassNaming.MyListener))*/ {
  34. pointcut pressed(InnerClassNaming.MyListener ls):
  35. //instanceof(ls) && executions(* mousePressed(..));
  36. this(InnerClassNaming.MyListener) &&
  37. target(ls) &&
  38. execution(* mousePressed(..));
  39. before(InnerClassNaming.MyListener ls): pressed(ls) {
  40. System.out.println(thisJoinPoint);
  41. }
  42. }