Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] @this(@Foo) does not work


Hi,

I believe the problem here is the age of the build you are using -
what you are trying to do is perfectly valid.

We've put in *loads* of fixes and enhancements for annotations in the
last couple of weeks that won't be in a build from 20050204.  In your
particular case you are possibly hitting a bug we had with annotations
in packages.

If you try a more recent AJDT then that will fix it.  The new build
will also have annotation binding in so you examine the annotation in
your advice.  Here is an example:

--------8<----------------------------
import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@interface Colored { String color(); }

@Colored(color="yellow")
public class AtTarget1 {
  public static void main(String[]argv) {
    new AtTarget1().m();
  }
  public void m() {
    System.err.println("method");
  }
}

aspect X {
  before(Colored c): call(* *(..)) && !within(X) && @target(c) {
    System.err.println("Color = "+c.color());
  }
}
--------8<----------------------------

The documentation we try and keep up to date is the developers notebook
and Adrian is currently converting all examples in that notebook into
real testcases to confirm it does work as claimed.  As for other
examples, I think we have about 150 testcases for java5 features in CVS -
some of those will probably make it into the shipped examples at some
point.

I should mention an imminent change of syntax, based on some traffic
on this list.  You won't need the @ in front of your annotation when
using it within an @ pointcut, so your @target(@Role) will become
@target(Role).

cheers,
Andy.
---
Andy Clement
AspectJ






"Oli B." <boehm@xxxxxxxxxx>
Sent by: aspectj-users-admin@xxxxxxxxxxx

18/02/2005 19:27

Please respond to
aspectj-users@xxxxxxxxxxx

To
aspectj-users@xxxxxxxxxxx
cc
Subject
[aspectj-users] @this(@Foo) does not work





Hi,

I'm just trying the new AspectJ5 features for my new book using the
AspectJ 5 Developers Notebook. But with the @this(@Foo) (and the
following examples) I have problems. Here is my example:

    after() : call(public * *.*(..)) && @target(@Role) {
        log.info("@@@ " + thisJoinPoint.toShortString());
    }

I want to log all calls where the target has a @Role annotation. The
compilation is successful but when I start my test cases I get a

java.lang.NoClassDefFoundError: Role
                at space.LogBook.ajc$after$space_LogBook$1$69ac1cc5(LogBook.aj:38)
                at space.Taxi.<init>(Taxi.java:24)
                at space.test.TaxiTest.setUp(TaxiTest.java:31)
                at junit.framework.TestCase.runBare(TestCase.java:125)
                ...

I'm using Eclipse 3.1M4 with AJDT 1.2.0.20050204153223 on Linux. Is it a
problem with the pre version or is it a problem of my understanding?

regards
Oliver
--
Oliver Böhm
mailto:boehm@xxxxxxxxxx
http://www.javatux.de



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top