Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] add instance members to a class

Hi,

I'm just learning about AspectJ.  I haven't been able to determine if
I can apply it to my problem.

The problem is to add an instance member, together with
getters/setters, to certain existing classes.  This seems to be an
example of a crosscutting concern.

So far, I have managed with AspectJ only to produce classes with new
static members.

Is it possible with AspectJ to create an annotation, say @Labelled, so that

    @Labelled
    public class LabelledClass extends PlainClass{
    }

so that instances of LabelledClass will have their own private String
member "itsLabel", with a getter "getLabel()", and a setter
"setLabel()".  That is, so that LabelledClass effectively implements

     interface LabelledInterface{
         String getLabel();
         void setLabel( String label );
    }

How would one go about this?  Is something like this possible?

If this kind of thing isn't possible, where can I find passages in the
documentation that would clarify the situation?

Thanks!


Back to the top