Skip to main content

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

Yes, Lombok is also an easy means to implement that requirement. If you
do not need Aspects for anything else, take a look at Lombok. Of course,
just like for AspectJ you need both build-time and IDE tooling in order
to work comfortably with Lombok. Steve is thinking about using marker
annotations anyway. Of course, in AspectJ you could add the members
without adding any marker annotations, as long as you can express the
set of target classes in a pointcut, which is often possible. Another
thing to consider is that Lombok does not play nice with AspectJ out of
the box, i.e you also use AspectJ for other things, you need to tweak
your build process to mix both tools. Using AspectJ only for member
(field/method) introduction as well as all other types of cross-cutting
concerns would be one-stop shopping. Depending on the situation, you can
make an informed choice to use either A or B or both at the same time.

@Tim: By instance method he means non-static methods. It is a commonly used term.

-- 
Alexander Kriegisch
https://scrum-master.de


n614cd--- via aspectj-users schrieb am 29.03.2024 16:12 (GMT +01:00):

> I would instead use project Lombok annotations for the getter/setter. Lombok
> annotations are respected in most IDEs for compile support, and also for
> many build tools.
> 
> What do you mean by "instance" method?
> 
> Tim
> 
> -----Original Message-----
> From: aspectj-users <aspectj-users-bounces@xxxxxxxxxxx> On Behalf Of Steve
> White via aspectj-users
> Sent: Friday, March 29, 2024 10:47 AM
> To: aspectj-users@xxxxxxxxxxx
> Cc: Steve White <stevan.white@xxxxxxxxx>
> Subject: [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!
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/aspectj-users
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/aspectj-users
> 
> 


Back to the top