[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] adding methods to annotated classes
|
> Is there a way to add methods to classes annotated with a particular annotation?
No and yes.
No: Inter-type declarations must be on a determinate type.
and: You can declare a method implementation on an interface, and declare
that the class extends the interface:
interface I {}
aspect IImpl { public void I.go() {} }
aspect IClasses { declare parents: BeanA, BeanB implements I; }
Yes: One way to declare that the class extends the interface is using annotations:
aspect IClasses { declare parents: (@Annot *) implements I; }
Wes
---------- ajsandbox/OnAnnot.java:
package ajsandbox;
public class OnAnnot {
public static void main(String[] args) {
new BeanA().go();
}
interface I {}
static aspect IImpl {
public void I.go() {System.out.println(this + ".go");}
}
// and: declare classes implement interface
//static aspect IClasses { declare parents: BeanA || BeanB implements I; }
// Yes: declare that the class extends the interface using annotations:
static aspect IClasses { declare parents: (@Annot *) implements I; }
@Annot static class BeanA {}
@Annot static class BeanB{}
@interface Annot {}
}
------------Original Message------------
From: "Beransky, Dmitry" <Dmitry.Beransky@xxxxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Thu, Aug-24-2006 3:15 PM
Subject: [aspectj-users] adding methods to annotated classes
Hi,
Is there a way to add methods to classes annotated with a particular annotation?
For example,
CLASS 1
---------------
@MyAnnotation public class BeanA
{
// …
}
CLASS 2
@MyAnnotation public class BeanB
{
// …
}
Now, I need an aspect to insert a method, let’s call it foo(), to all classes annotated with @MyAnnotation
Is this doable and if so, how?
Thanks
Dmitry
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users