Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Problem converting to annotation style

I am resurrecting an aspect that I developed a while ago in the non-annotation style and trying to convert it to annotation style. I've read the documents and made what seemed to be the appropriate changes, but the effect is that, while ajc compiles everything happily, no weaving occurs, confirmed by the -showWeaveInfo option. I've scanned the archives for relevant posts and come up empty, so I'm hoping someone can see what I assume is a trivial mistake.

Here is the key part of the non-annotation version:

public abstract aspect Trace {
public abstract pointcut execAll();

before() : execAll() {
      doBefore(thisJoinPoint);
}
public void doBefore(JoinPoint jp) {
  // the work
}
after() returning(Object result) : execAll() {
      doAfter(thisJoinPoint, result, true);
}

 after() throwing(Throwable t) : execAll() {
      doAfter(thisJoinPoint, t, false);
}

protected void doAfter(JoinPoint jp, Object result, boolean normalReturn) {
  // the work
}
}

This is coupled with a concrete aspect, e.g to trace code with classes A and C:

aspect TraceAandCTest extends Trace {
public pointcut execAll() : execution(* A.*(..)) || execution(* C.*(..));
}

This all works just fine.

Now here is the annotation version:

import org.aspectj.lang.annotation.*;
@Aspect
public abstract class Trace {
  @Pointcut("")
  public abstract void execAll();
  @Before("execAll()")
  public void doBefore(JoinPoint jp) {
    // the work
  }
  @AfterReturning(pointcut="execAll()", returning="result")
  public void doAfterNormalReturn(JoinPoint jp, Object result) {
      doAfter(jp, result, true);
  }

  @AfterThrowing(pointcut="execAll()", throwing="result")
  public void doAfterExceptionReturn(JoinPoint jp, Object result) {
      doAfter(jp, result, false);
  }
protected void doAfter(JoinPoint jp, Object result, boolean normalReturn) {
    // the work
  }
}

Here is the corresponding concrete aspect:

import org.aspectj.lang.annotation.*;

@Aspect
public class TraceAandCTest extends Trace {

  @Pointcut("execution(* A.*(..)) || execution(* C.*(..))")
  public void execAll() {
  }
}

The build scripts for the two versions are identical. The behavior of the non-annotated version is that I see "weaveInfo joinPoint ..." traces from ajc, whereas no such traces occur for the annotated version. I have -source=1.5 set, of course.

Appreciate any insight into what I'm missing. I'm using AspectJ 1.5.

Thanks
Mick Jordan


Back to the top