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

In annotation-style, pointcut expressions must use fully-qualified type names. So you will need to change your pointcut to something like:

@Pointcut("execution(* packageof.A.*(..)) || execution(* packageof.C.*(..))")

Also, can you switch to the latest version AspectJ? A lot of bugs have been fixed, especially for annotation-style aspects.

-Ramnivas

On Wed, Feb 10, 2010 at 4:28 PM, Mick Jordan <Mick.Jordan@xxxxxxx> wrote:
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
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users