Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] @DeclareParents

Thanks for the quick turnaround and updates to the documentation! With the updates, the example now compiles.

One last question/issue: is the annotation-style advice supposed to be static?

The two examples are not equivalent (in a subtle way that wouldn't be apparent given the example, since the example has no setter)...

If I implement MoodIndicator using the "classic" style and create two instances, each instance will have it's own mood (since the example has no setter, both instances' values would be Mood.HAPPY). In the annotation style, the mood is static (shared). This becomes evident if I add a setter to both styles and change the value of one of the instances, as the following pseudo code illustrates:
  MoodyGuy m0 = new MoodyGuy();
  m0.setMood(Mood.HAPPY); //the default...
  MoodyGuy m1 = new MoodyGuy();
  m1.setMood(Mood.JOLLY);

  if (m0.getMood() == m1.getMood()) System.out.println("Advice is static");
  else System.out.println("Advice is not static");

For classic, this would result in "Advice is not static", but for the annotation style, this would produce "Advice is static" because setting the mood on m1 affects m0. Can the annotation-style be made non-static?

Adrian Colyer wrote:

I've now fixed the docs in CVS and in the online version.

On 22/12/05, Alexandre Vasseur <avasseur@xxxxxxxxx> wrote:
Hi Brian

I have spotted a little typo in the doc indeed.

First the syntax is
@DeclareParents(value=".....", defaultImpl=Some.class)
that is reference the class object itself, not the fully qualified name there.

Also, the static inner class must be static and public so that the
implicit no-arg constructor is public.

Alex



On 12/22/05, Brian Ericson <bme@xxxxxxxx> wrote:
The syntax for @DeclareParents changed slightly in the AspectJ 5
release.  I can't get the example to compile...  The first two hurdles
are minor:
o 'defaultImpl="MoodyImpl"' should be 'defaultImpl=MoodyImpl.class'
o 'void feelingMoody(Moody m) {' should be 'public void
feelingMoody(Moody m) {'

However, having made the changes, the compilation fails because
'defaultImpl="MoodIndicator$MoodyImpl" has no public no-arg
constructor'.  I've tried a number of things, but can't get beyond this...

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

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



--
-- Adrian
adrian.colyer@xxxxxxxxx
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top