Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
AW: [aspectj-users] Introduction on more than just one class

Thanks for clarifying this. As you might have seen on the AJDT newgroup, I
was already wondering whether this particular kind of introduction was
broken in AspectJ-1.1.

So, if I get this right:
1) I declare an interface
2) The interface contains a method PLUS that method's implementation body?
3) I ask AspectJ to introduce this interface into one or more classes (using
a type pattern)

In particular, point 2) make me scratch the back of my head. Is this legal
Java? I always thought that interfaces were not allowed to contain
implementation...

Anyway, the code works as you suggested, so thanks everybody for working it
out!

Peter


> -----Ursprüngliche Nachricht-----
> Von: Jim.Hugunin@xxxxxxxx [mailto:Jim.Hugunin@xxxxxxxx]
> Gesendet: Mittwoch, 19. März 2003 19:02
> An: aspectj-users@xxxxxxxxxxx
> Betreff: RE: [aspectj-users] Introduction on more than just one class
> 
> 
> The method suggested below will work in AspectJ-1.0, but is 
> not permitted in AspectJ-1.1.  In order to enable truly 
> modular compilation of aspects AspectJ-1.1 doesn't permit 
> performing introduction on a type pattern.  The 1.1 answer is 
> to use an interface combined with declare parents, i.e.
> 
> aspect A {
>     interface Bar { }
>     public void Bar.bar() {
>         System.out.println("An introduced method");
>     }
>     declare parents: Foo* implements Bar;
> }
> 
> This is explained in slightly more detail in the changes file 
> for 1.1, 
> http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspect
> j-home/README-11.html#SINGLE_INTERCLASS_TARGET
> 
> -Jim
> 
> 
> > -----Original Message-----
> > From: Valentin Crettaz [mailto:Valentin.Crettaz@xxxxxxx]
> > Sent: Wednesday, March 19, 2003 2:08 AM
> > To: aspectj-users@xxxxxxxxxxx
> > Subject: Re: [aspectj-users] Introduction on more than just 
> one class
> > 
> > Yes, there is a very simple way of doing this using type patterns.
> > You are not very far from the solution :)
> > 
> > The bar() method can be introduced in the Foo1, Foo2, and 
> Foo3 types using
> > the following introduction
> > 
> > public void (Foo*).bar() {
> >     System.out.println("An introduced method");
> > }
> > 
> > Consider reading the following sections about type patterns 
> in the AspectJ
> > programming guide:
> > http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-
> > home/doc/pro
> > gguide/apas02.html
> > http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-
> > home/doc/pro
> > gguide/apbs02.html#d0e5092
> > 
> > Good luck
> > 
> > Val
> > 
> > ----- Original Message -----
> > From: <PETER.FRIESE@xxxxxxxxxxxxx>
> > To: <aspectj-users@xxxxxxxxxxx>
> > Sent: Wednesday, March 19, 2003 10:59 AM
> > Subject: [aspectj-users] Introduction on more than just one class
> > 
> > 
> > > Hi,
> > >
> > > I want to introduce a method on more than one class - is 
> there a way to
> > do
> > > this?
> > >
> > > Sample code (this is what I can do now):
> > >
> > > --------------------- 8< --------------------------
> > > public aspect FooAspect {
> > >   public void Foo1.bar() {
> > >     System.out.println("An introduced method");
> > >   }
> > > }
> > >
> > > public class Foo1 {
> > > }
> > > --------------------- >8 --------------------------
> > >
> > > Sample code (what I would like to do):
> > >
> > > --------------------- 8< --------------------------
> > > public aspect FooAspect {
> > >   public void [Foo1, Foo2, Foo3].bar() {
> > >     System.out.println("An introduced method");
> > >   }
> > > }
> > >
> > > public class Foo1 {
> > > }
> > >
> > > public class Foo2 {
> > > }
> > >
> > > public class Foo3 {
> > > }
> > > --------------------- >8 --------------------------
> > >
> > > TIA,
> > > Peter
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> > >
> > 
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > http://dev.eclipse.org/mailman/listinfo/aspectj-users
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 


Back to the top