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.

Pr113368.aj 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. public aspect Pr113368 {
  2. public static void main(String[] args) {
  3. try {
  4. aspectOf().hook();
  5. } catch (ExceptionInInitializerError ex) {
  6. Throwable cause = ex.getCause();
  7. if (! (cause instanceof org.aspectj.lang.NoAspectBoundException)) {
  8. throw new RuntimeException("Unexpected exception: " + cause);
  9. }
  10. }
  11. }
  12. void hook() {}
  13. private pointcut managedBeanConstruction(ManagedBean bean) :
  14. execution(ManagedBean+.new(..)) && this(bean);
  15. //NPE's on the if pointcut below
  16. private pointcut topLevelManagedBeanConstruction(ManagedBean bean) :
  17. managedBeanConstruction(bean) &&
  18. if(thisJoinPointStaticPart.getSignature().getDeclaringType() == bean.getClass());
  19. after(ManagedBean bean) returning: topLevelManagedBeanConstruction(bean) {
  20. System.out.println("I just constructed " + bean);
  21. }
  22. }
  23. abstract aspect ManagedBean {
  24. }
  25. aspect ManagedSubBean extends ManagedBean {
  26. before() : execution(* hook()) {
  27. }
  28. }
  29. aspect AutoStart {
  30. before() : staticinitialization(ManagedBean) {
  31. ManagedSubBean.aspectOf();
  32. }
  33. }
  34. aspect Tracer {
  35. before() : !within(Tracer) {
  36. System.out.println(thisJoinPoint);
  37. }
  38. }