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 On Behalf Of Steve > White via aspectj-users > Sent: Friday, March 29, 2024 10:47 AM > To: aspectj-users@eclipse.org > Cc: Steve White > 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@eclipse.org > To unsubscribe from this list, visit > https://www.eclipse.org/mailman/listinfo/aspectj-users > > ___ > aspectj-users mailing list > aspectj-users@eclipse.org > To unsubscribe from this list, visit > https://www.eclipse.org/mailman/listinfo/aspectj-users > > ___ aspectj-users mailing list aspectj-users@eclipse.org To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/aspectj-users
Re: [aspectj-users] add instance members to a class
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 On Behalf Of Steve White via aspectj-users Sent: Friday, March 29, 2024 10:47 AM To: aspectj-users@eclipse.org Cc: Steve White 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@eclipse.org To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/aspectj-users ___ aspectj-users mailing list aspectj-users@eclipse.org To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/aspectj-users
Re: [aspectj-users] add instance members to a class
Hi Steve. I think we know each other from GitHub issue #299. Welcome to the mailing list channel, too. First, a few links for you: How to declare an interface and its implementation including fields and accessor methods by means of inter-type declarations (ITD) in native AspectJ syntax: https://eclipse.dev/aspectj/doc/latest/progguide/progguide.html#language-interType The chapter right below that one also showcases some basic AspectJ examples, among them ITD ones. Just search for "declare parents", if scrolling is too tedious. The corresponding chapter explaining ITDs in annotation-style is here: https://eclipse.dev/aspectj/doc/latest/adk15notebook/adk15notebook.html#ataspectj-itds There, you find an example explaining how to achieve a similar result as in native syntax in the less powerful (but still powerful enough) annotation syntax by means of "@DeclareParents" and "@DeclareMixin", respectively. I hope this helps. If you need more support, please share an MCVE (https://stackoverflow.com/help/mcve), ideally a GitHub project or in old-school fashion by attaching a zip or tar.* archive to your next message, and I will do my best to help you sort out the details. Cheers -- Alexander Kriegisch https://scrum-master.de Steve White via aspectj-users schrieb am 29.03.2024 15:47 (GMT +01:00): > 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@eclipse.org > To unsubscribe from this list, visit > https://www.eclipse.org/mailman/listinfo/aspectj-users > > ___ aspectj-users mailing list aspectj-users@eclipse.org To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/aspectj-users
[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@eclipse.org To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/aspectj-users